// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x540, %rsp            # imm = 0x540
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
movl %ecx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $0x0, -0x58(%rbp)
movl $0x0, -0x490(%rbp)
movl $0x0, -0x494(%rbp)
movl $0xffffffff, -0x498(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x48c(%rbp)
leaq 0xe600(%rip), %rax      # 0x149f8
cmpl $0x0, (%rax)
je 0x641f
movq -0x18(%rbp), %rax
movl (%rax), %esi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
leaq 0x92f0(%rip), %rdi      # 0xf708
movb $0x0, %al
callq 0x3170
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x644d
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x644d
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0x648b
movq 0xdb9c(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %edx
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x20(%rbp), %rax
movl (%rax), %r8d
movq -0x20(%rbp), %rax
movl 0x4(%rax), %r9d
leaq 0x92aa(%rip), %rsi      # 0xf724
movb $0x0, %al
callq 0x3290
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3480
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x40(%rbp)
imull $0x3, -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpq $0x0, 0xefc3(%rip)      # 0x15470
je 0x64ef
movl -0x3c(%rbp), %eax
movq 0xefb7(%rip), %rcx      # 0x15470
cmpl (%rcx), %eax
jne 0x64cc
movl -0x40(%rbp), %eax
movq 0xefa9(%rip), %rcx      # 0x15470
cmpl 0x4(%rcx), %eax
je 0x64ef
movq 0xef9d(%rip), %rdi      # 0x15470
callq 0x3040
movq 0xef89(%rip), %rdi      # 0x15468
callq 0x3040
movq $0x0, 0xef81(%rip) # 0x15470
cmpq $0x0, 0xef79(%rip)      # 0x15470
jne 0x6565
movl -0x3c(%rbp), %edi
movl -0x40(%rbp), %esi
callq 0x7ff0
movq %rax, 0xef65(%rip)      # 0x15470
cmpq $0x0, 0xef55(%rip)      # 0x15468
jne 0x6522
movl -0x3c(%rbp), %edi
movl -0x40(%rbp), %esi
callq 0x7960
jmp 0x6563
movq 0xef3f(%rip), %rax      # 0x15468
movl (%rax), %eax
cmpl -0x3c(%rbp), %eax
jne 0x653f
movq 0xef31(%rip), %rax      # 0x15468
movl 0x4(%rax), %eax
cmpl -0x40(%rbp), %eax
je 0x6561
movq 0xdaaa(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x920f(%rip), %rsi      # 0xf75f
movb $0x0, %al
callq 0x3290
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3480
jmp 0x6563
jmp 0x6565
movq 0xef04(%rip), %rdi      # 0x15470
addq $0x8, %rdi
movslq -0x3c(%rbp), %rax
imulq $0x0, %rax, %rdx
movslq -0x40(%rbp), %rax
imulq %rax, %rdx
xorl %esi, %esi
callq 0x31b0
cmpq $0x0, -0x30(%rbp)
je 0x65d9
movl -0x40(%rbp), %eax
imull -0x44(%rbp), %eax
movl %eax, -0x49c(%rbp)
movslq -0x49c(%rbp), %rdi
addq $0xc, %rdi
callq 0x3330
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rdi
addq $0xc, %rdi
movslq -0x49c(%rbp), %rdx
xorl %esi, %esi
callq 0x31b0
leaq 0xe838(%rip), %rax      # 0x14e18
movq (%rax), %rcx
movq %rcx, -0x488(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x480(%rbp)
movl -0x47c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jle 0x6609
movl -0x40(%rbp), %eax
movl %eax, -0x47c(%rbp)
movl -0x484(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x661d
movl -0x3c(%rbp), %eax
movl %eax, -0x484(%rbp)
movl -0x484(%rbp), %eax
cmpl -0x488(%rbp), %eax
jl 0x6639
movl -0x47c(%rbp), %eax
cmpl -0x480(%rbp), %eax
jge 0x666c
movq 0xd9b0(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x9133(%rip), %rsi      # 0xf77d
movb $0x0, %al
callq 0x3290
movq -0x498(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x490(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x708a
movl -0x484(%rbp), %eax
subl -0x488(%rbp), %eax
movl -0x47c(%rbp), %ecx
subl -0x480(%rbp), %ecx
imull %ecx, %eax
movl %eax, -0x468(%rbp)
cmpl $0x3e8, -0x468(%rbp)    # imm = 0x3E8
jge 0x66cc
movq 0xd950(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x9100(%rip), %rsi      # 0xf7aa
movb $0x0, %al
callq 0x3290
movq -0x498(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x490(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x708a
leaq 0xe325(%rip), %rax      # 0x149f8
cmpl $0x0, (%rax)
jle 0x66ff
movl -0x488(%rbp), %esi
movl -0x484(%rbp), %edx
movl -0x480(%rbp), %ecx
movl -0x47c(%rbp), %r8d
leaq 0x90cc(%rip), %rdi      # 0xf7c4
movb $0x0, %al
callq 0x3170
movq -0x18(%rbp), %rdi
movq 0xed5e(%rip), %rcx      # 0x15468
movq -0x488(%rbp), %rsi
movq -0x480(%rbp), %rdx
callq 0x7ea0
movsd %xmm0, -0x4a8(%rbp)
movq -0x20(%rbp), %rdi
movq 0xed38(%rip), %rcx      # 0x15468
movq -0x488(%rbp), %rsi
movq -0x480(%rbp), %rdx
callq 0x7ea0
movsd %xmm0, -0x4b0(%rbp)
movsd 0x78bd(%rip), %xmm0     # 0xe010
addsd -0x4b0(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0xed13(%rip)      # 0x15478
leaq 0xe28c(%rip), %rax      # 0x149f8
cmpl $0x0, (%rax)
jle 0x678f
movsd -0x4a8(%rbp), %xmm0
movsd -0x4b0(%rbp), %xmm1
leaq 0x905e(%rip), %rdi      # 0xf7e6
movb $0x2, %al
callq 0x3170
movsd 0x7879(%rip), %xmm0     # 0xe010
ucomisd -0x4a8(%rbp), %xmm0
jbe 0x67b1
movsd 0x7867(%rip), %xmm0     # 0xe010
movsd %xmm0, -0x4a8(%rbp)
movsd 0x7857(%rip), %xmm0     # 0xe010
ucomisd -0x4b0(%rbp), %xmm0
jbe 0x67d3
movsd 0x7845(%rip), %xmm0     # 0xe010
movsd %xmm0, -0x4b0(%rbp)
movsd 0x8efd(%rip), %xmm0     # 0xf6d8
divsd -0x4a8(%rbp), %xmm0
movsd %xmm0, -0x4b8(%rbp)
movsd 0x8ee5(%rip), %xmm0     # 0xf6d8
divsd -0x4b0(%rbp), %xmm0
movsd %xmm0, -0x4c0(%rbp)
movsd -0x4b8(%rbp), %xmm0
ucomisd -0x4c0(%rbp), %xmm0
jbe 0x6837
movsd -0x4b8(%rbp), %xmm0
movsd %xmm0, -0x4c8(%rbp)
movsd -0x4c0(%rbp), %xmm0
movsd %xmm0, -0x4d0(%rbp)
jmp 0x6857
movsd -0x4c0(%rbp), %xmm0
movsd %xmm0, -0x4c8(%rbp)
movsd -0x4b8(%rbp), %xmm0
movsd %xmm0, -0x4d0(%rbp)
movsd -0x4c8(%rbp), %xmm0
divsd -0x4d0(%rbp), %xmm0
movsd %xmm0, -0x478(%rbp)
movsd -0x4c8(%rbp), %xmm0
movsd 0x8e61(%rip), %xmm1     # 0xf6e0
ucomisd %xmm1, %xmm0
jbe 0x68c7
movsd 0x8e53(%rip), %xmm0     # 0xf6e0
mulsd -0x4b8(%rbp), %xmm0
divsd -0x4c8(%rbp), %xmm0
movsd %xmm0, -0x4b8(%rbp)
movsd 0x8e33(%rip), %xmm0     # 0xf6e0
mulsd -0x4c0(%rbp), %xmm0
divsd -0x4c8(%rbp), %xmm0
movsd %xmm0, -0x4c0(%rbp)
jmp 0x691b
movsd 0x8e19(%rip), %xmm0     # 0xf6e8
ucomisd -0x4c8(%rbp), %xmm0
jbe 0x6919
movsd 0x8e07(%rip), %xmm0     # 0xf6e8
mulsd -0x4b8(%rbp), %xmm0
divsd -0x4c8(%rbp), %xmm0
movsd %xmm0, -0x4b8(%rbp)
movsd 0x8de7(%rip), %xmm0     # 0xf6e8
mulsd -0x4c0(%rbp), %xmm0
divsd -0x4c8(%rbp), %xmm0
movsd %xmm0, -0x4c0(%rbp)
jmp 0x691b
leaq 0xe0d6(%rip), %rax      # 0x149f8
cmpl $0x0, (%rax)
je 0x6945
movsd -0x4b8(%rbp), %xmm0
movsd -0x4c0(%rbp), %xmm1
leaq 0x8ebf(%rip), %rdi      # 0xf7fd
movb $0x2, %al
callq 0x3170
movsd -0x4b8(%rbp), %xmm0
movsd 0x8d9b(%rip), %xmm1     # 0xf6f0
mulsd %xmm1, %xmm0
movsd 0x76af(%rip), %xmm1     # 0xe010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x46c(%rbp)
movsd -0x4c0(%rbp), %xmm0
movsd 0x8d71(%rip), %xmm1     # 0xf6f0
mulsd %xmm1, %xmm0
movsd 0x7685(%rip), %xmm1     # 0xe010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x470(%rbp)
leaq -0x460(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x31b0
movl -0x480(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x47c(%rbp), %eax
jge 0x6e65
movq $0x0, -0x4e8(%rbp)
movq -0x18(%rbp), %rax
addq $0xc, %rax
movl -0x48(%rbp), %ecx
imull -0x44(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
imull $0x3, -0x488(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x4d8(%rbp)
movq -0x20(%rbp), %rax
addq $0xc, %rax
movl -0x48(%rbp), %ecx
imull -0x44(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
imull $0x3, -0x488(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x4e0(%rbp)
movq 0xea48(%rip), %rax      # 0x15470
addq $0x8, %rax
movl -0x3c(%rbp), %ecx
imull -0x48(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x4f8(%rbp)
movq 0xea1d(%rip), %rax      # 0x15468
addq $0x8, %rax
movl -0x3c(%rbp), %ecx
imull -0x48(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x4f0(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x6a8a
movq -0x58(%rbp), %rax
addq $0xc, %rax
movl -0x48(%rbp), %ecx
imull -0x44(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x4e8(%rbp)
movl -0x488(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x484(%rbp), %eax
jge 0x6e57
movq -0x4f0(%rbp), %rax
movslq -0x4c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x6e13
movq -0x4d8(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x510(%rbp)
movq -0x4d8(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl -0x510(%rbp), %eax
jle 0x6aeb
movq -0x4d8(%rbp), %rax
movzbl 0x1(%rax), %eax
movl %eax, -0x510(%rbp)
movq -0x4d8(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl -0x510(%rbp), %eax
jle 0x6b0f
movq -0x4d8(%rbp), %rax
movzbl 0x2(%rax), %eax
movl %eax, -0x510(%rbp)
movl -0x46c(%rbp), %eax
imull -0x510(%rbp), %eax
movl %eax, -0x510(%rbp)
movq -0x4e0(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x514(%rbp)
movq -0x4e0(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl -0x510(%rbp), %eax
jle 0x6b56
movq -0x4e0(%rbp), %rax
movzbl 0x1(%rax), %eax
movl %eax, -0x510(%rbp)
movq -0x4e0(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl -0x510(%rbp), %eax
jle 0x6b7a
movq -0x4e0(%rbp), %rax
movzbl 0x2(%rax), %eax
movl %eax, -0x510(%rbp)
movl -0x470(%rbp), %eax
imull -0x514(%rbp), %eax
movl %eax, -0x514(%rbp)
movl -0x514(%rbp), %eax
cmpl -0x510(%rbp), %eax
jle 0x6ba9
movl -0x514(%rbp), %eax
movl %eax, -0x538(%rbp)
jmp 0x6bb5
movl -0x510(%rbp), %eax
movl %eax, -0x538(%rbp)
movl -0x538(%rbp), %eax
movl %eax, -0x50c(%rbp)
movl -0x50c(%rbp), %eax
sarl $0x8, %eax
movl %eax, -0x50c(%rbp)
cmpl $0x28, -0x50c(%rbp)
jge 0x6be3
movl $0x28, -0x50c(%rbp)
movq -0x4d8(%rbp), %rax
movzbl (%rax), %eax
imull -0x46c(%rbp), %eax
movq -0x4e0(%rbp), %rcx
movzbl (%rcx), %ecx
imull -0x470(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x4fc(%rbp)
movq -0x4d8(%rbp), %rax
movzbl 0x1(%rax), %eax
imull -0x46c(%rbp), %eax
movq -0x4e0(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
imull -0x470(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x500(%rbp)
movq -0x4d8(%rbp), %rax
movzbl 0x2(%rax), %eax
imull -0x46c(%rbp), %eax
movq -0x4e0(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
imull -0x470(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x504(%rbp)
cmpl $0x0, -0x4fc(%rbp)
jge 0x6c7c
xorl %eax, %eax
subl -0x4fc(%rbp), %eax
movl %eax, -0x4fc(%rbp)
cmpl $0x0, -0x500(%rbp)
jge 0x6c93
xorl %eax, %eax
subl -0x500(%rbp), %eax
movl %eax, -0x500(%rbp)
cmpl $0x0, -0x504(%rbp)
jge 0x6caa
xorl %eax, %eax
subl -0x504(%rbp), %eax
movl %eax, -0x504(%rbp)
movl -0x4fc(%rbp), %eax
movl -0x500(%rbp), %ecx
shll %ecx
addl %ecx, %eax
addl -0x504(%rbp), %eax
sarl $0x8, %eax
movl %eax, -0x508(%rbp)
imull $0x78, -0x508(%rbp), %eax
cltd
idivl -0x50c(%rbp)
movl %eax, -0x508(%rbp)
cmpl $0x100, -0x508(%rbp)    # imm = 0x100
jl 0x6cf3
movl $0xff, -0x508(%rbp)
cmpl $0x0, -0x508(%rbp)
jge 0x6d1e
movq 0xd2ed(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x8b26(%rip), %rsi      # 0xf833
movb $0x0, %al
callq 0x3290
movl $0x0, -0x508(%rbp)
movslq -0x508(%rbp), %rax
movl -0x460(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x460(%rbp,%rax,4)
movl -0x508(%rbp), %edx
movq -0x4f8(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
cmpq $0x0, -0x30(%rbp)
je 0x6e11
imull $0x3c, -0x4fc(%rbp), %eax
cltd
idivl -0x50c(%rbp)
sarl $0x6, %eax
movl %eax, -0x4fc(%rbp)
cmpl $0xff, -0x4fc(%rbp)
jle 0x6d82
movl $0xff, -0x4fc(%rbp)
imull $0x3c, -0x500(%rbp), %eax
cltd
idivl -0x50c(%rbp)
sarl $0x6, %eax
movl %eax, -0x500(%rbp)
cmpl $0xff, -0x500(%rbp)
jle 0x6daf
movl $0xff, -0x500(%rbp)
imull $0x3c, -0x504(%rbp), %eax
cltd
idivl -0x50c(%rbp)
sarl $0x6, %eax
movl %eax, -0x504(%rbp)
cmpl $0xff, -0x504(%rbp)
jle 0x6ddc
movl $0xff, -0x504(%rbp)
movl -0x4fc(%rbp), %eax
movb %al, %cl
movq -0x4e8(%rbp), %rax
movb %cl, (%rax)
movl -0x500(%rbp), %eax
movb %al, %cl
movq -0x4e8(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x504(%rbp), %eax
movb %al, %cl
movq -0x4e8(%rbp), %rax
movb %cl, 0x2(%rax)
jmp 0x6e13
movq -0x4e8(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x4e8(%rbp)
movq -0x4d8(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x4d8(%rbp)
movq -0x4e0(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x4e0(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6a93
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x69b5
cmpq $0x0, -0x30(%rbp)
je 0x6e82
movq -0x30(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x8bf0
movq -0x58(%rbp), %rdi
callq 0x3040
leaq 0xdb6f(%rip), %rax      # 0x149f8
cmpl $0x1, (%rax)
jle 0x6f20
leaq 0x89b0(%rip), %rdi      # 0xf849
movb $0x0, %al
callq 0x3170
movl $0x0, -0x464(%rbp)
cmpl $0x3c, -0x464(%rbp)
jge 0x6f1e
movl -0x464(%rbp), %esi
movslq -0x464(%rbp), %rax
movl -0x460(%rbp,%rax,4), %edx
movl -0x464(%rbp), %eax
addl $0x1, %eax
cltq
movl -0x460(%rbp,%rax,4), %ecx
movl -0x464(%rbp), %eax
addl $0x2, %eax
cltq
movl -0x460(%rbp,%rax,4), %r8d
movl -0x464(%rbp), %eax
addl $0x3, %eax
cltq
movl -0x460(%rbp,%rax,4), %r9d
leaq 0x8959(%rip), %rdi      # 0xf85f
movb $0x0, %al
callq 0x3170
movl -0x464(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x464(%rbp)
jmp 0x6eaa
jmp 0x6f20
movl $0x0, -0x51c(%rbp)
movl -0x468(%rbp), %eax
shll %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, -0x520(%rbp)
movl $0x0, -0x464(%rbp)
cmpl $0x100, -0x464(%rbp)    # imm = 0x100
jge 0x6f91
movl -0x51c(%rbp), %eax
cmpl -0x520(%rbp), %eax
jl 0x6f66
jmp 0x6f91
movslq -0x464(%rbp), %rax
movl -0x460(%rbp,%rax,4), %eax
addl -0x51c(%rbp), %eax
movl %eax, -0x51c(%rbp)
movl -0x464(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
jmp 0x6f4a
imull $0x3, -0x464(%rbp), %eax
addl $0xc, %eax
movl %eax, -0x518(%rbp)
cmpl $0x1e, -0x518(%rbp)
jge 0x6fb4
movl $0x1e, -0x518(%rbp)
movsd -0x478(%rbp), %xmm0
movsd 0x8734(%rip), %xmm1     # 0xf6f8
mulsd %xmm1, %xmm0
movsd 0x8730(%rip), %xmm1     # 0xf700
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x524(%rbp)
movl -0x518(%rbp), %eax
cmpl -0x524(%rbp), %eax
jle 0x701a
movl -0x524(%rbp), %eax
movl %eax, -0x518(%rbp)
leaq 0xd9f9(%rip), %rax      # 0x149f8
cmpl $0x0, (%rax)
je 0x7018
movl -0x518(%rbp), %esi
leaq 0x8863(%rip), %rdi      # 0xf874
movb $0x0, %al
callq 0x3170
jmp 0x7042
leaq 0xd9d7(%rip), %rax      # 0x149f8
cmpl $0x0, (%rax)
je 0x7040
movl -0x464(%rbp), %esi
movl -0x518(%rbp), %edx
leaq 0x8858(%rip), %rdi      # 0xf891
movb $0x0, %al
callq 0x3170
jmp 0x7042
movl -0x518(%rbp), %edx
movl -0x24(%rbp), %ecx
movl -0x28(%rbp), %r8d
movq -0x38(%rbp), %r9
movq -0x488(%rbp), %rdi
movq -0x480(%rbp), %rsi
callq 0x70a0
movq %rax, -0x534(%rbp)
movq %rdx, -0x52c(%rbp)
movq -0x534(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x52c(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rdx
addq $0x540, %rsp            # imm = 0x540
popq %rbp
retq
nopl (%rax,%rax)