// File: /workspace/github_cpp_makefile_star2_O2/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 $0x168, %rsp            # imm = 0x168
movq %rsi, -0xd8(%rbp)
movq %rdi, %r13
movzbl 0x5efa(%rip), %r14d     # 0xbc65
leal (,%r14,8), %esi
movzbl 0x5ee9(%rip), %r15d     # 0xbc64
leal (,%r15,8), %ebx
movzwl 0x5ed8(%rip), %eax      # 0xbc62
decl %eax
cltd
movq %rsi, -0x60(%rbp)
idivl %esi
movl %eax, %r12d
leal 0x1(%r12), %ecx
movzwl 0x5ebe(%rip), %eax      # 0xbc60
decl %eax
cltd
idivl %ebx
movq %rax, -0xd0(%rbp)
leal 0x1(%rax), %edx
movl %ecx, -0x2c(%rbp)
imull %ecx, %edx
imull $0x28, %r14d, %eax
movl %eax, -0xb8(%rbp)
movl %eax, %edi
imull %ebx, %edi
movl %edx, -0x78(%rbp)
imull %edx, %edi
shlq $0x9, %rdi
callq 0x5190
movq %rax, -0xb0(%rbp)
movq %r12, -0x58(%rbp)
leal (%r12,%r12,4), %eax
addl $0x5, %eax
movq %r15, -0x80(%rbp)
movl %r15d, %ecx
movq %r14, -0x70(%rbp)
imull %r14d, %ecx
imull %ecx, %eax
shll $0x6, %eax
movl %eax, -0x30(%rbp)
imull $0x140, %ecx, %eax      # imm = 0x140
movl %eax, -0x88(%rbp)
shll $0x6, %ecx
movl %ecx, -0x3c(%rbp)
movq $0x0, -0x48(%rbp)
xorl %ecx, %ecx
movq %rbx, -0x98(%rbp)
cmpl -0xd0(%rbp), %ecx
jg 0x5f59
xorl %edx, %edx
movq -0x48(%rbp), %rax
movl %ecx, -0x90(%rbp)
cmpl -0x58(%rbp), %edx
jg 0x5f47
movl %edx, -0x38(%rbp)
movl %eax, -0x34(%rbp)
movl %eax, -0x50(%rbp)
xorl %r14d, %r14d
movzbl 0x5e10(%rip), %eax      # 0xbc66
cmpq %rax, %r14
jae 0x5f2e
leaq (%r14,%r14,2), %rax
leaq 0x5df6(%rip), %rcx      # 0xbc60
leaq (%rcx,%rax), %r12
addq $0x8, %r12
movl -0x50(%rbp), %ecx
xorl %edx, %edx
movzbl 0x1(%r12), %eax
cmpq %rax, %rdx
jae 0x5f16
movq %rdx, -0xa0(%rbp)
movl %ecx, -0xa8(%rbp)
movslq %ecx, %r15
shlq $0x9, %r15
addq -0xb0(%rbp), %r15
xorl %ebx, %ebx
movzbl (%r12), %eax
cmpq %rax, %rbx
jae 0x5efb
movzbl %r14b, %esi
movq %r13, %rdi
callq 0x5a2f
movq %r15, %rax
leaq 0x5e0d(%rip), %rcx      # 0xbcd0
xorl %edx, %edx
cmpq $0x8, %rdx
je 0x5eef
xorl %esi, %esi
cmpq $0x8, %rsi
je 0x5ee2
movsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, (%rax,%rsi,8)
incq %rsi
jmp 0x5ecd
incq %rdx
addq $0x40, %rcx
addq $0x40, %rax
jmp 0x5ec5
incq %rbx
addq $0x200, %r15            # imm = 0x200
jmp 0x5ea3
movq -0xa0(%rbp), %rdx
incq %rdx
movl -0xa8(%rbp), %ecx
addl -0x98(%rbp), %ecx
jmp 0x5e77
incq %r14
movl -0x50(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x98(%rbp), %rbx
jmp 0x5e4f
movl -0x38(%rbp), %edx
incl %edx
movl -0x34(%rbp), %eax
addl -0x88(%rbp), %eax
movl -0x90(%rbp), %ecx
jmp 0x5e3a
incl %ecx
movq -0x48(%rbp), %rax
addl -0x30(%rbp), %eax
movq %rax, -0x48(%rbp)
jmp 0x5e22
movl -0x78(%rbp), %eax
movq %rbx, %rcx
imulq -0x60(%rbp), %rcx
movq %rcx, -0xf8(%rbp)
imulq %rcx, %rax
leaq (%rax,%rax,2), %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %r9
movq %r9, %rax
subq %rcx, %rax
movq %rax, -0xf0(%rbp)
movq %rax, %rsp
movzbl 0x5cce(%rip), %r8d      # 0xbc64
movl %r8d, %eax
divb 0x5cca(%rip)            # 0xbc69
movl %eax, %edx
movzbl 0x5cbd(%rip), %esi      # 0xbc65
movl %esi, %eax
divb 0x5cb8(%rip)            # 0xbc68
movl %eax, %edi
movl %r8d, %eax
divb 0x5cb1(%rip)            # 0xbc6c
movzbl %dl, %r10d
movzbl %dil, %edi
movzbl %al, %r11d
movl %esi, %eax
divb 0x5c9c(%rip)            # 0xbc6b
movzbl %al, %r14d
movl %r8d, %eax
divb 0x5c93(%rip)            # 0xbc6f
movl %eax, %edx
movl %esi, %eax
divb 0x5c88(%rip)            # 0xbc6e
movzbl %dl, %edx
movzbl %al, %esi
movq %r10, -0x78(%rbp)
leal (,%r10,8), %eax
movl %eax, -0xc8(%rbp)
movq %rdi, -0xa8(%rbp)
leal (,%rdi,8), %eax
movl %eax, -0x3c(%rbp)
movq %r11, -0x120(%rbp)
leal (,%r11,8), %eax
movl %eax, -0xc4(%rbp)
movslq -0x58(%rbp), %rax
movq %rax, -0x108(%rbp)
negq %rcx
leaq (%r9,%rcx), %rax
addq $0x2, %rax
movq %rax, -0xe8(%rbp)
movq -0x70(%rbp), %rcx
movl %ecx, %eax
shll $0x4, %ecx
movq %rcx, -0x70(%rbp)
movq -0x80(%rbp), %rcx
imulq %rax, %rcx
imulq $0xc0, %rcx, %rcx
movq %rcx, -0xe0(%rbp)
imulq $0x18, %rax, %rax
movq %rax, -0x110(%rbp)
movsd 0xfb1(%rip), %xmm0      # 0x7028
movsd 0xfb1(%rip), %xmm1      # 0x7030
movsd 0xfb1(%rip), %xmm2      # 0x7038
movsd 0xfb1(%rip), %xmm3      # 0x7040
movsd 0xfb1(%rip), %xmm4      # 0x7048
movsd 0xfb1(%rip), %xmm5      # 0x7050
movq %r14, -0xa0(%rbp)
leal (,%r14,8), %eax
movl %eax, -0x38(%rbp)
movq %rdx, -0x118(%rbp)
leal (,%rdx,8), %eax
movl %eax, -0xc0(%rbp)
movq %rsi, -0x50(%rbp)
leal (,%rsi,8), %eax
movl %eax, -0x34(%rbp)
movq $0x0, -0x68(%rbp)
xorl %eax, %eax
cmpl -0xd0(%rbp), %eax
jg 0x634a
movl %eax, -0xb4(%rbp)
imull -0x2c(%rbp), %eax
movq %rax, -0x100(%rbp)
movq -0x68(%rbp), %rax
xorl %ecx, %ecx
cmpq -0x108(%rbp), %rcx
jg 0x6330
movl %eax, -0xbc(%rbp)
movslq %eax, %r14
imulq -0xe0(%rbp), %r14
addq -0xe8(%rbp), %r14
movq -0x100(%rbp), %rax
leal (%rax,%rcx), %edx
imull -0xb8(%rbp), %edx
movq -0x60(%rbp), %rax
addl %edx, %eax
movl %eax, -0x30(%rbp)
movq -0x70(%rbp), %rax
movq %rdx, -0x48(%rbp)
addl %edx, %eax
movl %eax, -0x80(%rbp)
xorl %r10d, %r10d
movq %rcx, -0x88(%rbp)
cmpq %rbx, %r10
je 0x6320
movl %r10d, %eax
xorl %edx, %edx
divl -0xc8(%rbp)
movl %eax, %esi
movl %edx, %eax
xorl %edx, %edx
divl -0x78(%rbp)
movl %eax, %edi
movl %r10d, %eax
xorl %edx, %edx
divl -0xc4(%rbp)
movl %eax, %r8d
movl %edx, %eax
xorl %edx, %edx
divl -0x120(%rbp)
movl %eax, %r9d
movq %r10, -0x90(%rbp)
movl %r10d, %eax
xorl %edx, %edx
divl -0xc0(%rbp)
movl %eax, %r10d
movl %edx, %eax
addl -0x48(%rbp), %esi
imull %ebx, %esi
addl -0x30(%rbp), %r8d
imull %ebx, %r8d
addl -0x80(%rbp), %r10d
imull %ebx, %r10d
xorl %edx, %edx
divl -0x118(%rbp)
movl %eax, %r11d
shlq $0x6, %rdi
shlq $0x6, %r9
shlq $0x6, %r11
movq %r14, -0x58(%rbp)
movq %r14, %rcx
xorl %r12d, %r12d
cmpq %r12, -0x60(%rbp)
je 0x62f8
movl %r12d, %eax
xorl %edx, %edx
divl -0x3c(%rbp)
addl %esi, %eax
movslq %eax, %rbx
movl %edx, %eax
xorl %edx, %edx
divl -0xa8(%rbp)
shlq $0x9, %rbx
movq -0xb0(%rbp), %r14
addq %r14, %rbx
addq %rdi, %rbx
movsd (%rbx,%rax,8), %xmm6
movl %r12d, %eax
xorl %edx, %edx
divl -0x38(%rbp)
movl %eax, %ebx
movl %edx, %eax
xorl %edx, %edx
divl -0xa0(%rbp)
movl %eax, %r13d
movl %r12d, %eax
xorl %edx, %edx
divl -0x34(%rbp)
addl %r10d, %eax
movslq %eax, %r15
movl %edx, %eax
xorl %edx, %edx
divl -0x50(%rbp)
shlq $0x9, %r15
addq %r14, %r15
addq %r11, %r15
movsd (%r15,%rax,8), %xmm8
addl %r8d, %ebx
movslq %ebx, %rax
shlq $0x9, %rax
addq %r14, %rax
addq %r9, %rax
addsd %xmm0, %xmm8
movapd %xmm8, %xmm10
mulsd %xmm1, %xmm10
addsd %xmm6, %xmm10
movsd (%rax,%r13,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 0x62ac
xorpd %xmm11, %xmm11
maxsd %xmm10, %xmm11
cvttsd2si %xmm11, %edx
addsd %xmm6, %xmm9
addsd %xmm9, %xmm8
movb %dl, -0x2(%rcx)
ucomisd %xmm5, %xmm8
ja 0x62cf
xorpd %xmm9, %xmm9
maxsd %xmm8, %xmm9
cvttsd2si %xmm9, %eax
addsd %xmm6, %xmm7
movb %al, -0x1(%rcx)
movb $-0x1, %al
ucomisd %xmm5, %xmm7
ja 0x62ea
xorpd %xmm6, %xmm6
maxsd %xmm7, %xmm6
cvttsd2si %xmm6, %eax
movb %al, (%rcx)
incq %r12
addq $0x3, %rcx
jmp 0x61de
movq -0x90(%rbp), %r10
incq %r10
movq -0x58(%rbp), %r14
addq -0x110(%rbp), %r14
movq -0x98(%rbp), %rbx
movq -0x88(%rbp), %rcx
jmp 0x6156
incq %rcx
movl -0xbc(%rbp), %eax
incl %eax
jmp 0x6100
movl -0xb4(%rbp), %ecx
incl %ecx
movq -0x68(%rbp), %rax
addl -0x2c(%rbp), %eax
movq %rax, -0x68(%rbp)
movl %ecx, %eax
jmp 0x60dd
movq -0xb0(%rbp), %rdi
callq 0x5160
movzwl 0x5905(%rip), %esi      # 0xbc62
movzwl 0x58fc(%rip), %edx      # 0xbc60
leaq -0x190(%rbp), %rdi
callq 0x6656
xorl %ecx, %ecx
movzwl 0x58e7(%rip), %eax      # 0xbc60
cmpl %eax, %ecx
jae 0x6433
xorl %esi, %esi
movzwl 0x58d8(%rip), %eax      # 0xbc62
cmpl %eax, %esi
jae 0x642c
movl %ecx, %eax
xorl %edx, %edx
divl %ebx
movl %edx, %edi
movl %eax, %r8d
movl %esi, %eax
xorl %edx, %edx
movq -0x60(%rbp), %r9
divl %r9d
imull -0x2c(%rbp), %r8d
addl %r8d, %eax
cltq
imulq -0xf8(%rbp), %rax
leaq (%rax,%rax,2), %rax
imull %r9d, %edi
leaq (%rdi,%rdi,2), %rdi
addq -0xf0(%rbp), %rdi
addq %rax, %rdi
leaq (%rdx,%rdx,2), %rax
movb (%rdi,%rax), %dl
movb 0x1(%rdi,%rax), %r8b
movb 0x2(%rdi,%rax), %al
movl -0x168(%rbp), %edi
imull %ecx, %edi
movl -0x164(%rbp), %r9d
imull %esi, %r9d
leal (%r9,%rdi), %r10d
movq -0x158(%rbp), %r11
movb %al, (%r11,%r10)
leal (%r9,%rdi), %eax
incl %eax
movq -0x158(%rbp), %r10
movb %r8b, (%r10,%rax)
leal (%r9,%rdi), %eax
addl $0x2, %eax
movq -0x158(%rbp), %rdi
movb %dl, (%rdi,%rax)
incl %esi
jmp 0x6383
incl %ecx
jmp 0x6372
leaq -0x140(%rbp), %rdi
leaq -0x3d(%rbp), %rdx
movq -0xd8(%rbp), %rsi
callq 0x6862
leaq -0x190(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x66d0
leaq -0x140(%rbp), %rdi
callq 0x5080
leaq -0x190(%rbp), %rdi
callq 0x689e
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x5080
jmp 0x6498
movq %rax, %rbx
leaq -0x190(%rbp), %rdi
callq 0x689e
movq %rbx, %rdi
callq 0x5200