// File: /workspace/github_cpp_makefile_star2_O2/rapirent[P]JPEG/encoder.c
// Function: calculate_mcu(_IO_FILE*, int, int)
void calculate_mcu(FILE *fp,int block_x, int block_y)
{

    rgb_t colour;
    char mcu[8][8];
    byte R,G,B;
    for (int yuv_id = 0; yuv_id<3; yuv_id++) {
        for (int y=0; y<8; y++) {
            for (int x=0; x<8; x++) {
                if (image_width - block_x < 7 && image_height - block_y < 7) {
                    rgb_image.get_pixel((x + block_x - 8), (y + block_y - 8), colour);
                } else if (image_width - block_x < 7) {
                    rgb_image.get_pixel((x + block_x - 8), y, colour);
                } else if(image_height - block_y < 7) {
                    rgb_image.get_pixel(x, (y + block_y - 8), colour);
                } else {
                    rgb_image.get_pixel(x+block_x, y+block_y, colour);
                }
                switch(yuv_id) {
                    case 0:
                        mcu[y][x] = (byte)(0.299 * colour.red + 0.587 * colour.green + 0.114 * colour.blue - 128);
                        break;
                    case 1:
                        mcu[y][x] = (byte)(-0.1687 * colour.red - 0.3313 * colour.green + 0.5 * colour.blue);
                        break;
                    case 2:
                        mcu[y][x] = (byte)(0.5 * colour.red - 0.4187 * colour.green - 0.0813 * colour.blue);
                        break;
                }
            }
        }
        calculate_mcu_block(fp,mcu,yuv_id);
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, 0x10(%rsp)
leal -0x8(%rbx), %eax
movq %rax, 0x18(%rsp)
movl %esi, %eax
movq %rax, 0x20(%rsp)
addq $-0x8, %rax
movq %rax, 0x28(%rsp)
xorl %r15d, %r15d
leaq 0x30(%rsp), %r14
cmpl $0x3, %r15d
je 0x5c10
xorl %ecx, %ecx
cmpq $0x8, %rcx
je 0x5bf3
movq 0x18(%rsp), %rax
leal (%rax,%rcx), %r12d
movq %rcx, 0x8(%rsp)
leal (%rcx,%rbx), %eax
movl %eax, 0x4(%rsp)
xorl %r13d, %r13d
cmpq $0x8, %r13
je 0x5be2
movl 0x57a5(%rip), %ecx      # 0xb248
subl %ebp, %ecx
movl 0x5799(%rip), %eax      # 0xb244
subl %ebx, %eax
cmpl $0x6, %ecx
jg 0x5ace
movq 0x28(%rsp), %rcx
leaq (%rcx,%r13), %rsi
leaq 0x580e(%rip), %rdi      # 0xb2d0
cmpl $0x6, %eax
jle 0x5add
movq 0x8(%rsp), %rdx
jmp 0x5af6
cmpl $0x6, %eax
jg 0x5ae2
leaq 0x57f6(%rip), %rdi      # 0xb2d0
movl %r13d, %esi
movl %r12d, %edx
jmp 0x5af6
movq 0x20(%rsp), %rax
leal (%rax,%r13), %esi
leaq 0x57de(%rip), %rdi      # 0xb2d0
movl 0x4(%rsp), %edx
leaq 0x1(%rsp), %rcx
callq 0x622c
cmpl $0x2, %r15d
je 0x5b97
cmpl $0x1, %r15d
je 0x5b5e
testl %r15d, %r15d
jne 0x5bda
movzbl 0x1(%rsp), %eax
cvtsi2sd %eax, %xmm1
movzbl 0x2(%rsp), %eax
cvtsi2sd %eax, %xmm2
mulsd 0x1535(%rip), %xmm2     # 0x7068
mulsd 0x1535(%rip), %xmm1     # 0x7070
movzbl 0x3(%rsp), %eax
cvtsi2sd %eax, %xmm0
addsd %xmm2, %xmm1
mulsd 0x1528(%rip), %xmm0     # 0x7078
addsd %xmm1, %xmm0
addsd 0x1524(%rip), %xmm0     # 0x7080
jmp 0x5bd2
movzbl 0x1(%rsp), %eax
cvtsi2sd %eax, %xmm1
movzbl 0x2(%rsp), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x14e0(%rip), %xmm0     # 0x7058
mulsd 0x14e0(%rip), %xmm1     # 0x7060
addsd %xmm0, %xmm1
movzbl 0x3(%rsp), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x14ab(%rip), %xmm0     # 0x7040
jmp 0x5bce
movzbl 0x1(%rsp), %eax
cvtsi2sd %eax, %xmm1
movzbl 0x2(%rsp), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x1497(%rip), %xmm0     # 0x7048
mulsd 0x1487(%rip), %xmm1     # 0x7040
addsd %xmm0, %xmm1
movzbl 0x3(%rsp), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x1482(%rip), %xmm0     # 0x7050
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, (%r14,%r13)
incq %r13
jmp 0x5a93
movq 0x8(%rsp), %rcx
incq %rcx
addq $0x8, %r14
jmp 0x5a71
movq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %r14
movq %r14, %rsi
movl %r15d, %edx
callq 0x55c0
incl %r15d
jmp 0x5a65
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq