// File: /workspace/github_cpp_makefile_star2_O1/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, -0xc0(%rbp)
movzbl 0x5de9(%rip), %edi      # 0xbc65
leal (,%rdi,8), %ecx
movzbl 0x5dda(%rip), %eax      # 0xbc64
movq %rax, -0x60(%rbp)
leal (,%rax,8), %esi
movl %esi, %eax
movq %rax, -0x78(%rbp)
movzwl 0x5dc0(%rip), %eax      # 0xbc62
decl %eax
cltd
movq %rcx, -0x100(%rbp)
idivl %ecx
movq %rax, -0x50(%rbp)
leal 0x1(%rax), %ecx
movzwl 0x5da4(%rip), %eax      # 0xbc60
decl %eax
cltd
idivl %esi
movl %eax, %ebx
leal 0x1(%rbx), %eax
movq %rax, -0x118(%rbp)
movl %eax, %edx
movl %ecx, -0x2c(%rbp)
imull %ecx, %edx
movq %rdi, -0x58(%rbp)
movl %edi, %eax
movq %rsi, -0x70(%rbp)
imull %esi, %eax
movl %edx, -0x90(%rbp)
imull %edx, %eax
shll $0x3, %eax
leal (%rax,%rax,4), %edi
shlq $0x9, %rdi
callq 0x5180
movq %rbx, -0x68(%rbp)
testl %ebx, %ebx
movq %rax, -0xd8(%rbp)
js 0x608e
movq %rax, %rcx
movq -0x50(%rbp), %rax
leal (%rax,%rax,4), %edx
addl $0x5, %edx
movq -0x58(%rbp), %rax
imull -0x60(%rbp), %eax
imull %eax, %edx
shll $0x6, %edx
movq %rdx, -0x98(%rbp)
shll $0x6, %eax
movq %rax, -0xb8(%rbp)
leal (%rax,%rax,4), %eax
movq %rax, -0xa8(%rbp)
movq $0x0, -0x38(%rbp)
xorl %eax, %eax
movq -0xc0(%rbp), %r14
movq %rax, -0xa0(%rbp)
cmpl $0x0, -0x50(%rbp)
js 0x606c
xorl %edx, %edx
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq %rdx, -0xb0(%rbp)
cmpb $0x0, 0x5ce9(%rip)      # 0xbc66
je 0x6048
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
xorl %ebx, %ebx
leaq (%rbx,%rbx,2), %rax
leaq 0x5cc8(%rip), %rdx      # 0xbc60
cmpb $0x0, 0x9(%rdx,%rax)
je 0x6026
leaq 0x5cb6(%rip), %rdx      # 0xbc60
addq %rax, %rdx
addq $0x8, %rdx
xorl %edi, %edi
movq -0x48(%rbp), %r15
movq %rdx, -0xd0(%rbp)
movl %edi, -0xc8(%rbp)
cmpb $0x0, (%rdx)
je 0x6012
xorl %r13d, %r13d
leal (%r15,%r13), %eax
movslq %eax, %r12
shlq $0x9, %r12
addq %rcx, %r12
movzbl %bl, %esi
movq %r14, %rdi
callq 0x5b1b
movl $0x200, %edx            # imm = 0x200
movq %r12, %rdi
leaq 0x5cdc(%rip), %rsi      # 0xbcd0
callq 0x50c0
movq -0xd0(%rbp), %rdx
movq -0xd8(%rbp), %rcx
incq %r13
movzbl (%rdx), %eax
cmpq %rax, %r13
jb 0x5fcc
movl -0xc8(%rbp), %edi
incl %edi
movzbl 0x1(%rdx), %eax
addq -0x70(%rbp), %r15
cmpl %eax, %edi
jb 0x5fbe
incq %rbx
movzbl 0x5c36(%rip), %eax      # 0xbc66
movq -0x48(%rbp), %rdx
addq -0xb8(%rbp), %rdx
movq %rdx, -0x48(%rbp)
cmpq %rax, %rbx
jb 0x5f8d
movq -0xb0(%rbp), %rsi
leal 0x1(%rsi), %eax
movq -0x40(%rbp), %rdx
addq -0xa8(%rbp), %rdx
movq %rdx, -0x40(%rbp)
cmpl -0x50(%rbp), %esi
movl %eax, %edx
jne 0x5f6f
movq -0xa0(%rbp), %rsi
leal 0x1(%rsi), %eax
movq -0x38(%rbp), %rdx
addq -0x98(%rbp), %rdx
movq %rdx, -0x38(%rbp)
cmpl -0x68(%rbp), %esi
jne 0x5f54
movl -0x90(%rbp), %eax
movq -0x100(%rbp), %r15
movq -0x78(%rbp), %rcx
imulq %r15, %rcx
movq %rcx, -0x78(%rbp)
imulq %rcx, %rax
leaq (%rax,%rax,2), %rax
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xf8(%rbp)
movq %rcx, %rsp
movzbl 0x5b95(%rip), %r8d      # 0xbc64
movl %r8d, %eax
divb 0x5b91(%rip)            # 0xbc69
movl %eax, %ecx
movzbl 0x5b83(%rip), %r9d      # 0xbc65
movl %r9d, %eax
divb 0x5b7d(%rip)            # 0xbc68
movl %eax, %edx
movl %r8d, %eax
divb 0x5b76(%rip)            # 0xbc6c
movl %eax, %esi
movl %r9d, %eax
divb 0x5b6a(%rip)            # 0xbc6b
movl %eax, %edi
movl %r8d, %eax
divb 0x5b63(%rip)            # 0xbc6f
movl %eax, %r8d
movl %r9d, %eax
divb 0x5b56(%rip)            # 0xbc6e
cmpl $0x0, -0x68(%rbp)
js 0x64e8
movzbl %cl, %ecx
movzbl %dl, %edx
movzbl %sil, %esi
movzbl %dil, %edi
movzbl %r8b, %r8d
movzbl %al, %r9d
leal (%r15,%r15,4), %eax
movl %eax, -0xdc(%rbp)
movq -0x58(%rbp), %r10
movl %r10d, %eax
shll $0x4, %eax
movq %rax, -0x130(%rbp)
cmpl $0x1, %r15d
movl %r15d, %eax
adcl $0x0, %eax
movq %rax, -0x48(%rbp)
movq -0x70(%rbp), %rax
cmpl $0x1, %eax
adcl $0x0, %eax
movq %rax, -0x150(%rbp)
movq %rcx, -0x90(%rbp)
leal (,%rcx,8), %eax
movl %eax, -0xec(%rbp)
movq -0x60(%rbp), %rcx
imull %r10d, %ecx
movq %rdx, -0xd0(%rbp)
leal (,%rdx,8), %eax
movl %eax, -0xb8(%rbp)
shll $0x6, %ecx
leaq (%rcx,%rcx,2), %rax
movq %rax, -0x128(%rbp)
movsd 0xe70(%rip), %xmm0      # 0x7028
movsd 0xe70(%rip), %xmm1      # 0x7030
movsd 0xe70(%rip), %xmm2      # 0x7038
movsd 0xe70(%rip), %xmm3      # 0x7040
movsd 0xe70(%rip), %xmm4      # 0x7048
movsd 0xe70(%rip), %xmm5      # 0x7050
movq %rsi, -0x60(%rbp)
leal (,%rsi,8), %eax
movl %eax, -0xe8(%rbp)
movq %rdi, -0xc8(%rbp)
leal (,%rdi,8), %eax
movl %eax, -0x40(%rbp)
movq %r8, -0x58(%rbp)
leal (,%r8,8), %eax
movl %eax, -0xe4(%rbp)
movq %r9, -0xc0(%rbp)
leal (,%r9,8), %eax
movl %eax, -0xb0(%rbp)
movl -0x2c(%rbp), %eax
movq %rax, -0x108(%rbp)
movq -0xf8(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x120(%rbp)
leaq (%r15,%r15,2), %rax
movq %rax, -0x148(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x80(%rbp)
movq -0xd8(%rbp), %r14
cmpl $0x0, -0x50(%rbp)
js 0x64bf
movq -0x80(%rbp), %rax
imulq -0x108(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x88(%rbp), %rax
xorl %ecx, %ecx
movl %eax, -0xe0(%rbp)
movslq %eax, %rbx
imulq -0x128(%rbp), %rbx
addq -0x120(%rbp), %rbx
movq -0x138(%rbp), %rax
movq %rcx, -0x140(%rbp)
addl %eax, %ecx
imull -0xdc(%rbp), %ecx
leal (%rcx,%r15), %eax
movl %eax, -0x68(%rbp)
movq -0x130(%rbp), %rax
movq %rcx, -0xa0(%rbp)
addl %ecx, %eax
movl %eax, -0x98(%rbp)
xorl %ecx, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl -0xec(%rbp)
movl %eax, %esi
movl %edx, %eax
xorl %edx, %edx
divl -0x90(%rbp)
movl %eax, %edi
movl %ecx, %eax
xorl %edx, %edx
divl -0xe8(%rbp)
movl %eax, %r8d
movl %edx, %eax
xorl %edx, %edx
divl -0x60(%rbp)
movl %eax, %r9d
movq %rcx, -0x38(%rbp)
movl %ecx, %eax
xorl %edx, %edx
divl -0xe4(%rbp)
movl %eax, %r10d
movl %edx, %eax
addl -0xa0(%rbp), %esi
movq -0x70(%rbp), %rcx
imull %ecx, %esi
addl -0x68(%rbp), %r8d
imull %ecx, %r8d
addl -0x98(%rbp), %r10d
imull %ecx, %r10d
xorl %edx, %edx
divl -0x58(%rbp)
movl %eax, %r11d
shlq $0x6, %rdi
shlq $0x6, %r9
shlq $0x6, %r11
movq %rbx, -0xa8(%rbp)
movq %rbx, %rcx
xorl %r12d, %r12d
movl %r12d, %eax
xorl %edx, %edx
divl -0xb8(%rbp)
addl %esi, %eax
movslq %eax, %rbx
movl %edx, %eax
xorl %edx, %edx
divl -0xd0(%rbp)
shlq $0x9, %rbx
addq %r14, %rbx
addq %rdi, %rbx
movsd (%rbx,%rax,8), %xmm6
movl %r12d, %eax
xorl %edx, %edx
divl -0x40(%rbp)
movl %eax, %r13d
movl %edx, %eax
xorl %edx, %edx
divl -0xc8(%rbp)
movl %eax, %ebx
movl %r12d, %eax
xorl %edx, %edx
divl -0xb0(%rbp)
addl %r10d, %eax
movslq %eax, %r15
movl %edx, %eax
xorl %edx, %edx
divl -0xc0(%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,%rbx,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 0x6426
xorpd %xmm11, %xmm11
maxsd %xmm10, %xmm11
cvttsd2si %xmm11, %edx
addsd %xmm6, %xmm9
addsd %xmm9, %xmm8
movb %dl, -0x2(%rcx)
ucomisd %xmm5, %xmm8
ja 0x6449
xorpd %xmm9, %xmm9
maxsd %xmm8, %xmm9
cvttsd2si %xmm9, %eax
addsd %xmm6, %xmm7
movb %al, -0x1(%rcx)
movb $-0x1, %al
ucomisd %xmm5, %xmm7
ja 0x6464
xorpd %xmm6, %xmm6
maxsd %xmm7, %xmm6
cvttsd2si %xmm6, %eax
movb %al, (%rcx)
incq %r12
addq $0x3, %rcx
cmpq %r12, -0x48(%rbp)
jne 0x6361
movq -0x38(%rbp), %rcx
incq %rcx
movq -0xa8(%rbp), %rbx
addq -0x148(%rbp), %rbx
cmpq -0x150(%rbp), %rcx
jne 0x62de
movq -0x140(%rbp), %rcx
incq %rcx
movl -0xe0(%rbp), %eax
incl %eax
cmpq -0x108(%rbp), %rcx
movq -0x100(%rbp), %r15
jne 0x6290
movq -0x80(%rbp), %rcx
incq %rcx
movq -0x88(%rbp), %rax
addl -0x2c(%rbp), %eax
movq %rax, -0x88(%rbp)
movq %rcx, -0x80(%rbp)
cmpq -0x118(%rbp), %rcx
jne 0x626a
movq -0xd8(%rbp), %rdi
callq 0x5150
movzwl 0x5767(%rip), %esi      # 0xbc62
movzwl 0x575e(%rip), %edx      # 0xbc60
leaq -0x1c0(%rbp), %rdi
callq 0x68b0
cmpw $0x0, 0x574a(%rip)      # 0xbc60
movq -0x78(%rbp), %r12
je 0x65d8
xorl %ecx, %ecx
cmpw $0x0, 0x5738(%rip)      # 0xbc62
je 0x65c7
movl %ecx, %eax
xorl %edx, %edx
divl -0x70(%rbp)
movl %eax, %esi
xorl %edi, %edi
imull -0x2c(%rbp), %esi
imull %r15d, %edx
leaq (%rdx,%rdx,2), %r8
addq -0xf8(%rbp), %r8
movl %edi, %eax
xorl %edx, %edx
divl %r15d
addl %esi, %eax
cltq
imulq %r12, %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 %edi, %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 (%rbx,%r10), %edx
addl $0x2, %edx
movb %r9b, (%rax,%rdx)
incl %edi
movzwl 0x569f(%rip), %eax      # 0xbc62
cmpl %eax, %edi
jb 0x654e
incl %ecx
movzwl 0x5690(%rip), %eax      # 0xbc60
cmpl %eax, %ecx
jb 0x6522
leaq -0x170(%rbp), %rdi
leaq -0x2d(%rbp), %rdx
movq -0x110(%rbp), %rsi
callq 0x6c62
leaq -0x1c0(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x6948
leaq -0x160(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6621
movq -0x160(%rbp), %rsi
incq %rsi
callq 0x5110
movq -0x188(%rbp), %rdi
testq %rdi, %rdi
je 0x663c
movq -0x178(%rbp), %rsi
subq %rdi, %rsi
callq 0x5110
leaq -0x1b0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x665b
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 0x6691
movq -0x160(%rbp), %rsi
incq %rsi
callq 0x5110
jmp 0x6691
movq %rax, %rbx
leaq -0x1c0(%rbp), %rdi
callq 0x6ca0
movq %rbx, %rdi
callq 0x51f0