// File: brianwu02[P]ImageProcessing/error_diffusion.cpp
// Function: error_diffusion(imageS*, int, int, float, imageS*)
void error_diffusion(imageP I1, int mtd, int serpentine, float gamma, imageP I2) {
    int i, total, threshold;
    unsigned char *in;
    unsigned char *out;
    unsigned char gammaCorrectionLUT[256];
    unsigned char thresholdingLUT[256];

    total = I1->width * I1->height;
    I2->width = I1->width;
    I2->height = I1->height;

    I2->image = (unsigned char *) malloc(total);

    out = I2->image;
    in = I1->image;

    if (I2->image == NULL) {
        cerr << "Not enough memory\n";
        exit(1);
    }

    // create gamma correction lookup table
    for (i=0; i<256; i++) {
        gammaCorrectionLUT[i] = (int) (pow((double) i / 255.0, (1.0 / gamma)) * 255.0);
    }

    // gamma correct the input Image
    for (i=0; i<total; i++) {
        in[i] = gammaCorrectionLUT[in[i]];
    }

    // create thresholding scale
    threshold = 255 / 2;
    
    // create circular buffer. this one here is only 2 'widths' long.

    int h = I1->height;
    int w = I1->width;

    // mtd=0; manually copy row 0 to the circular buffer. Floyd-Steinberg Algorithm
    if (mtd == 0) {
        short buf[1][w+2];

        //short bufer[10];
        //short *buf1 = bufer;

        // pad the buffer
        buf[0][0] = 0;
        buf[0][(w+2) -1] = 0;
        buf[1][0] = 0;
        buf[1][(w+2) -1] = 0;

        for (int i = 0; i < w; i++) {
            buf[0][i+1] = in[i];
        }
        
        for (int y=0; y<h; y++) {
            // manually copy row 1 in to the circular buffer.
            if ((y % 2) == 0) {
                // if y is even, copy to buf[1]
                for (int i = 0; i < w; i++) {
                    buf[1][i+1] = in[y*w+i];
                }
            } else {
                // if y is odd, copy to buf[0]
                for (int i = 0; i < w; i++) {
                    buf[0][i+1] = in[y*w+i];
                }
            }
            
            int p = 1;

            for (int x=0; x<w; x++) {

                *out = (buf[0][p] < threshold) ? 0 : 255;
                short e = (buf[0][p] - *out);
                
                buf[0][p+1] += (e*7/16.0);
                buf[1][p-1] += (e*3/16.0); // error to SW
                buf[1][p] += (e*5/16.0);   // error to S
                buf[1][p+1] += (e*1/16.0); // error to SE
                p++;
                out++;
            }
        }
    } else {
        short buf[2][w+4];

        // pad the buffer, 2 deep.
        buf[0][0] = 0;
        buf[0][1] = 0;
        buf[0][(w+4) -1] = 0;
        buf[0][(w+4) -2] = 0;

        buf[1][0] = 0;
        buf[1][1] = 0;
        buf[1][(w+4) -1] = 0;
        buf[1][(w+4) -2] = 0;

        buf[2][0] = 0;
        buf[2][1] = 0;
        buf[2][(w+4) -1] = 0;
        buf[2][(w+4) -2] = 0;

        // mtd=1; for Jarvis-Judice-Ninke Error diffusion algorithm, need buffers.
        for (int i = 0; i < w; i++) {
            buf[0][i+2] = in[i];
            buf[1][i+2] = in[i+w];
        }
        // circular buffer logic.
        for (int y=0; y<h; y++) {
            if ((y % 3) == 0) {
                for (int i = 0; i < w; i++) {
                    buf[2][i+2] = in[y*w+i];
                }
            }
            if ((y % 3) == 1) {
                for (int i = 0; i < w; i++) {
                   buf[0][i+2] = in[y*w+i];
                }
            }
            if ((y % 3) == 2) {
                for (int i = 0; i < w; i++) {
                    buf[1][i+2] = in[y*w+i];
                }
            }

            int p = 2;
            for (int x=0; x<w; x++) {
                *out = (buf[0][p] < threshold) ? 0 : 255;
                //cout << (int) buf[0][p] << endl;
                short e = (buf[0][p] - *out);

                buf[0][p+1] += (e*7/48.0);
                buf[0][p+2] += (e*5/48.0);
                buf[1][p-2] += (e*3/48.0);
                buf[1][p-1] += (e*5/48.0);
                buf[1][p] += (e*7/48.0);
                buf[1][p+1] += (e*5/48.0);
                buf[1][p+2] += (e*3/48.0);

                buf[2][p-2] += (e*1/48.0);
                buf[2][p-1] += (e*3/48.0);
                buf[2][p] += (e*5/48.0);
                buf[2][p+1] += (e*3/48.0);
                buf[2][p+2] += (e*1/48.0);

                p++;
                out++;
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movss %xmm0, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movq -0x8(%rbp), %rcx
imull 0x4(%rcx), %eax
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movslq -0x28(%rbp), %rdi
callq 0x1120
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x159d
movq 0x3a69(%rip), %rdi      # 0x4ff0
leaq 0x1acc(%rip), %rsi      # 0x305a
callq 0x10a0
movl $0x1, %edi
callq 0x10e0
movl $0x0, -0x24(%rbp)
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
jge 0x1600
cvtsi2sdl -0x24(%rbp), %xmm0
movsd 0x1a5e(%rip), %xmm1     # 0x3018
divsd %xmm1, %xmm0
movss -0x14(%rbp), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x1a51(%rip), %xmm1     # 0x3020
divsd %xmm2, %xmm1
callq 0x1180
movsd 0x1a38(%rip), %xmm1     # 0x3018
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, %cl
movslq -0x24(%rbp), %rax
movb %cl, -0x140(%rbp,%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x15a4
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x1638
movq -0x38(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movb -0x140(%rbp,%rax), %dl
movq -0x38(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1607
movl $0x7f, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x244(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x248(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x19fa
movl -0x248(%rbp), %eax
addl $0x2, %eax
movl %eax, %ecx
movq %rcx, -0x2b8(%rbp)
movq %rsp, %rax
movq %rax, -0x250(%rbp)
leaq 0xf(%rcx,%rcx), %rdx
andq $-0x10, %rdx
movq %rsp, %rax
subq %rdx, %rax
movq %rax, -0x2b0(%rbp)
movq %rax, %rsp
movq %rcx, -0x258(%rbp)
imulq $0x0, %rcx, %rdx
movw $0x0, (%rax,%rdx,2)
imulq $0x0, %rcx, %rsi
shlq %rsi
movq %rax, %rdx
addq %rsi, %rdx
movl -0x248(%rbp), %esi
addl $0x2, %esi
subl $0x1, %esi
movslq %esi, %rsi
movw $0x0, (%rdx,%rsi,2)
movq %rcx, %rdx
shlq $0x0, %rdx
movw $0x0, (%rax,%rdx,2)
shlq $0x0, %rcx
shlq %rcx
addq %rcx, %rax
movl -0x248(%rbp), %ecx
addl $0x2, %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movw $0x0, (%rax,%rcx,2)
movl $0x0, -0x25c(%rbp)
movl -0x25c(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x1756
movq -0x2b0(%rbp), %rax
movq -0x2b8(%rbp), %rcx
movq -0x38(%rbp), %rdx
movslq -0x25c(%rbp), %rsi
movzbl (%rdx,%rsi), %edx
imulq $0x0, %rcx, %rcx
shlq %rcx
addq %rcx, %rax
movl -0x25c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movl -0x25c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x25c(%rbp)
jmp 0x1700
movl $0x0, -0x260(%rbp)
movl -0x260(%rbp), %eax
cmpl -0x244(%rbp), %eax
jge 0x19eb
movl -0x260(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x17f6
movl $0x0, -0x264(%rbp)
movl -0x264(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x17f4
movq -0x2b0(%rbp), %rax
movq -0x2b8(%rbp), %rcx
movq -0x38(%rbp), %rdx
movl -0x260(%rbp), %esi
imull -0x248(%rbp), %esi
addl -0x264(%rbp), %esi
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
shlq $0x0, %rcx
shlq %rcx
addq %rcx, %rax
movl -0x264(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movl -0x264(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x264(%rbp)
jmp 0x178f
jmp 0x1867
movl $0x0, -0x268(%rbp)
movl -0x268(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x1865
movq -0x2b0(%rbp), %rax
movq -0x2b8(%rbp), %rcx
movq -0x38(%rbp), %rdx
movl -0x260(%rbp), %esi
imull -0x248(%rbp), %esi
addl -0x268(%rbp), %esi
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
imulq $0x0, %rcx, %rcx
shlq %rcx
addq %rcx, %rax
movl -0x268(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movl -0x268(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x268(%rbp)
jmp 0x1800
jmp 0x1867
movl $0x1, -0x26c(%rbp)
movl $0x0, -0x270(%rbp)
movl -0x270(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x19d5
movq -0x2b0(%rbp), %rax
movq -0x2b8(%rbp), %rcx
movslq -0x26c(%rbp), %rdx
movswl (%rax,%rdx,2), %edx
movl -0x2c(%rbp), %esi
subl %esi, %edx
setge %sil
negb %sil
movq -0x40(%rbp), %rdx
movb %sil, (%rdx)
movslq -0x26c(%rbp), %rdx
movzwl (%rax,%rdx,2), %edx
movq -0x40(%rbp), %rsi
movzbl (%rsi), %esi
subl %esi, %edx
movw %dx, -0x272(%rbp)
movswl -0x272(%rbp), %esi
movl %esi, %edx
shll $0x3, %edx
subl %esi, %edx
cvtsi2sd %edx, %xmm2
movsd 0x1722(%rip), %xmm0     # 0x3010
mulsd %xmm0, %xmm2
movslq -0x26c(%rbp), %rdx
movswl 0x2(%rax,%rdx,2), %esi
cvtsi2sd %esi, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
movw %si, 0x2(%rax,%rdx,2)
movswl -0x272(%rbp), %esi
movl %esi, %edx
leal (%rdx,%rdx,2), %edx
cvtsi2sd %edx, %xmm2
mulsd %xmm0, %xmm2
leaq (%rax,%rcx,2), %rax
movl -0x26c(%rbp), %ecx
decl %ecx
movslq %ecx, %rcx
movswl (%rax,%rcx,2), %edx
cvtsi2sd %edx, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %edx
movw %dx, (%rax,%rcx,2)
movswl -0x272(%rbp), %edx
movl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
cvtsi2sd %ecx, %xmm2
mulsd %xmm0, %xmm2
movslq -0x26c(%rbp), %rcx
movswl (%rax,%rcx,2), %edx
cvtsi2sd %edx, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %edx
movw %dx, (%rax,%rcx,2)
movswl -0x272(%rbp), %ecx
cvtsi2sd %ecx, %xmm1
mulsd %xmm0, %xmm1
movslq -0x26c(%rbp), %rdx
movq %rdx, %rcx
incq %rcx
movswl 0x2(%rax,%rdx,2), %edx
cvtsi2sd %edx, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movw %dx, (%rax,%rcx,2)
movl -0x26c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x26c(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movl -0x270(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x270(%rbp)
jmp 0x187b
jmp 0x19d7
movl -0x260(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x260(%rbp)
jmp 0x1760
movq -0x250(%rbp), %rax
movq %rax, %rsp
jmp 0x20cb
movl -0x248(%rbp), %eax
addl $0x4, %eax
movl %eax, %ecx
movq %rcx, -0x2c8(%rbp)
movq %rsp, %rax
movq %rax, -0x280(%rbp)
leaq 0xf(,%rcx,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rax
subq %rdx, %rax
movq %rax, -0x2c0(%rbp)
movq %rax, %rsp
movq %rcx, -0x288(%rbp)
imulq $0x0, %rcx, %rdx
movw $0x0, (%rax,%rdx,2)
imulq $0x0, %rcx, %rdx
movw $0x0, 0x2(%rax,%rdx,2)
imulq $0x0, %rcx, %rsi
shlq %rsi
movq %rax, %rdx
addq %rsi, %rdx
movl -0x248(%rbp), %esi
addl $0x4, %esi
subl $0x1, %esi
movslq %esi, %rsi
movw $0x0, (%rdx,%rsi,2)
imulq $0x0, %rcx, %rsi
shlq %rsi
movq %rax, %rdx
addq %rsi, %rdx
movl -0x248(%rbp), %esi
addl $0x4, %esi
subl $0x2, %esi
movslq %esi, %rsi
movw $0x0, (%rdx,%rsi,2)
movq %rcx, %rdx
shlq $0x0, %rdx
movw $0x0, (%rax,%rdx,2)
movq %rcx, %rdx
shlq $0x0, %rdx
movw $0x0, 0x2(%rax,%rdx,2)
movq %rcx, %rsi
shlq $0x0, %rsi
shlq %rsi
movq %rax, %rdx
addq %rsi, %rdx
movl -0x248(%rbp), %esi
addl $0x4, %esi
subl $0x1, %esi
movslq %esi, %rsi
movw $0x0, (%rdx,%rsi,2)
movq %rcx, %rsi
shlq $0x0, %rsi
shlq %rsi
movq %rax, %rdx
addq %rsi, %rdx
movl -0x248(%rbp), %esi
addl $0x4, %esi
subl $0x2, %esi
movslq %esi, %rsi
movw $0x0, (%rdx,%rsi,2)
movq %rcx, %rdx
shlq %rdx
movw $0x0, (%rax,%rdx,2)
movq %rcx, %rdx
shlq %rdx
movw $0x0, 0x2(%rax,%rdx,2)
movq %rcx, %rsi
shlq %rsi
shlq %rsi
movq %rax, %rdx
addq %rsi, %rdx
movl -0x248(%rbp), %esi
addl $0x4, %esi
subl $0x1, %esi
movslq %esi, %rsi
movw $0x0, (%rdx,%rsi,2)
shlq %rcx
shlq %rcx
addq %rcx, %rax
movl -0x248(%rbp), %ecx
addl $0x4, %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movw $0x0, (%rax,%rcx,2)
movl $0x0, -0x28c(%rbp)
movl -0x28c(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x1bf0
movq -0x2c0(%rbp), %rax
movq -0x2c8(%rbp), %rcx
movq -0x38(%rbp), %rdx
movslq -0x28c(%rbp), %rsi
movzbl (%rdx,%rsi), %edx
movw %dx, %di
imulq $0x0, %rcx, %rsi
shlq %rsi
movq %rax, %rdx
addq %rsi, %rdx
movl -0x28c(%rbp), %esi
addl $0x2, %esi
movslq %esi, %rsi
movw %di, (%rdx,%rsi,2)
movq -0x38(%rbp), %rdx
movl -0x28c(%rbp), %esi
addl -0x248(%rbp), %esi
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
shlq $0x0, %rcx
shlq %rcx
addq %rcx, %rax
movl -0x28c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movl -0x28c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28c(%rbp)
jmp 0x1b5c
movl $0x0, -0x290(%rbp)
movl -0x290(%rbp), %eax
cmpl -0x244(%rbp), %eax
jge 0x20c1
movl -0x290(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x1c8f
movl $0x0, -0x294(%rbp)
movl -0x294(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x1c8d
movq -0x2c0(%rbp), %rax
movq -0x2c8(%rbp), %rcx
movq -0x38(%rbp), %rdx
movl -0x290(%rbp), %esi
imull -0x248(%rbp), %esi
addl -0x294(%rbp), %esi
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
shlq %rcx
shlq %rcx
addq %rcx, %rax
movl -0x294(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movl -0x294(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x294(%rbp)
jmp 0x1c29
jmp 0x1c8f
movl -0x290(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x1d13
movl $0x0, -0x298(%rbp)
movl -0x298(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x1d11
movq -0x2c0(%rbp), %rax
movq -0x2c8(%rbp), %rcx
movq -0x38(%rbp), %rdx
movl -0x290(%rbp), %esi
imull -0x248(%rbp), %esi
addl -0x298(%rbp), %esi
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
imulq $0x0, %rcx, %rcx
shlq %rcx
addq %rcx, %rax
movl -0x298(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movl -0x298(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x298(%rbp)
jmp 0x1cac
jmp 0x1d13
movl -0x290(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
cmpl $0x2, %edx
jne 0x1d97
movl $0x0, -0x29c(%rbp)
movl -0x29c(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x1d95
movq -0x2c0(%rbp), %rax
movq -0x2c8(%rbp), %rcx
movq -0x38(%rbp), %rdx
movl -0x290(%rbp), %esi
imull -0x248(%rbp), %esi
addl -0x29c(%rbp), %esi
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
shlq $0x0, %rcx
shlq %rcx
addq %rcx, %rax
movl -0x29c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movl -0x29c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x29c(%rbp)
jmp 0x1d30
jmp 0x1d97
movl $0x2, -0x2a0(%rbp)
movl $0x0, -0x2a4(%rbp)
movl -0x2a4(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x20ab
movq -0x2c0(%rbp), %rax
movq -0x2c8(%rbp), %rcx
movslq -0x2a0(%rbp), %rdx
movswl (%rax,%rdx,2), %edx
movl -0x2c(%rbp), %esi
subl %esi, %edx
setge %sil
negb %sil
movq -0x40(%rbp), %rdx
movb %sil, (%rdx)
movslq -0x2a0(%rbp), %rdx
movzwl (%rax,%rdx,2), %edx
movq -0x40(%rbp), %rsi
movzbl (%rsi), %esi
subl %esi, %edx
movw %dx, -0x2a6(%rbp)
movswl -0x2a6(%rbp), %esi
movl %esi, %edx
shll $0x3, %edx
subl %esi, %edx
cvtsi2sd %edx, %xmm2
movsd 0x11ea(%rip), %xmm0     # 0x3008
movsd %xmm0, -0x2e0(%rbp)
divsd %xmm0, %xmm2
movslq -0x2a0(%rbp), %rdx
movswl 0x2(%rax,%rdx,2), %esi
cvtsi2sd %esi, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
movw %si, 0x2(%rax,%rdx,2)
movswl -0x2a6(%rbp), %esi
movl %esi, %edx
leal (%rdx,%rdx,4), %edx
cvtsi2sd %edx, %xmm2
divsd %xmm0, %xmm2
movslq -0x2a0(%rbp), %rdx
movswl 0x4(%rax,%rdx,2), %esi
cvtsi2sd %esi, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
movw %si, 0x4(%rax,%rdx,2)
movswl -0x2a6(%rbp), %esi
movl %esi, %edx
leal (%rdx,%rdx,2), %edx
cvtsi2sd %edx, %xmm2
divsd %xmm0, %xmm2
leaq (%rax,%rcx,2), %rdx
movq %rdx, -0x2d8(%rbp)
movl -0x2a0(%rbp), %esi
addl $-0x2, %esi
movslq %esi, %rsi
movswl (%rdx,%rsi,2), %edi
cvtsi2sd %edi, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movw %di, (%rdx,%rsi,2)
movswl -0x2a6(%rbp), %edi
movl %edi, %esi
leal (%rsi,%rsi,4), %esi
cvtsi2sd %esi, %xmm2
divsd %xmm0, %xmm2
movl -0x2a0(%rbp), %esi
decl %esi
movslq %esi, %rsi
movswl (%rdx,%rsi,2), %edi
cvtsi2sd %edi, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movw %di, (%rdx,%rsi,2)
movswl -0x2a6(%rbp), %edi
movl %edi, %esi
shll $0x3, %esi
subl %edi, %esi
cvtsi2sd %esi, %xmm2
divsd %xmm0, %xmm2
movslq -0x2a0(%rbp), %rsi
movswl (%rdx,%rsi,2), %edi
cvtsi2sd %edi, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movw %di, (%rdx,%rsi,2)
movswl -0x2a6(%rbp), %edi
movl %edi, %esi
leal (%rsi,%rsi,4), %esi
cvtsi2sd %esi, %xmm2
divsd %xmm0, %xmm2
movslq -0x2a0(%rbp), %rsi
movswl 0x2(%rdx,%rsi,2), %edi
cvtsi2sd %edi, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movw %di, 0x2(%rdx,%rsi,2)
movswl -0x2a6(%rbp), %edi
movl %edi, %esi
leal (%rsi,%rsi,2), %esi
cvtsi2sd %esi, %xmm2
divsd %xmm0, %xmm2
movslq -0x2a0(%rbp), %rsi
movswl 0x4(%rdx,%rsi,2), %edi
cvtsi2sd %edi, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movw %di, 0x4(%rdx,%rsi,2)
movswl -0x2a6(%rbp), %edx
cvtsi2sd %edx, %xmm2
divsd %xmm0, %xmm2
leaq (%rax,%rcx,4), %rax
movq %rax, -0x2d0(%rbp)
movl -0x2a0(%rbp), %ecx
addl $-0x2, %ecx
movslq %ecx, %rcx
movswl (%rax,%rcx,2), %edx
cvtsi2sd %edx, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %edx
movw %dx, (%rax,%rcx,2)
movswl -0x2a6(%rbp), %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
cvtsi2sd %ecx, %xmm2
divsd %xmm0, %xmm2
movl -0x2a0(%rbp), %ecx
decl %ecx
movslq %ecx, %rcx
movswl (%rax,%rcx,2), %edx
cvtsi2sd %edx, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %edx
movw %dx, (%rax,%rcx,2)
movswl -0x2a6(%rbp), %edx
movl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
cvtsi2sd %ecx, %xmm2
divsd %xmm0, %xmm2
movslq -0x2a0(%rbp), %rcx
movswl (%rax,%rcx,2), %edx
cvtsi2sd %edx, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %edx
movw %dx, (%rax,%rcx,2)
movswl -0x2a6(%rbp), %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
cvtsi2sd %ecx, %xmm2
divsd %xmm0, %xmm2
movslq -0x2a0(%rbp), %rcx
movswl 0x2(%rax,%rcx,2), %edx
cvtsi2sd %edx, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %edx
movw %dx, 0x2(%rax,%rcx,2)
movswl -0x2a6(%rbp), %ecx
cvtsi2sd %ecx, %xmm1
divsd %xmm0, %xmm1
movslq -0x2a0(%rbp), %rdx
movq %rdx, %rcx
addq $0x2, %rcx
movswl 0x4(%rax,%rdx,2), %edx
cvtsi2sd %edx, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movw %dx, (%rax,%rcx,2)
movl -0x2a0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a0(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movl -0x2a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a4(%rbp)
jmp 0x1dab
jmp 0x20ad
movl -0x290(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x290(%rbp)
jmp 0x1bfa
movq -0x280(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq