// File: /workspace/github_cpp_makefile_star2_O3/rapirent[P]JPEG/decoder.c
// Function: calculate_mcu(_IO_FILE*, char const*)
void calculate_mcu(FILE* fp, const char* fwrite)
{
    int mcu_width = 8 * f0.hmax;
    int mcu_height = 8 * f0.vmax;
    int mcus_on_x = (f0.width - 1) / mcu_width + 1;
    int mcus_on_y = (f0.height - 1) / mcu_height + 1;
    mcu_small_block* data_unit = (mcu_small_block*) malloc(mcus_on_y*mcus_on_x*5*mcu_width*mcu_height*sizeof(
                                     mcu_small_block));

    for (int i  = 0; i<mcus_on_y; i++) {
        for (int j = 0; j<mcus_on_x; j++) {
            for (int component_id = 0; component_id<f0.components_num; component_id++)  {
                for (int a =0; a<f0.frame_components[component_id].vertical_sample; a++) {
                    for (int b = 0; b<f0.frame_components[component_id].horizontal_sample; b++) {
                        calcualte_mcu_block(fp, component_id);
                        for (int x = 0; x < 8; x++) {
                            for (int y = 0; y < 8; y++) {
                                data_unit[i*mcus_on_x*5*mcu_width*mcu_height
                                          + j*5*mcu_width*mcu_height
                                          + component_id*mcu_width*mcu_height
                                          + a*mcu_height
                                          + b][x][y] = block[x][y];
                            }
                        }
                    }
                }
            }
        }
    }
    rgb_element mcu_rgb[mcus_on_x*mcus_on_y][mcu_height][mcu_width];
    rgb_element rgb_image[f0.width][f0.height];
    int yV = f0.vmax/f0.frame_components[0].vertical_sample,
        yH = f0.hmax/f0.frame_components[0].horizontal_sample,
        cbV = f0.vmax/f0.frame_components[1].vertical_sample,
        cbH =f0.hmax/ f0.frame_components[1].horizontal_sample,
        crV = f0.vmax/f0.frame_components[2].vertical_sample,
        crH =f0.hmax/ f0.frame_components[2].horizontal_sample;
    for (int i  = 0; i<mcus_on_y; i++) {
        for (int j = 0; j<mcus_on_x; j++) {
            //1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q
            for (int a = 0; a < mcu_height; a++) {
                for (int b = 0; b < mcu_width; b++) {
                    double Y = data_unit[i*mcus_on_x*5*mcu_width*mcu_height
                                         + j*5*mcu_width*mcu_height
                                         + 0*mcu_width*mcu_height
                                         + (a/(8*yV))*mcu_height
                                         + (b/(8*yH))][(a % (8*yV)) /yV][(b % (8*yH)) /yH],
                               Cb = data_unit[i*mcus_on_x*5*mcu_width*mcu_height
                                              + j*5*mcu_width*mcu_height
                                              + 1*mcu_width*mcu_height
                                              + (a/(8*cbV))*mcu_height
                                              + b/(8*cbH)][(a % (8*cbV)) /cbV][(b % (8*cbH)) /cbH],
                                    Cr = data_unit[i*mcus_on_x*5*mcu_width*mcu_height
                                                   + j*5*mcu_width*mcu_height
                                                   + 2*mcu_width*mcu_height
                                                   + (a/(8*crV))*mcu_height
                                                   + b/(8*crH)][(a % (8*crV)) /crV][(b % (8*crH)) /crH];
                    double R = Y + 1.402*(Cr - 128),
                           G = Y - 0.34414*(Cb - 128) - 0.71414*(Cr -  128),
                           B = Y + 1.772*(Cb - 128);
                    mcu_rgb[i*mcus_on_x + j][a][b].r = (byte)(R > 255.0 ? 255.0 : (R < 0.0 ? 0.0 : R));
                    mcu_rgb[i*mcus_on_x + j][a][b].g = (byte)(G > 255.0 ? 255.0 : (G < 0.0 ? 0.0 : G));
                    mcu_rgb[i*mcus_on_x + j][a][b].b = (byte)(B > 255.0 ? 255.0 : (B < 0.0 ? 0.0 : B));
                }
            }
        }
    }
    free(data_unit);
    bitmap_image outimg(f0.width,f0.height);

    for (int y = 0; y < f0.height; y++) {
        for (int x = 0; x < f0.width; x++) {
            outimg.set_pixel(x,y,mcu_rgb[y/mcu_height * mcus_on_x + x/mcu_width][y%mcu_height][x%mcu_width].r
                             ,mcu_rgb[y/mcu_height * mcus_on_x + x/mcu_width][y%mcu_height][x%mcu_width].g
                             ,mcu_rgb[y/mcu_height * mcus_on_x + x/mcu_width][y%mcu_height][x%mcu_width].b);
        }
    }
    outimg.save_image(fwrite);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rsi, -0x110(%rbp)
movq %rdi, %r13
movb 0x5e3d(%rip), %bl       # 0xbc65
movzbl %bl, %eax
movq %rax, -0x60(%rbp)
leal (,%rax,8), %ecx
movb 0x5e27(%rip), %r14b     # 0xbc64
movzbl %r14b, %r15d
leal (,%r15,8), %esi
movzwl 0x5e12(%rip), %eax      # 0xbc62
decl %eax
cltd
idivl %ecx
movq %rax, -0x50(%rbp)
leal 0x1(%rax), %edi
movzwl 0x5dfd(%rip), %eax      # 0xbc60
decl %eax
cltd
idivl %esi
movl %eax, %r12d
leal 0x1(%r12), %eax
movl %eax, -0x98(%rbp)
movl %eax, %edx
movl %edi, -0x30(%rbp)
imull %edi, %edx
movq %rcx, -0x58(%rbp)
leal (%rcx,%rcx,4), %eax
movl %eax, -0xe4(%rbp)
movl %eax, %edi
movl %esi, -0x2c(%rbp)
imull %esi, %edi
movl %edx, -0xa0(%rbp)
imull %edx, %edi
shlq $0x9, %rdi
callq 0x5180
movq %r12, -0x68(%rbp)
testl %r12d, %r12d
movq %rax, -0xe0(%rbp)
js 0x6070
movq %rax, %rsi
movq -0x50(%rbp), %rax
leal (%rax,%rax,4), %eax
addl $0x5, %eax
movl %r15d, %ecx
imull -0x60(%rbp), %ecx
imull %ecx, %eax
shll $0x6, %eax
movq %rax, -0xa8(%rbp)
shll $0x6, %ecx
movq %rcx, -0xb8(%rbp)
leal (%rcx,%rcx,4), %eax
movq %rax, -0xb0(%rbp)
leal (,%r15,8), %eax
movq %rax, -0xc8(%rbp)
movq $0x0, -0x40(%rbp)
leaq 0x5d54(%rip), %rdi      # 0xbc60
movq $0x0, -0x70(%rbp)
movq %r13, -0xd8(%rbp)
cmpl $0x0, -0x50(%rbp)
js 0x6040
movq $0x0, -0x78(%rbp)
movb 0x5d33(%rip), %al       # 0xbc66
movq -0x40(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movl %eax, %ecx
testb %cl, %cl
je 0x6019
movq -0x48(%rbp), %r15
xorl %r8d, %r8d
leaq (%r8,%r8,2), %rdx
movb 0x9(%rdi,%rdx), %cl
testb %cl, %cl
je 0x5fff
leaq (%rdi,%rdx), %r14
addq $0x8, %r14
movb (%r14), %al
xorl %r9d, %r9d
movq %r15, -0xc0(%rbp)
testb %al, %al
je 0x5fd7
movl %r9d, -0xd0(%rbp)
xorl %r13d, %r13d
leal (%r15,%r13), %eax
movslq %eax, %r12
shlq $0x9, %r12
addq %rsi, %r12
movzbl %r8b, %esi
movq -0xd8(%rbp), %rdi
movq %r8, %rbx
callq 0x5aba
movl $0x200, %edx            # imm = 0x200
movq %r12, %rdi
leaq 0x5d21(%rip), %rsi      # 0xbcd0
callq 0x50c0
movq %rbx, %r8
movq -0xe0(%rbp), %rsi
incq %r13
movzbl (%r14), %eax
cmpq %rax, %r13
jb 0x5f7f
movb 0x1(%r14), %cl
movl -0xd0(%rbp), %r9d
jmp 0x5fd9
xorl %eax, %eax
incl %r9d
movzbl %cl, %edx
addq -0xc8(%rbp), %r15
cmpl %edx, %r9d
jb 0x5f71
movb 0x5c75(%rip), %al       # 0xbc66
leaq 0x5c68(%rip), %rdi      # 0xbc60
movq -0xc0(%rbp), %r15
incq %r8
movzbl %al, %edx
addq -0xb8(%rbp), %r15
movl %eax, %ecx
cmpq %rdx, %r8
jb 0x5f4c
jmp 0x601b
xorl %ecx, %ecx
movq -0x78(%rbp), %r9
leal 0x1(%r9), %edx
movq -0x48(%rbp), %r8
addq -0xb0(%rbp), %r8
movq %r8, -0x48(%rbp)
cmpl -0x50(%rbp), %r9d
movq %rdx, -0x78(%rbp)
jne 0x5f3d
movq -0x70(%rbp), %rdx
leal 0x1(%rdx), %eax
movq -0x40(%rbp), %rcx
addq -0xa8(%rbp), %rcx
movq %rcx, -0x40(%rbp)
cmpl -0x68(%rbp), %edx
movq %rax, -0x70(%rbp)
jne 0x5f1b
movb 0x5bfa(%rip), %r14b     # 0xbc64
movb 0x5bf5(%rip), %bl       # 0xbc65
movl -0xa0(%rbp), %eax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
movq -0x58(%rbp), %r10
imull %r10d, %edx
movq %rdx, -0x90(%rbp)
imulq %rdx, %rax
leaq (%rax,%rax,2), %rax
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x100(%rbp)
movq %rcx, %rsp
movzbl %r14b, %r8d
movl %r8d, %eax
divb 0x5bb2(%rip)            # 0xbc69
movl %eax, %ecx
movzbl %bl, %r9d
movl %r9d, %eax
divb 0x5ba2(%rip)            # 0xbc68
movl %eax, %edx
movl %r8d, %eax
divb 0x5b9b(%rip)            # 0xbc6c
movl %eax, %esi
movl %r9d, %eax
divb 0x5b8f(%rip)            # 0xbc6b
movl %eax, %edi
movl %r8d, %eax
divb 0x5b88(%rip)            # 0xbc6f
movl %eax, %r8d
movl %r9d, %eax
divb 0x5b7b(%rip)            # 0xbc6e
cmpl $0x0, -0x68(%rbp)
js 0x64c2
movzbl %cl, %ecx
movzbl %dl, %edx
movzbl %sil, %esi
movzbl %dil, %edi
movzbl %r8b, %r8d
movzbl %al, %r9d
movq %rcx, -0xa0(%rbp)
leal (,%rcx,8), %eax
movl %eax, -0xf4(%rbp)
movq %rdx, -0xd8(%rbp)
leal (,%rdx,8), %eax
movl %eax, -0xc0(%rbp)
movq -0x60(%rbp), %rcx
movl %ecx, %eax
shll $0x4, %eax
movq %rax, -0x130(%rbp)
cmpl $0x1, %r10d
movl %r10d, %eax
adcl $0x0, %eax
movq %rax, -0xb8(%rbp)
movl -0x2c(%rbp), %eax
cmpl $0x1, %eax
adcl $0x0, %eax
movq %rax, -0x150(%rbp)
movl -0x98(%rbp), %eax
movq %rax, -0x118(%rbp)
leal (,%rcx,8), %eax
leaq (%rax,%rax,2), %rax
movq %rax, -0x148(%rbp)
movsd 0xe95(%rip), %xmm0      # 0x7028
movsd 0xe95(%rip), %xmm1      # 0x7030
movsd 0xe95(%rip), %xmm2      # 0x7038
movsd 0xe95(%rip), %xmm3      # 0x7040
movsd 0xe95(%rip), %xmm4      # 0x7048
movsd 0xe95(%rip), %xmm5      # 0x7050
movq %rsi, -0x60(%rbp)
leal (,%rsi,8), %eax
movl %eax, -0xf0(%rbp)
movq %rdi, -0xd0(%rbp)
leal (,%rdi,8), %eax
movl %eax, -0x48(%rbp)
movq %r8, -0x98(%rbp)
leal (,%r8,8), %eax
movl %eax, -0xec(%rbp)
movq %r9, -0xc8(%rbp)
leal (,%r9,8), %eax
movl %eax, -0x78(%rbp)
movl -0x30(%rbp), %eax
movq %rax, -0x108(%rbp)
movq -0x100(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x128(%rbp)
movq -0x90(%rbp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, -0x120(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x80(%rbp)
movq -0xe0(%rbp), %r14
cmpl $0x0, -0x50(%rbp)
js 0x6499
movq -0x80(%rbp), %rax
imulq -0x108(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x88(%rbp), %rax
xorl %ecx, %ecx
movl %eax, -0xe8(%rbp)
movslq %eax, %rbx
imulq -0x120(%rbp), %rbx
addq -0x128(%rbp), %rbx
movq -0x138(%rbp), %rax
movq %rcx, -0x140(%rbp)
addl %eax, %ecx
imull -0xe4(%rbp), %ecx
leal (%rcx,%r10), %eax
movl %eax, -0x68(%rbp)
movq -0x130(%rbp), %rax
movq %rcx, -0x70(%rbp)
addl %ecx, %eax
movl %eax, -0xa8(%rbp)
xorl %ecx, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl -0xf4(%rbp)
movl %eax, %esi
movl %edx, %eax
xorl %edx, %edx
divl -0xa0(%rbp)
movl %eax, %edi
movl %ecx, %eax
xorl %edx, %edx
divl -0xf0(%rbp)
movl %eax, %r8d
movl %edx, %eax
xorl %edx, %edx
divl -0x60(%rbp)
movl %eax, %r9d
movq %rcx, -0x40(%rbp)
movl %ecx, %eax
xorl %edx, %edx
divl -0xec(%rbp)
movl %eax, %r10d
movl %edx, %eax
addl -0x70(%rbp), %esi
movl -0x2c(%rbp), %ecx
imull %ecx, %esi
addl -0x68(%rbp), %r8d
imull %ecx, %r8d
addl -0xa8(%rbp), %r10d
imull %ecx, %r10d
xorl %edx, %edx
divl -0x98(%rbp)
movl %eax, %r11d
shlq $0x6, %rdi
shlq $0x6, %r9
shlq $0x6, %r11
movq %rbx, -0xb0(%rbp)
movq %rbx, %rcx
xorl %ebx, %ebx
movl %ebx, %eax
xorl %edx, %edx
divl -0xc0(%rbp)
addl %esi, %eax
movslq %eax, %r15
movl %edx, %eax
xorl %edx, %edx
divl -0xd8(%rbp)
shlq $0x9, %r15
addq %r14, %r15
addq %rdi, %r15
movsd (%r15,%rax,8), %xmm6
movl %ebx, %eax
xorl %edx, %edx
divl -0x48(%rbp)
movl %eax, %r13d
movl %edx, %eax
xorl %edx, %edx
divl -0xd0(%rbp)
movl %eax, %r12d
movl %ebx, %eax
xorl %edx, %edx
divl -0x78(%rbp)
addl %r10d, %eax
movslq %eax, %r15
movl %edx, %eax
xorl %edx, %edx
divl -0xc8(%rbp)
shlq $0x9, %r15
addq %r14, %r15
addq %r11, %r15
movsd (%r15,%rax,8), %xmm8
addl %r8d, %r13d
movslq %r13d, %rax
shlq $0x9, %rax
addq %r14, %rax
addq %r9, %rax
addsd %xmm0, %xmm8
movapd %xmm8, %xmm10
mulsd %xmm1, %xmm10
addsd %xmm6, %xmm10
movsd (%rax,%r12,8), %xmm7
addsd %xmm0, %xmm7
movapd %xmm7, %xmm9
mulsd %xmm2, %xmm9
mulsd %xmm3, %xmm8
mulsd %xmm4, %xmm7
movb $-0x1, %al
ucomisd %xmm5, %xmm10
movb $-0x1, %dl
ja 0x6400
xorpd %xmm11, %xmm11
maxsd %xmm10, %xmm11
cvttsd2si %xmm11, %edx
addsd %xmm6, %xmm9
addsd %xmm9, %xmm8
movb %dl, -0x2(%rcx)
ucomisd %xmm5, %xmm8
ja 0x6423
xorpd %xmm9, %xmm9
maxsd %xmm8, %xmm9
cvttsd2si %xmm9, %eax
addsd %xmm6, %xmm7
movb %al, -0x1(%rcx)
movb $-0x1, %al
ucomisd %xmm5, %xmm7
ja 0x643e
xorpd %xmm6, %xmm6
maxsd %xmm7, %xmm6
cvttsd2si %xmm6, %eax
movb %al, (%rcx)
incq %rbx
addq $0x3, %rcx
cmpq %rbx, -0xb8(%rbp)
jne 0x633e
movq -0x40(%rbp), %rcx
incq %rcx
movq -0xb0(%rbp), %rbx
addq -0x148(%rbp), %rbx
cmpq -0x150(%rbp), %rcx
jne 0x62bd
movq -0x140(%rbp), %rcx
incq %rcx
movl -0xe8(%rbp), %eax
incl %eax
cmpq -0x108(%rbp), %rcx
movq -0x58(%rbp), %r10
jne 0x6272
movq -0x80(%rbp), %rcx
incq %rcx
movq -0x88(%rbp), %rax
addl -0x30(%rbp), %eax
movq %rax, -0x88(%rbp)
movq %rcx, -0x80(%rbp)
cmpq -0x118(%rbp), %rcx
jne 0x624c
movq -0xe0(%rbp), %rdi
callq 0x5150
movzwl 0x578d(%rip), %esi      # 0xbc62
movzwl 0x5784(%rip), %edx      # 0xbc60
leaq -0x1c0(%rbp), %rdi
callq 0x68c4
movq -0x58(%rbp), %r10
movzwl 0x576d(%rip), %eax      # 0xbc60
testw %ax, %ax
movq -0x90(%rbp), %r11
je 0x65d1
xorl %ecx, %ecx
movzwl 0x5756(%rip), %edx      # 0xbc62
xorl %esi, %esi
testw %dx, %dx
je 0x65c2
movl %ecx, %eax
xorl %edx, %edx
divl -0x2c(%rbp)
movl %eax, %edi
imull -0x30(%rbp), %edi
imull %r10d, %edx
leaq (%rdx,%rdx,2), %r8
addq -0x100(%rbp), %r8
movl %esi, %eax
xorl %edx, %edx
divl %r10d
addl %edi, %eax
cltq
imulq %r11, %rax
leaq (%rax,%rax,2), %rax
addq %r8, %rax
leaq (%rdx,%rdx,2), %rdx
movb (%rax,%rdx), %r9b
movl -0x198(%rbp), %r10d
movb 0x1(%rax,%rdx), %r11b
imull %ecx, %r10d
movl -0x194(%rbp), %ebx
imull %esi, %ebx
movb 0x2(%rax,%rdx), %al
leal (%rbx,%r10), %edx
movq -0x188(%rbp), %r14
movb %al, (%r14,%rdx)
leal 0x1(%rbx,%r10), %eax
movq -0x188(%rbp), %rdx
movb %r11b, (%rdx,%rax)
movq -0x188(%rbp), %rax
leal 0x2(%rbx,%r10), %edx
movq -0x90(%rbp), %r11
movq -0x58(%rbp), %r10
movb %r9b, (%rax,%rdx)
incl %esi
movzwl 0x56b1(%rip), %edx      # 0xbc62
cmpl %edx, %esi
jb 0x6533
movzwl 0x56a0(%rip), %eax      # 0xbc60
jmp 0x65c4
xorl %edx, %edx
incl %ecx
movzwl %ax, %esi
cmpl %esi, %ecx
jb 0x650c
leaq -0x170(%rbp), %rdi
leaq -0x31(%rbp), %rdx
movq -0x110(%rbp), %rsi
callq 0x6c76
leaq -0x1c0(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x695c
leaq -0x160(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x661a
movq -0x160(%rbp), %rsi
incq %rsi
callq 0x5110
movq -0x188(%rbp), %rdi
testq %rdi, %rdi
je 0x6635
movq -0x178(%rbp), %rsi
subq %rdi, %rsi
callq 0x5110
leaq -0x1b0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6654
movq -0x1b0(%rbp), %rsi
incq %rsi
callq 0x5110
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x160(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x668a
movq -0x160(%rbp), %rsi
incq %rsi
callq 0x5110
jmp 0x668a
movq %rax, %rbx
leaq -0x1c0(%rbp), %rdi
callq 0x6cb4
movq %rbx, %rdi
callq 0x51f0