static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n)
{
    int i, best;
    int32_t lt, rt;
    uint64_t sum[4];
    uint64_t score[4];
    sum[0] = sum[1] = sum[2] = sum[3] = 0;
    for (i = 2; i < n; i++) {
        lt =  left_ch[i] - 2 *  left_ch[i - 1] +  left_ch[i - 2];
        rt = right_ch[i] - 2 * right_ch[i - 1] + right_ch[i - 2];
        sum[2] += FFABS((lt + rt) >> 1);
        sum[3] += FFABS(lt - rt);
        sum[0] += FFABS(lt);
        sum[1] += FFABS(rt);
    }
    score[0] = sum[0] + sum[1];
    score[1] = sum[0] + sum[3];
    score[2] = sum[1] + sum[3];
    score[3] = sum[2] + sum[3];
    best = 0;
    for (i = 1; i < 4; i++) {
        if (score[i] < score[best])
            best = i;
    }
    return best;
}
['static void alac_stereo_decorrelation(AlacEncodeContext *s)\n{\n    int32_t *left = s->sample_buf[0], *right = s->sample_buf[1];\n    int i, mode, n = s->frame_size;\n    int32_t tmp;\n    mode = estimate_stereo_mode(left, right, n);\n    switch (mode) {\n    case ALAC_CHMODE_LEFT_RIGHT:\n        s->interlacing_leftweight = 0;\n        s->interlacing_shift      = 0;\n        break;\n    case ALAC_CHMODE_LEFT_SIDE:\n        for (i = 0; i < n; i++)\n            right[i] = left[i] - right[i];\n        s->interlacing_leftweight = 1;\n        s->interlacing_shift      = 0;\n        break;\n    case ALAC_CHMODE_RIGHT_SIDE:\n        for (i = 0; i < n; i++) {\n            tmp = right[i];\n            right[i] = left[i] - right[i];\n            left[i]  = tmp + (right[i] >> 31);\n        }\n        s->interlacing_leftweight = 1;\n        s->interlacing_shift      = 31;\n        break;\n    default:\n        for (i = 0; i < n; i++) {\n            tmp = left[i];\n            left[i]  = (tmp + right[i]) >> 1;\n            right[i] =  tmp - right[i];\n        }\n        s->interlacing_leftweight = 1;\n        s->interlacing_shift      = 1;\n        break;\n    }\n}', 'static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n)\n{\n    int i, best;\n    int32_t lt, rt;\n    uint64_t sum[4];\n    uint64_t score[4];\n    sum[0] = sum[1] = sum[2] = sum[3] = 0;\n    for (i = 2; i < n; i++) {\n        lt =  left_ch[i] - 2 *  left_ch[i - 1] +  left_ch[i - 2];\n        rt = right_ch[i] - 2 * right_ch[i - 1] + right_ch[i - 2];\n        sum[2] += FFABS((lt + rt) >> 1);\n        sum[3] += FFABS(lt - rt);\n        sum[0] += FFABS(lt);\n        sum[1] += FFABS(rt);\n    }\n    score[0] = sum[0] + sum[1];\n    score[1] = sum[0] + sum[3];\n    score[2] = sum[1] + sum[3];\n    score[3] = sum[2] + sum[3];\n    best = 0;\n    for (i = 1; i < 4; i++) {\n        if (score[i] < score[best])\n            best = i;\n    }\n    return best;\n}']