// File: /workspace/github_c_makefile_star2_O3/Matthias-Wandel[P]imgcomp/src/compare.c
// Function: ComparePix
TriggerInfo_t ComparePix(MemImage_t * pic1, MemImage_t * pic2,
    int UpdateFatigue, int SkipFatigue, char * DebugImgName, TriggerInfo_t * no_fatigue_motion)
{
    int width, height, bPerRow;
    int row, col;
    MemImage_t * DiffOut = NULL;
    int DiffHist[256];
    int a;
    int DetectionPixels;
    int m1i, m2i;
    double BrightnessRatio;
    Region_t MainReg;
    TriggerInfo_t RetVal;
    RetVal.x = RetVal.y = 0;
    RetVal.DiffLevel = -1;
    RetVal.Motion = 0;

    if (Verbosity){
        printf("\ncompare pictures %dx%d %d\n", pic1->width, pic1->height, pic1->components);
    }

    if (pic1->width != pic2->width || pic1->height != pic2->height
        || pic1->components != pic2->components){
        fprintf(stderr, "pic size mismatch (maybe clear ramdisk?)\n  %dx%d vs %dx%d\n",pic1->width, pic1->height, pic2->width, pic2->height);
        exit(-1);
        //return RetVal;
    }
    width = pic1->width;
    height = pic1->height;
    bPerRow = width * 3;

    // Make sure we have an allocated working array and weight map.

    if (DiffVal != NULL && (width != DiffVal->w || height != DiffVal->h)){
        // DiffVal allocated size is wrong.
        free(DiffVal);
        free(WeightMap);
        DiffVal = NULL;
    }
    if (DiffVal == NULL){
        DiffVal = MakeImgMap(width,height);

        if (!WeightMap){
            FillWeightMap(width,height);
        }else{
            if (WeightMap->w != width || WeightMap->h != height){
                fprintf(stderr,"diff map image size mismatch\n");
                exit(-1);
            }
        }
    }
    memset(DiffVal->values, 0,  sizeof(DiffVal->values)*width*height);

    if (DebugImgName){
        // Create image for writing difference to.
        int data_size;
        data_size = height * bPerRow;
        DiffOut = malloc(data_size+offsetof(MemImage_t, pixels));
        memcpy(DiffOut, pic1, offsetof(MemImage_t, pixels));
        memset(DiffOut->pixels, 0, data_size);
    }

    MainReg = Regions.DetectReg;
    if (MainReg.y2 > height) MainReg.y2 = height;
    if (MainReg.x2 > width) MainReg.x2 = width;
    if (MainReg.x2 < MainReg.x1 || MainReg.y2 < MainReg.y1){
        fprintf(stderr, "Negative region, or region outside of image\n");
        return RetVal;
    }

    DetectionPixels = (MainReg.x2-MainReg.x1) * (MainReg.y2-MainReg.y1);
    if (DetectionPixels < 1000){
        fprintf(stderr, "Too few pixels in region\n");
        return RetVal;
    }

    if (Verbosity > 0){
        printf("Detection region is %d-%d, %d-%d\n",MainReg.x1, MainReg.x2, MainReg.y1, MainReg.y2);
    }


    // Compute brightness multipliers for the two images
    {
        double b1average, b2average;
        double m1, m2;
        b1average = AverageBright(pic1, MainReg, WeightMap);
        b2average = AverageBright(pic2, MainReg, WeightMap);

        NewestAverageBright = (int)(b2average+0.5);

        if (Verbosity > 0){
            printf("average bright: %f %f\n",b1average, b2average);
        }
        if (b1average < 0.5) b1average = 0.5; // Avoid possible division by zero.
        if (b2average < 0.5) b2average = 0.5;

        m1 = 80/b1average;
        m2 = 80/b2average;

        {
            double maxm, minm;
            if (m1 > m2){
                maxm = m1; minm = m2;
            }else{
                maxm = m2; minm = m1;
            }
            BrightnessRatio = maxm/minm;

            if (maxm > 2.5){
                // Don't allow multiplier to get bigger than 2.5.  Otherwise, for dark images
                // we just end up multiplying pixel noise!
                m1 = m1 * 2.5 / maxm;
                m2 = m2 * 2.5 / maxm;
            }else if (maxm < 1.0){
                // And there's no point in scaling down both images either.
                m1 = m1 * 1 / maxm;
                m2 = m2 * 1 / maxm;
            }
        }

        if (Verbosity) printf("Brightness adjust multipliers:  m1 = %5.2f  m2=%5.2f\n",m1,m2);

        m1i = (int)(m1*256+0.5);
        m2i = (int)(m2*256+0.5);
    }

    // Compute differences
    memset(DiffHist, 0, sizeof(DiffHist));
    for (row=MainReg.y1;row<MainReg.y2;){
        unsigned char * p1, *p2, *pd = NULL;
        int * ExRow;
        int * diffrow;
        p1 = pic1->pixels+row*bPerRow + MainReg.x1*3;
        p2 = pic2->pixels+row*bPerRow + MainReg.x1*3;
        diffrow = &DiffVal->values[width*row];
        ExRow = &WeightMap->values[width*row];
        if (DebugImgName) pd = DiffOut->pixels+row*bPerRow;

        for (col=MainReg.x1;col<MainReg.x2;col++){
            if (ExRow[col]){
                // Data is in order red, green, blue.
                int dr,dg,db;
                int dcomp;
                int max;
                {
                    // Find maximum of red green or blue for either picture after adjustment.
                    int max1, max2;
                    max1 = p1[0];
                    if (p1[1] > max1) max1 = p1[1];
                    if (p1[2] > max1) max1 = p1[2];
                    max1 *= m1i;
                    max2 = p2[0];
                    if (p2[1] > max1) max1 = p2[1];
                    if (p2[2] > max1) max1 = p2[2];
                    max2 *= m2i;
                    max = max2 > max1 ? max2 : max1;
                    max = max >> 8;
                    if (max < 40) max = 40; // Don't allow under 40 to avoid amlifying dark noise.
                }

                // Compute red green and blue differences
                dr = (p1[0]*m1i - p2[0]*m2i);
                dg = (p1[1]*m1i - p2[1]*m2i);
                db = (p1[2]*m1i - p2[2]*m2i);

                // Make differences absolute values.
                if (dr < 0) dr = -dr;
                if (dg < 0) dg = -dg;
                if (db < 0) db = -db;

                // compute composite difference.
                dcomp = (dr + dg*2 + db) >> 8; // Put more emphasis on green
                dcomp = dcomp * 120/max;       // Normalize difference to local brightness.


                // Add computed difference value to histogram bins.
                if (dcomp >= 256) dcomp = 255;
                if (dcomp < 0){
                    fprintf(stderr,"Internal error dcomp\n");
                    dcomp = 0;
                }
                DiffHist[dcomp] += 1;
                diffrow[col] = dcomp;

                if (DebugImgName){
                    // Save the difference image, scale brightness up 4x
                    dr=(dr*60/max)>> 6; if (dr > 255) dr = 255;
                    dg=(dg*60/max)>> 6; if (dg > 255) dg = 255;
                    db=(db*60/max)>> 6; if (db > 255) db = 255;
                    pd[0] = dr;
                    pd[1] = dg;
                    pd[2] = db;
                }
            }

            // Advance pointers to next pixel.
            pd += 3;
            p1 += 3;
            p2 += 3;
        }
        row++;
    }


    if (DebugImgName){
        WritePpmFile(DebugImgName,DiffOut);
        free(DiffOut);
    }


    if (Verbosity > 1){
        printf("Difference histogram\n");
        for (a=0;a<60;a+=4){
            printf("%3d:%6d,%6d,%6d,%6d\n",a,DiffHist[a], DiffHist[a+1], DiffHist[a+2], DiffHist[a+3]);
        }
    }

    TriggerInfo_t Trigger;
    int threshold;
    {
        // Gauge the difference noise level of the difference maps using the built histogram.
        // assuming two thirds of the image has not changed
        int cumsum = 0;
        int twothirds = DetectionPixels*2/3;

        for (a=0;a<256;a++){
            if (cumsum >= twothirds) break;
            cumsum += DiffHist[a];
        }

        threshold = a*3+12;
        if (threshold < 30) threshold = 30;

        int maxth = 180 + BrightnessRatio*5;
        if (threshold > maxth){
            threshold = maxth;
            if (Verbosity) printf("Using limit threshold of %d\n", threshold);
        }else{
            if (Verbosity) printf("2/3 of image is below %d diff.  Using %d threshold\n",a, threshold);
        }
    }

    // Apply motion fatigure and search for a window with the largest difference in it
    Trigger = AnalyzeDifferences(MainReg, threshold, UpdateFatigue, SkipFatigue, no_fatigue_motion);
    return Trigger;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4f8, %rsp            # imm = 0x4F8
movq %r9, 0xa8(%rsp)
movq %r8, %r15
movl %ecx, 0x6c(%rsp)
movl %edx, 0x68(%rsp)
movq %rsi, %r14
movq %rdi, %r12
leaq 0xcddf(%rip), %rbx      # 0x12998
cmpl $0x0, (%rbx)
je 0x5bda
movl (%r12), %esi
movl 0x4(%r12), %edx
movl 0x8(%r12), %ecx
leaq 0x6b8d(%rip), %rdi      # 0xc760
xorl %eax, %eax
callq 0x3170
movslq (%r12), %r13
movl (%r14), %r8d
movl 0x4(%r14), %r9d
movl 0x4(%r12), %ebp
cmpl %r8d, %r13d
jne 0x676b
cmpl %r9d, %ebp
jne 0x676b
movl 0x8(%r12), %eax
movl %ebp, %r9d
cmpl 0x8(%r14), %eax
jne 0x676b
movq 0xd7fb(%rip), %rdi      # 0x13410
testq %rdi, %rdi
je 0x5c40
cmpl (%rdi), %r13d
jne 0x5c24
cmpl 0x4(%rdi), %ebp
je 0x5c76
callq 0x3040
movq 0xd7d8(%rip), %rdi      # 0x13408
callq 0x3040
movq $0x0, 0xd7d0(%rip) # 0x13410
movl %r13d, %edi
movl %ebp, %esi
callq 0x6f87
movq %rax, 0xd7bf(%rip)      # 0x13410
movq 0xd7b0(%rip), %rax      # 0x13408
testq %rax, %rax
je 0x5c6c
cmpl %r13d, (%rax)
jne 0x5c67
cmpl %ebp, 0x4(%rax)
je 0x5c76
callq 0x3718
movl %r13d, %edi
movl %ebp, %esi
callq 0x697c
movq %r14, 0x38(%rsp)
leal (%r13,%r13,2), %ecx
movq %r15, 0x60(%rsp)
testq %r15, %r15
movq %r13, %r14
movl %ecx, 0xc(%rsp)
je 0x5cc6
movl %ebp, %eax
imull %ecx, %eax
movslq %eax, %r15
leaq 0xc(%r15), %rdi
callq 0x3340
movq (%r12), %rcx
movq %rcx, (%rax)
movl 0x8(%r12), %ecx
movl %ecx, 0x8(%rax)
movq %rax, 0x40(%rsp)
leaq 0xc(%rax), %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x31b0
jmp 0x5ccf
movq $0x0, 0x40(%rsp)
leaq 0xd0e2(%rip), %rax      # 0x12db8
movq (%rax), %rsi
movq 0x8(%rax), %rax
movq %rsi, %r13
shrq $0x20, %r13
movq %rax, %rcx
shrq $0x20, %rcx
movq %rbp, %rdx
shlq $0x20, %rdx
movl %eax, %r8d
orq %rdx, %r8
cmpl %ecx, %ebp
cmovgeq %rax, %r8
movq %r14, %rax
cmpl %r13d, %eax
cmovll %eax, %r13d
movl %r13d, %eax
movq %rsi, 0x28(%rsp)
subl %esi, %eax
jl 0x674f
movq %r8, %rdx
shrq $0x20, %rdx
movq %rdx, 0x48(%rsp)
subl %r8d, %edx
jl 0x674f
imull %eax, %edx
cmpl $0x3e7, %edx            # imm = 0x3E7
jle 0x675b
movq %rdx, 0xa0(%rsp)
cmpl $0x0, (%rbx)
movq 0x28(%rsp), %r15
movq %r8, 0x30(%rsp)
jle 0x5d74
leaq 0x6ac2(%rip), %rdi      # 0xc81c
movl %r15d, %esi
movl %r13d, %edx
movl %r8d, %ecx
movq 0x48(%rsp), %r8
xorl %eax, %eax
callq 0x3170
movq 0x30(%rsp), %r8
movq 0xd68d(%rip), %rcx      # 0x13408
movq %r13, %rax
shlq $0x20, %rax
movl %r15d, %ebp
orq %rax, %rbp
movq %r12, %rdi
movq %rbp, %rsi
movq %r8, %rdx
movq %r8, %r15
callq 0x6e78
movapd %xmm0, 0x10(%rsp)
movq 0xd662(%rip), %rcx      # 0x13408
movq 0x38(%rsp), %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x6e78
movapd %xmm0, %xmm2
addsd 0x6936(%rip), %xmm0     # 0xc6f8
cvttsd2si %xmm0, %eax
movl %eax, 0xd64c(%rip)      # 0x13418
cmpl $0x0, (%rbx)
jle 0x5df5
leaq 0x6a66(%rip), %rdi      # 0xc83e
movapd 0x10(%rsp), %xmm0
movapd %xmm2, %xmm1
movb $0x2, %al
movapd %xmm2, 0x70(%rsp)
callq 0x3170
movapd 0x70(%rsp), %xmm2
movapd 0x10(%rsp), %xmm1
unpcklpd %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
movapd 0x6919(%rip), %xmm0     # 0xc720
maxpd %xmm1, %xmm0
movapd 0x691d(%rip), %xmm2     # 0xc730
divpd %xmm0, %xmm2
movapd %xmm2, %xmm0
unpckhpd %xmm2, %xmm0            # xmm0 = xmm0[1],xmm2[1]
movapd %xmm2, %xmm1
movapd %xmm0, 0x90(%rsp)
maxsd %xmm0, %xmm1
ucomisd 0x68c8(%rip), %xmm1     # 0xc700
jbe 0x5e50
movapd 0x68fe(%rip), %xmm3     # 0xc740
mulpd %xmm2, %xmm3
movapd %xmm1, %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
jmp 0x5e70
movsd 0x68b0(%rip), %xmm0     # 0xc708
ucomisd %xmm1, %xmm0
movapd %xmm2, 0x10(%rsp)
jbe 0x5e7a
movapd %xmm1, %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movapd %xmm2, %xmm3
divpd %xmm0, %xmm3
movapd %xmm3, 0x10(%rsp)
movapd %xmm2, 0xd0(%rsp)
movapd %xmm1, 0xe0(%rsp)
cmpl $0x0, (%rbx)
je 0x5ead
movapd 0x10(%rsp), %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
leaq 0x69af(%rip), %rdi      # 0xc855
movb $0x2, %al
callq 0x3170
leaq 0xf0(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x31b0
movq 0x48(%rsp), %rax
cmpl 0x30(%rsp), %eax
movq %r13, 0x50(%rsp)
movapd 0xd0(%rsp), %xmm5
jle 0x6190
movapd 0x10(%rsp), %xmm0
mulpd 0x6864(%rip), %xmm0     # 0xc750
addpd 0x682c(%rip), %xmm0     # 0xc720
cvttpd2dq %xmm0, %xmm0
movq 0x28(%rsp), %rcx
movq %rcx, %rax
shlq $0x20, %rax
leaq (%rax,%rax,2), %rax
sarq $0x20, %rax
movq 0x40(%rsp), %rdx
addq $0xc, %rdx
movq %rdx, 0xb8(%rsp)
movslq %ecx, %rcx
movq %rcx, 0xb0(%rsp)
movq 0x30(%rsp), %rcx
movslq %ecx, %rdx
movslq 0xc(%rsp), %rsi
sarq $0x20, %rcx
movq %rcx, 0xc0(%rsp)
movslq %r13d, %rcx
movq %rcx, 0x10(%rsp)
movd %xmm0, %edi
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
movd %xmm1, 0xc(%rsp)
movq %r14, %rcx
imulq %rdx, %rcx
leaq 0x8(,%rcx,4), %rcx
movq %rcx, 0x58(%rsp)
shlq $0x2, %r14
movq %r14, 0xc8(%rsp)
movq %rsi, 0x88(%rsp)
movq %rsi, %rcx
movq %rdx, 0x70(%rsp)
imulq %rdx, %rcx
addq %rax, %rcx
movq 0x38(%rsp), %rax
leaq (%rax,%rcx), %r14
addq $0xe, %r14
addq %rcx, %r12
addq $0xe, %r12
pshufd $0xf5, %xmm0, %xmm1     # xmm1 = xmm0[1,1,3,3]
movl $0xff, %r10d
cmpl 0x28(%rsp), %r13d
jle 0x6150
movq 0x70(%rsp), %r9
imulq 0x88(%rsp), %r9
addq 0xb8(%rsp), %r9
movq 0x60(%rsp), %rax
testq %rax, %rax
cmoveq %rax, %r9
movq 0xd426(%rip), %rbx      # 0x13408
movq 0x58(%rsp), %rax
addq %rax, %rbx
movq 0xd41f(%rip), %rcx      # 0x13410
addq %rax, %rcx
movq %rcx, 0x38(%rsp)
xorl %r13d, %r13d
movq 0xb0(%rsp), %r15
cmpl $0x0, (%rbx,%r15,4)
je 0x613e
movzbl -0x2(%r12,%r13), %ecx
movzbl -0x1(%r12,%r13), %eax
cmpb %cl, %al
movl %ecx, %r11d
cmoval %eax, %r11d
movzbl (%r12,%r13), %esi
cmpb %r11b, %sil
cmoval %esi, %r11d
imull %edi, %r11d
movzbl -0x2(%r14,%r13), %edx
movzbl -0x1(%r14,%r13), %r8d
cmpl %r8d, %r11d
cmovlel %r8d, %r11d
imull %edi, %eax
movl 0xc(%rsp), %ebp
imull %ebp, %r8d
subl %r8d, %eax
movzbl (%r14,%r13), %r8d
imull %ebp, %edx
imull %edi, %ecx
subl %edx, %ecx
movd %esi, %xmm2
movdqa %xmm2, %xmm3
pinsrw $0x2, %r8d, %xmm3
pshufd $0x55, %xmm3, %xmm4     # xmm4 = xmm3[1,1,1,1]
movd %xmm4, %esi
cmpl %esi, %r11d
cmovbel %esi, %r11d
cmpl %r11d, %edx
cmovgl %edx, %r11d
shrl $0x8, %r11d
cmpl $0x29, %r11d
movl $0x28, %edx
cmovbl %edx, %r11d
pshufd $0xf5, %xmm3, %xmm3     # xmm3 = xmm3[1,1,3,3]
pmuludq %xmm1, %xmm3
pmuludq %xmm0, %xmm2
psubd %xmm3, %xmm2
movd %xmm2, %edx
movl %ecx, %r8d
negl %r8d
cmovsl %ecx, %r8d
movl %eax, %esi
negl %esi
cmovsl %eax, %esi
movl %edx, %ebp
negl %ebp
cmovsl %edx, %ebp
leal (%r8,%rsi,2), %eax
addl %ebp, %eax
shrl $0x8, %eax
imull $0x78, %eax, %eax
xorl %edx, %edx
divl %r11d
cmpl %r10d, %eax
cmovael %r10d, %eax
incl 0xf0(%rsp,%rax,4)
movq 0x38(%rsp), %rcx
movl %eax, (%rcx,%r15,4)
cmpq $0x0, 0x60(%rsp)
je 0x613e
imull $0x3c, %r8d, %eax
xorl %edx, %edx
divl %r11d
movl %eax, %ecx
shrl $0x6, %ecx
cmpl %r10d, %ecx
cmovael %r10d, %ecx
imull $0x3c, %esi, %eax
xorl %edx, %edx
divl %r11d
movl %eax, %esi
shrl $0x6, %esi
cmpl %r10d, %esi
cmovael %r10d, %esi
imull $0x3c, %ebp, %eax
xorl %edx, %edx
divl %r11d
shrl $0x6, %eax
cmpl %r10d, %eax
cmovael %r10d, %eax
movb %cl, (%r9,%r13)
movb %sil, 0x1(%r9,%r13)
movb %al, 0x2(%r9,%r13)
incq %r15
addq $0x3, %r13
cmpq %r15, 0x10(%rsp)
jne 0x6004
movq 0x70(%rsp), %rax
incq %rax
movq 0x58(%rsp), %rcx
addq 0xc8(%rsp), %rcx
movq %rcx, 0x58(%rsp)
movq 0x88(%rsp), %rcx
addq %rcx, %r14
addq %rcx, %r12
movq %rax, 0x70(%rsp)
cmpq 0xc0(%rsp), %rax
movq 0x50(%rsp), %r13
jne 0x5fae
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x61b8
movq 0x40(%rsp), %rbx
movq %rbx, %rsi
callq 0x777c
movq %rbx, %rdi
callq 0x3040
movapd 0xd0(%rsp), %xmm5
movapd 0x90(%rsp), %xmm0
minsd %xmm5, %xmm0
movapd %xmm0, 0x90(%rsp)
leaq 0xc7c3(%rip), %r13      # 0x12998
cmpl $0x2, (%r13)
jl 0x622c
leaq 0x67e2(%rip), %rdi      # 0xc9c5
callq 0x30c0
leaq 0x669c(%rip), %rbx      # 0xc88b
xorl %r14d, %r14d
movl 0xf0(%rsp,%r14,4), %edx
movl 0xf4(%rsp,%r14,4), %ecx
movl 0xf8(%rsp,%r14,4), %r8d
movl 0xfc(%rsp,%r14,4), %r9d
movq %rbx, %rdi
movl %r14d, %esi
xorl %eax, %eax
callq 0x3170
leaq 0x4(%r14), %rax
cmpq $0x38, %r14
movq %rax, %r14
jb 0x61f2
movapd 0xe0(%rsp), %xmm0
divsd 0x90(%rsp), %xmm0
movq 0xa0(%rsp), %rax
addl %eax, %eax
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
shrq $0x20, %rcx
xorl %eax, %eax
xorl %edi, %edi
xorl %edx, %edx
leaq 0x1(%rdi), %rsi
addl $0x3, %eax
cmpq $0xfe, %rdi
ja 0x6277
addl 0xf0(%rsp,%rdi,4), %edx
movq %rsi, %rdi
cmpl %ecx, %edx
jl 0x6259
cmpl $0x13, %eax
movl $0x12, %ebp
cmovael %eax, %ebp
addl $0xc, %ebp
mulsd 0x6483(%rip), %xmm0     # 0xc710
addsd 0x6483(%rip), %xmm0     # 0xc718
cvttsd2si %xmm0, %ebx
movl (%r13), %eax
cmpl %ebx, %ebp
jle 0x62b7
testl %eax, %eax
je 0x62cd
leaq 0x65f4(%rip), %rdi      # 0xc8a0
movl %ebx, %esi
xorl %eax, %eax
callq 0x3170
jmp 0x62cd
testl %eax, %eax
je 0x62cb
leaq 0x65fb(%rip), %rdi      # 0xc8bd
movl %ebp, %edx
xorl %eax, %eax
callq 0x3170
movl %ebp, %ebx
movq 0xd154(%rip), %r14      # 0x13428
testq %r14, %r14
je 0x6338
movl 0xd13d(%rip), %ebp      # 0x1341c
movq 0xd12a(%rip), %r15      # 0x13410
movl (%r15), %r12d
leal 0x4(%r12), %eax
cltq
imulq $0x66666667, %rax, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rax
addl %ecx, %eax
cmpl %eax, %ebp
jne 0x6333
movl 0xd112(%rip), %edx      # 0x13420
movl 0x4(%r15), %eax
addl $0x4, %eax
cltq
imulq $0x66666667, %rax, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rax
addl %ecx, %eax
cmpl %eax, %edx
je 0x63dc
callq 0x373d
movq 0xd0d1(%rip), %rax      # 0x13410
movl (%rax), %ecx
addl $0x4, %ecx
movslq %ecx, %rcx
imulq $0x66666667, %rcx, %rdi # imm = 0x66666667
movq %rdi, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rdi
addl %ecx, %edi
movl %edi, 0xd0bb(%rip)      # 0x1341c
movl 0x4(%rax), %eax
addl $0x4, %eax
cltq
imulq $0x66666667, %rax, %rsi # imm = 0x66666667
movq %rsi, %rax
shrq $0x3f, %rax
sarq $0x21, %rsi
addl %eax, %esi
movl %esi, 0xd09d(%rip)      # 0x13420
callq 0x6f87
movq %rax, 0xd099(%rip)      # 0x13428
movl 0xd087(%rip), %edi      # 0x1341c
movl 0xd085(%rip), %esi      # 0x13420
callq 0x6f87
movq %rax, 0xd089(%rip)      # 0x13430
movl 0xd06f(%rip), %edi      # 0x1341c
movl 0xd06d(%rip), %esi      # 0x13420
callq 0x6f87
movq %rax, 0xd079(%rip)      # 0x13438
movq 0xd04a(%rip), %r15      # 0x13410
movl (%r15), %r12d
movq 0xd058(%rip), %r14      # 0x13428
movl 0xd046(%rip), %ebp      # 0x1341c
movl 0xd044(%rip), %edx      # 0x13420
addq $0x8, %r14
movslq %ebp, %rax
movl %edx, 0x10(%rsp)
movslq %edx, %rdx
imulq %rax, %rdx
shlq $0x2, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x31b0
movq 0x30(%rsp), %r13
cmpl %r13d, 0x48(%rsp)
jle 0x64de
movslq 0x28(%rsp), %rdi
movslq %r13d, %rax
movslq %r12d, %rcx
sarq $0x20, %r13
movslq 0x50(%rsp), %rdx
movq %rcx, %r8
imulq %rax, %r8
leaq (,%rdi,4), %r9
leaq (%r9,%r8,4), %rsi
addq $0x8, %rsi
addq 0xcfca(%rip), %rsi      # 0x13408
leaq (%r9,%r8,4), %r8
shlq $0x2, %rcx
subq %rdi, %rdx
leaq (%r15,%r8), %rdi
addq $0x8, %rdi
movq 0x28(%rsp), %r12
cmpl %r12d, 0x50(%rsp)
jle 0x64cc
movslq %eax, %r8
imulq $0x66666667, %r8, %r8   # imm = 0x66666667
movq %r8, %r9
shrq $0x3f, %r9
sarq $0x21, %r8
addl %r9d, %r8d
imull %ebp, %r8d
movslq %r8d, %r8
leaq (%r14,%r8,4), %r8
xorl %r9d, %r9d
movl (%rdi,%r9,4), %r10d
subl %ebx, %r10d
jle 0x64c4
leal (%r12,%r9), %r11d
movslq %r11d, %r11
imulq $0x66666667, %r11, %r11 # imm = 0x66666667
movq %r11, %r15
shrq $0x3f, %r15
sarq $0x21, %r11
addl %r15d, %r11d
movslq %r11d, %r11
movl (%r8,%r11,4), %r15d
addl %r10d, %r15d
movl %r15d, (%r8,%r11,4)
cmpl $0x2, (%rsi,%r9,4)
jl 0x64c4
addl %r10d, %r15d
movl %r15d, (%r8,%r11,4)
incq %r9
cmpq %r9, %rdx
jne 0x6483
incq %rax
addq %rcx, %rsi
addq %rcx, %rdi
cmpq %r13, %rax
jne 0x6456
leaq 0xc4b3(%rip), %r12      # 0x12998
cmpl $0x1, (%r12)
jle 0x6511
leaq 0x6419(%rip), %rdi      # 0xc90c
movl %ebp, %esi
movl 0x10(%rsp), %edx
xorl %eax, %eax
callq 0x3170
movq 0xcf21(%rip), %rdi      # 0x13428
movl $0x64, %esi
callq 0x6fb8
leaq 0xbd94(%rip), %rbx      # 0x122ac
cmpl $0x0, (%rbx)
movq 0xa8(%rsp), %r14
je 0x65d7
testq %r14, %r14
je 0x6541
movq 0xcef3(%rip), %rdi      # 0x13428
callq 0x6792
movq %rax, (%r14)
movq %rdx, 0x8(%r14)
movl 0x6c(%rsp), %ebp
testl %ebp, %ebp
jne 0x655c
movq 0xcee0(%rip), %rdi      # 0x13430
movq 0xcee1(%rip), %rsi      # 0x13438
callq 0x7123
cmpl $0x0, 0x68(%rsp)
je 0x667a
movslq 0xceb2(%rip), %rcx      # 0x13420
movl 0xcea7(%rip), %r8d      # 0x1341c
testq %rcx, %rcx
jle 0x65f8
movq 0xcea7(%rip), %rdi      # 0x13428
addq $0x8, %rdi
movq 0xcea4(%rip), %r9       # 0x13430
addq $0x8, %r9
leaq (,%r8,4), %r10
xorl %r11d, %r11d
xorl %esi, %esi
testl %r8d, %r8d
jle 0x65c7
xorl %r14d, %r14d
movl (%rbx), %r15d
leal -0x1(%r15), %eax
imull (%r9,%r14,4), %eax
addl (%rdi,%r14,4), %eax
cltd
idivl %r15d
movl %eax, (%r9,%r14,4)
addl %eax, %esi
incq %r14
cmpq %r14, %r8
jne 0x65a5
incq %r11
addq %r10, %r9
addq %r10, %rdi
cmpq %rcx, %r11
jne 0x659d
jmp 0x65fa
movq 0xce4a(%rip), %rdi      # 0x13428
callq 0x6792
testq %r14, %r14
je 0x6726
movq %rax, (%r14)
movq %rdx, 0x8(%r14)
jmp 0x6726
xorl %esi, %esi
movl %ecx, %edi
imull %r8d, %edi
movl %esi, %eax
cltd
idivl %edi
cmpl $0x1, (%r12)
jg 0x6628
cmpl $0x33, %eax
setge %dl
movl 0xce28(%rip), %ebx      # 0x13440
cmpl $0x3d, %ebx
setge %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x6672
leaq 0xc989(%rip), %r14      # 0x12fb8
movq (%r14), %rdi
leaq 0x62f6(%rip), %rsi      # 0xc92f
xorl %ebx, %ebx
movl %r8d, %edx
movl %eax, %r8d
xorl %eax, %eax
callq 0x32a0
movq 0xcde1(%rip), %rdi      # 0x13430
movl $0x32, %esi
callq 0x6fb8
movq (%r14), %rcx
leaq 0x62f1(%rip), %rdi      # 0xc954
movl $0x9, %esi
movl $0x1, %edx
callq 0x34a0
incl %ebx
movl %ebx, 0xcdc6(%rip)      # 0x13440
testl %ebp, %ebp
je 0x668a
movq 0xcda3(%rip), %rdi      # 0x13428
jmp 0x6721
movslq 0xcd8f(%rip), %rax      # 0x13420
movq 0xcd90(%rip), %rdi      # 0x13428
testq %rax, %rax
jle 0x6721
leaq 0xbc08(%rip), %rcx      # 0x122b0
movl (%rcx), %ecx
shll $0x8, %ecx
leal (%rcx,%rcx,2), %ecx
movslq %ecx, %rcx
imulq $0x51eb851f, %rcx, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x25, %rcx
addl %edx, %ecx
movl 0xcd4f(%rip), %edx      # 0x1341c
movq 0xcd64(%rip), %rsi      # 0x13438
addq $0x8, %rsi
leaq 0x8(%rdi), %r8
leaq (,%rdx,4), %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
testl %edx, %edx
jle 0x6713
xorl %ebx, %ebx
movl (%rsi,%rbx,4), %ebp
imull %ecx, %ebp
sarl $0x8, %ebp
movl (%r8,%rbx,4), %r14d
subl %ebp, %r14d
testl %r14d, %r14d
cmovlel %r10d, %r14d
movl %r14d, (%r8,%rbx,4)
incq %rbx
cmpq %rbx, %rdx
jne 0x66f0
incq %r11
addq %r9, %r8
addq %r9, %rsi
cmpq %rax, %r11
jne 0x66ea
callq 0x6792
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rax, %rcx
movl %eax, %ebx
movl %edx, %edx
orq %rcx, %rbx
movq %rbx, %rax
addq $0x4f8, %rsp            # imm = 0x4F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0x377e
jmp 0x6765
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0x3762
xorl %ecx, %ecx
xorl %edx, %edx
jmp 0x6737
movq 0xb886(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x6000(%rip), %rsi      # 0xc77c
movl %r13d, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x32a0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3490