// File: /workspace/github_c_makefile_star2_O1/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 $0x4b8, %rsp            # imm = 0x4B8
movq %r9, %r15
movq %r8, %rbx
movl %ecx, 0x64(%rsp)
movl %edx, 0x60(%rsp)
movq %rsi, %r12
movq %rdi, %r13
leaq 0xce58(%rip), %r14      # 0x12998
cmpl $0x0, (%r14)
je 0x5b60
movl (%r13), %esi
movl 0x4(%r13), %edx
movl 0x8(%r13), %ecx
leaq 0x6bbf(%rip), %rdi      # 0xc718
xorl %eax, %eax
callq 0x3170
movslq (%r13), %r10
movl (%r12), %r8d
cmpl %r8d, %r10d
jne 0x66f9
movl 0x4(%r13), %ebp
cmpl 0x4(%r12), %ebp
jne 0x66f9
movl 0x8(%r13), %eax
cmpl 0x8(%r12), %eax
jne 0x66f9
movq %r13, 0x10(%rsp)
movq %r12, 0x38(%rsp)
movq 0xd870(%rip), %rdi      # 0x13410
testq %rdi, %rdi
movq %r10, %r12
je 0x5bd1
cmpl (%rdi), %r10d
jne 0x5bb2
cmpl 0x4(%rdi), %ebp
je 0x5bd1
callq 0x3040
movq 0xd84a(%rip), %rdi      # 0x13408
callq 0x3040
movq %r12, %r10
movq $0x0, 0xd83f(%rip) # 0x13410
cmpq $0x0, 0xd837(%rip)      # 0x13410
jne 0x5c1a
movl %r10d, %edi
movl %ebp, %esi
movq %r10, %r13
callq 0x6e1c
movq %rax, 0xd821(%rip)      # 0x13410
movq 0xd812(%rip), %rax      # 0x13408
testq %rax, %rax
je 0x5c0d
cmpl %r13d, (%rax)
jne 0x5c08
movq %r13, %r10
cmpl %ebp, 0x4(%rax)
je 0x5c1a
callq 0x3708
movl %r13d, %edi
movl %ebp, %esi
callq 0x6908
movq %r13, %r10
movq %r15, 0x88(%rsp)
leal (%r10,%r10,2), %r13d
testq %rbx, %rbx
je 0x5c66
movl %ebp, %eax
imull %r13d, %eax
movslq %eax, %r15
leaq 0xc(%r15), %rdi
callq 0x3330
movq 0x10(%rsp), %rdx
movq (%rdx), %rcx
movq %rcx, (%rax)
movl 0x8(%rdx), %ecx
movl %ecx, 0x8(%rax)
movq %rax, 0x40(%rsp)
leaq 0xc(%rax), %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x31b0
movq %r12, %r10
jmp 0x5c6f
movq $0x0, 0x40(%rsp)
leaq 0xd142(%rip), %rax      # 0x12db8
movq (%rax), %rsi
movq 0x8(%rax), %rax
movq %rsi, %rdx
shrq $0x20, %rdx
movq %rax, %rcx
shrq $0x20, %rcx
movq %rbp, %rdi
shlq $0x20, %rdi
movl %eax, %r8d
orq %rdi, %r8
cmpl %ecx, %ebp
cmovgeq %rax, %r8
cmpl %edx, %r10d
cmovll %r10d, %edx
movl %edx, %eax
movq %rsi, 0x20(%rsp)
subl %esi, %eax
jl 0x66dd
movq %r8, %rsi
shrq $0x20, %rsi
movq %rsi, 0x48(%rsp)
subl %r8d, %esi
jl 0x66dd
movq %r8, 0x28(%rsp)
imull %eax, %esi
cmpl $0x3e7, %esi            # imm = 0x3E7
jle 0x66e9
movq %rsi, 0x80(%rsp)
movq %rbx, 0x58(%rsp)
cmpl $0x0, (%r14)
movq 0x20(%rsp), %r15
movq %rdx, 0x18(%rsp)
movq 0x28(%rsp), %rbx
jle 0x5d1c
leaq 0x6ace(%rip), %rdi      # 0xc7d4
movl %r15d, %esi
movl %ebx, %ecx
movq 0x48(%rsp), %r8
xorl %eax, %eax
callq 0x3170
movq 0x18(%rsp), %rdx
movq 0xd6e5(%rip), %rcx      # 0x13408
movq %rdx, %rax
shlq $0x20, %rax
movl %r15d, %ebp
orq %rax, %rbp
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x6cff
movsd %xmm0, 0x8(%rsp)
movq 0xd6bb(%rip), %rcx      # 0x13408
movq 0x38(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x6cff
movapd %xmm0, %xmm2
movsd 0x52af(%rip), %xmm0     # 0xb018
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0xd6a1(%rip)      # 0x13418
cmpl $0x0, (%r14)
jle 0x5d9f
leaq 0x6a72(%rip), %rdi      # 0xc7f6
movsd 0x8(%rsp), %xmm0
movapd %xmm2, %xmm1
movb $0x2, %al
movsd %xmm2, (%rsp)
callq 0x3170
movsd (%rsp), %xmm2
movsd 0x5271(%rip), %xmm1     # 0xb018
movapd %xmm1, %xmm0
maxsd 0x8(%rsp), %xmm0
maxsd %xmm2, %xmm1
movsd 0x692b(%rip), %xmm2     # 0xc6e8
movapd %xmm2, %xmm3
divsd %xmm0, %xmm3
divsd %xmm1, %xmm2
movapd %xmm3, %xmm1
maxsd %xmm2, %xmm1
ucomisd 0x6917(%rip), %xmm1     # 0xc6f0
jbe 0x5dfa
movsd 0x690d(%rip), %xmm0     # 0xc6f0
movapd %xmm3, %xmm4
mulsd %xmm0, %xmm4
divsd %xmm1, %xmm4
movsd %xmm4, (%rsp)
mulsd %xmm2, %xmm0
jmp 0x5e24
movsd 0x68f6(%rip), %xmm0     # 0xc6f8
ucomisd %xmm1, %xmm0
movsd %xmm3, (%rsp)
movsd %xmm2, 0x8(%rsp)
jbe 0x5e2e
movapd %xmm3, %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm3, 0x68(%rsp)
movsd %xmm2, 0x30(%rsp)
movsd %xmm1, 0x78(%rsp)
cmpl $0x0, (%r14)
je 0x5e5f
leaq 0x69c0(%rip), %rdi      # 0xc80d
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movb $0x2, %al
callq 0x3170
leaq 0xb0(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x31b0
movq 0x48(%rsp), %rax
cmpl 0x28(%rsp), %eax
movsd 0x30(%rsp), %xmm1
movsd 0x68(%rsp), %xmm2
jle 0x6131
movsd 0x686a(%rip), %xmm0     # 0xc700
movsd (%rsp), %xmm4
mulsd %xmm0, %xmm4
movsd 0x5171(%rip), %xmm3     # 0xb018
addsd %xmm3, %xmm4
cvttsd2si %xmm4, %edi
movsd 0x8(%rsp), %xmm4
mulsd %xmm0, %xmm4
addsd %xmm3, %xmm4
cvttsd2si %xmm4, %r8d
movq 0x20(%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, 0x98(%rsp)
movslq %ecx, %rcx
movq %rcx, 0x90(%rsp)
movq 0x28(%rsp), %rcx
movslq %ecx, %rdx
movslq %r13d, %rsi
sarq $0x20, %rcx
movq %rcx, 0xa0(%rsp)
movslq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movq %rsi, 0x70(%rsp)
movq %rsi, %rcx
imulq %rdx, %rcx
addq %rax, %rcx
movq %r12, %rax
movq %rdx, (%rsp)
imulq %rdx, %rax
leaq 0x8(,%rax,4), %rax
movq %rax, 0x50(%rsp)
shlq $0x2, %r12
movq %r12, 0xa8(%rsp)
movq 0x38(%rsp), %rax
leaq (%rax,%rcx), %r14
addq $0xe, %r14
movq 0x10(%rsp), %rax
leaq (%rax,%rcx), %r12
addq $0xe, %r12
movq 0x18(%rsp), %rax
cmpl 0x20(%rsp), %eax
jle 0x60fb
movq (%rsp), %r11
imulq 0x70(%rsp), %r11
addq 0x98(%rsp), %r11
movq 0x58(%rsp), %rax
testq %rax, %rax
cmoveq %rax, %r11
movq 0xd474(%rip), %rcx      # 0x13408
movq 0x50(%rsp), %rax
addq %rax, %rcx
movq %rcx, 0x10(%rsp)
movq 0xd468(%rip), %rcx      # 0x13410
addq %rax, %rcx
movq %rcx, 0x38(%rsp)
xorl %r10d, %r10d
movq 0x90(%rsp), %rbp
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax,%rbp,4)
je 0x60e9
movzbl -0x2(%r12,%r10), %ecx
movzbl -0x1(%r12,%r10), %eax
cmpb %cl, %al
movl %ecx, %r9d
cmoval %eax, %r9d
movzbl (%r12,%r10), %edx
cmpb %r9b, %dl
cmoval %edx, %r9d
imull %edi, %r9d
movzbl -0x1(%r14,%r10), %esi
cmpl %esi, %r9d
jg 0x5ffd
movl %esi, %r9d
movzbl (%r14,%r10), %ebx
cmpl %ebx, %r9d
ja 0x600a
movl %ebx, %r9d
movzbl -0x2(%r14,%r10), %r13d
imull %r8d, %r13d
movl %r13d, %r15d
cmpl %r9d, %r13d
jg 0x601f
movl %r9d, %r15d
shrl $0x8, %r15d
cmpl $0x29, %r15d
jge 0x602f
movl $0x28, %r15d
imull %edi, %ecx
subl %r13d, %ecx
imull %edi, %eax
imull %r8d, %esi
subl %esi, %eax
imull %edi, %edx
imull %r8d, %ebx
subl %ebx, %edx
movl %ecx, %r9d
negl %r9d
cmovsl %ecx, %r9d
movl %eax, %esi
negl %esi
cmovsl %eax, %esi
movl %edx, %ebx
negl %ebx
cmovsl %edx, %ebx
leal (%r9,%rsi,2), %eax
addl %ebx, %eax
shrl $0x8, %eax
imull $0x78, %eax, %eax
xorl %edx, %edx
divl %r15d
movl $0xff, %ecx
cmpl %ecx, %eax
cmovael %ecx, %eax
incl 0xb0(%rsp,%rax,4)
movq 0x38(%rsp), %rcx
movl %eax, (%rcx,%rbp,4)
cmpq $0x0, 0x58(%rsp)
je 0x60e9
imull $0x3c, %r9d, %eax
xorl %edx, %edx
divl %r15d
movl %eax, %ecx
shrl $0x6, %ecx
movl $0xff, %r9d
cmpl %r9d, %ecx
jl 0x60af
movl $0xff, %ecx
imull $0x3c, %esi, %eax
xorl %edx, %edx
divl %r15d
movl %eax, %esi
shrl $0x6, %esi
cmpl %r9d, %esi
jl 0x60c6
movl $0xff, %esi
imull $0x3c, %ebx, %eax
xorl %edx, %edx
divl %r15d
shrl $0x6, %eax
cmpl %r9d, %eax
jl 0x60db
movl $0xff, %eax
movb %cl, (%r11,%r10)
movb %sil, 0x1(%r11,%r10)
movb %al, 0x2(%r11,%r10)
incq %rbp
addq $0x3, %r10
cmpq %rbp, 0x8(%rsp)
jne 0x5fbb
movq (%rsp), %rax
incq %rax
movq 0x50(%rsp), %rcx
addq 0xa8(%rsp), %rcx
movq %rcx, 0x50(%rsp)
movq 0x70(%rsp), %rcx
addq %rcx, %r14
addq %rcx, %r12
movq %rax, (%rsp)
cmpq 0xa0(%rsp), %rax
jne 0x5f60
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x615c
movq 0x40(%rsp), %rbx
movq %rbx, %rsi
callq 0x7640
movq %rbx, %rdi
callq 0x3040
movsd 0x68(%rsp), %xmm2
movsd 0x30(%rsp), %xmm1
minsd %xmm2, %xmm1
movsd %xmm1, 0x30(%rsp)
leaq 0xc82b(%rip), %r15      # 0x12998
cmpl $0x2, (%r15)
movq 0x28(%rsp), %r13
jl 0x61c8
leaq 0x67fe(%rip), %rdi      # 0xc97d
callq 0x30c0
leaq 0x66b8(%rip), %rbx      # 0xc843
xorl %r14d, %r14d
movl 0xb0(%rsp,%r14,4), %edx
movl 0xb4(%rsp,%r14,4), %ecx
movl 0xb8(%rsp,%r14,4), %r8d
movl 0xbc(%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 0x618e
movsd 0x78(%rsp), %xmm0
divsd 0x30(%rsp), %xmm0
movq 0x80(%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 0x620d
addl 0xb0(%rsp,%rdi,4), %edx
movq %rsi, %rdi
cmpl %ecx, %edx
jl 0x61ef
cmpl $0x13, %eax
movl $0x12, %ebp
cmovael %eax, %ebp
addl $0xc, %ebp
mulsd 0x64e5(%rip), %xmm0     # 0xc708
addsd 0x64e5(%rip), %xmm0     # 0xc710
cvttsd2si %xmm0, %ebx
movl (%r15), %eax
cmpl %ebx, %ebp
jle 0x624c
testl %eax, %eax
je 0x6262
leaq 0x6617(%rip), %rdi      # 0xc858
movl %ebx, %esi
xorl %eax, %eax
callq 0x3170
jmp 0x6262
testl %eax, %eax
je 0x6260
leaq 0x661e(%rip), %rdi      # 0xc875
movl %ebp, %edx
xorl %eax, %eax
callq 0x3170
movl %ebp, %ebx
cmpq $0x0, 0xd1be(%rip)      # 0x13428
je 0x62c4
movq 0xd19d(%rip), %rax      # 0x13410
movl (%rax), %ecx
addl $0x4, %ecx
movslq %ecx, %rcx
imulq $0x66666667, %rcx, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
cmpl %ecx, 0xd187(%rip)      # 0x1341c
jne 0x62bf
movl 0x4(%rax), %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, 0xd167(%rip)      # 0x13420
je 0x634b
callq 0x372d
movq 0xd145(%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, 0xd12f(%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, 0xd111(%rip)      # 0x13420
callq 0x6e1c
movq %rax, 0xd10d(%rip)      # 0x13428
movl 0xd0fb(%rip), %edi      # 0x1341c
movl 0xd0f9(%rip), %esi      # 0x13420
callq 0x6e1c
movq %rax, 0xd0fd(%rip)      # 0x13430
movl 0xd0e3(%rip), %edi      # 0x1341c
movl 0xd0e1(%rip), %esi      # 0x13420
callq 0x6e1c
movq %rax, 0xd0ed(%rip)      # 0x13438
movq 0xd0be(%rip), %r12      # 0x13410
movslq (%r12), %r15
movq 0xd0cb(%rip), %rbp      # 0x13428
addq $0x8, %rbp
movslq 0xd0b4(%rip), %r14      # 0x1341c
movslq 0xd0b1(%rip), %rax      # 0x13420
movq %r14, %rdx
movq %rax, 0x10(%rsp)
imulq %rax, %rdx
shlq $0x2, %rdx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x31b0
cmpl %r13d, 0x48(%rsp)
jle 0x646a
movslq 0x20(%rsp), %rsi
movslq %r13d, %rax
sarq $0x20, %r13
movslq 0x18(%rsp), %rcx
movq %r15, %rdi
imulq %rax, %rdi
leaq (,%rsi,4), %r8
leaq (%r8,%rdi,4), %rdx
addq $0x8, %rdx
addq 0xd045(%rip), %rdx      # 0x13408
leaq (%r8,%rdi,4), %rdi
shlq $0x2, %r15
subq %rsi, %rcx
leaq (%r12,%rdi), %rsi
addq $0x8, %rsi
movq 0x20(%rsp), %r12
cmpl %r12d, 0x18(%rsp)
jle 0x6458
movslq %eax, %rdi
imulq $0x66666667, %rdi, %rdi # imm = 0x66666667
movq %rdi, %r8
shrq $0x3f, %r8
sarq $0x21, %rdi
addl %r8d, %edi
imull %r14d, %edi
movslq %edi, %rdi
leaq (,%rdi,4), %rdi
addq %rbp, %rdi
xorl %r8d, %r8d
movl (%rsi,%r8,4), %r9d
subl %ebx, %r9d
jle 0x6450
leal (%r12,%r8), %r10d
movslq %r10d, %r10
imulq $0x66666667, %r10, %r10 # imm = 0x66666667
movq %r10, %r11
shrq $0x3f, %r11
sarq $0x21, %r10
addl %r11d, %r10d
movslq %r10d, %r10
movl (%rdi,%r10,4), %r11d
addl %r9d, %r11d
movl %r11d, (%rdi,%r10,4)
cmpl $0x2, (%rdx,%r8,4)
jl 0x6450
addl %r9d, %r11d
movl %r11d, (%rdi,%r10,4)
incq %r8
cmpq %r8, %rcx
jne 0x640f
incq %rax
addq %r15, %rdx
addq %r15, %rsi
cmpq %r13, %rax
jne 0x63db
leaq 0xc527(%rip), %r12      # 0x12998
cmpl $0x1, (%r12)
jle 0x649f
leaq 0x6445(%rip), %rdi      # 0xc8c4
movl %r14d, %esi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x3170
movq 0xcf93(%rip), %rdi      # 0x13428
movl $0x64, %esi
callq 0x6e67
leaq 0xbdfe(%rip), %rbx      # 0x122a4
cmpl $0x0, (%rbx)
movl 0x64(%rsp), %ebp
movq 0x88(%rsp), %r14
je 0x6567
testq %r14, %r14
je 0x64d3
movq 0xcf61(%rip), %rdi      # 0x13428
callq 0x6727
movq %rax, (%r14)
movq %rdx, 0x8(%r14)
testl %ebp, %ebp
jne 0x64ea
movq 0xcf52(%rip), %rdi      # 0x13430
movq 0xcf53(%rip), %rsi      # 0x13438
callq 0x6fd2
cmpl $0x0, 0x60(%rsp)
je 0x6609
movslq 0xcf24(%rip), %rcx      # 0x13420
testq %rcx, %rcx
jle 0x6588
movl 0xcf11(%rip), %edi      # 0x1341c
movq 0xcf16(%rip), %r8       # 0x13428
addq $0x8, %r8
movq 0xcf13(%rip), %r9       # 0x13430
addq $0x8, %r9
leaq (,%rdi,4), %r10
xorl %r11d, %r11d
xorl %esi, %esi
testl %edi, %edi
jle 0x6557
xorl %r14d, %r14d
movl (%rbx), %r15d
leal -0x1(%r15), %eax
imull (%r9,%r14,4), %eax
addl (%r8,%r14,4), %eax
cltd
idivl %r15d
movl %eax, (%r9,%r14,4)
addl %eax, %esi
incq %r14
cmpq %r14, %rdi
jne 0x6535
incq %r11
addq %r10, %r9
addq %r10, %r8
cmpq %rcx, %r11
jne 0x652e
jmp 0x658a
movq 0xceba(%rip), %rdi      # 0x13428
callq 0x6727
testq %r14, %r14
je 0x66b4
movq %rax, (%r14)
movq %rdx, 0x8(%r14)
jmp 0x66b4
xorl %esi, %esi
movl 0xce8b(%rip), %r8d      # 0x1341c
movl %r8d, %edi
imull %ecx, %edi
movl %esi, %eax
cltd
idivl %edi
cmpl $0x1, (%r12)
jg 0x65b1
cmpl $0x33, %eax
jl 0x6603
cmpl $0x3d, 0xce91(%rip)     # 0x13440
jl 0x6603
leaq 0xca00(%rip), %rbx      # 0x12fb8
movq (%rbx), %rdi
leaq 0x6325(%rip), %rsi      # 0xc8e7
movl %r8d, %edx
movl %eax, %r8d
xorl %eax, %eax
callq 0x3290
movq 0xce5a(%rip), %rdi      # 0x13430
movl $0x32, %esi
callq 0x6e67
movq (%rbx), %rcx
leaq 0x6322(%rip), %rdi      # 0xc90c
movl $0x9, %esi
movl $0x1, %edx
callq 0x3490
movl $0x0, 0xce3d(%rip)      # 0x13440
incl 0xce37(%rip)            # 0x13440
testl %ebp, %ebp
jne 0x66a8
movslq 0xce08(%rip), %rax      # 0x13420
testq %rax, %rax
jle 0x66a8
leaq 0xbc80(%rip), %rcx      # 0x122a8
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 0xcdcf(%rip), %edx      # 0x1341c
movq 0xcde4(%rip), %rsi      # 0x13438
addq $0x8, %rsi
movq 0xcdc9(%rip), %rdi      # 0x13428
addq $0x8, %rdi
leaq (,%rdx,4), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
testl %edx, %edx
jle 0x669a
xorl %r11d, %r11d
movl (%rsi,%r11,4), %ebx
imull %ecx, %ebx
sarl $0x8, %ebx
movl (%rdi,%r11,4), %ebp
subl %ebx, %ebp
testl %ebp, %ebp
cmovlel %r9d, %ebp
movl %ebp, (%rdi,%r11,4)
incq %r11
cmpq %r11, %rdx
jne 0x6678
incq %r10
addq %r8, %rdi
addq %r8, %rsi
cmpq %rax, %r10
jne 0x6671
movq 0xcd79(%rip), %rdi      # 0x13428
callq 0x6727
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rax, %rcx
movl %eax, %ebx
movl %edx, %edx
orq %rcx, %rbx
movq %rbx, %rax
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0x376e
jmp 0x66f3
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0x3752
xorl %ecx, %ecx
xorl %edx, %edx
jmp 0x66c5
movq 0xb8f8(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
movl 0x4(%r13), %ecx
movl 0x4(%r12), %r9d
leaq 0x6021(%rip), %rsi      # 0xc734
movl %r10d, %edx
xorl %eax, %eax
callq 0x3290
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3480