// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %rdi, 0x28(%rsp)
movq %rdx, 0x10(%rsp)
leal -0x8(%rdx), %eax
movq %rax, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
leal -0x8(%rsi), %eax
movq %rax, 0x20(%rsp)
leaq 0x40(%rsp), %rbx
movsd 0x245c(%rip), %xmm3     # 0x8020
movsd 0x244c(%rip), %xmm4     # 0x8018
movsd 0x2454(%rip), %xmm5     # 0x8028
movsd 0x2454(%rip), %xmm6     # 0x8030
movsd 0x2454(%rip), %xmm7     # 0x8038
movsd 0x2453(%rip), %xmm8     # 0x8040
movsd 0x2452(%rip), %xmm9     # 0x8048
movsd 0x2451(%rip), %xmm10    # 0x8050
movsd 0x2450(%rip), %xmm11    # 0x8058
xorl %ebp, %ebp
movl 0x6618(%rip), %eax      # 0xc228
movq 0x30(%rsp), %r8
subl %r8d, %eax
movl 0x6606(%rip), %ecx      # 0xc224
subl 0x10(%rsp), %ecx
cmpl $0x7, %ecx
movl 0x66ad(%rip), %edx      # 0xc2d8
movl 0x66ab(%rip), %esi      # 0xc2dc
movq 0x66b0(%rip), %rdi      # 0xc2e8
movl $0x0, %r9d
cmovll %r9d, %r8d
movq %rbx, %r9
xorl %ebx, %ebx
movq 0x10(%rsp), %r10
leal (%rbx,%r10), %r11d
movq 0x38(%rsp), %r10
movq %rbx, 0x18(%rsp)
addl %ebx, %r10d
cmpl $0x7, %ecx
movl %r10d, 0xc(%rsp)
cmovll %r10d, %r11d
xorl %r14d, %r14d
cmpl $0x6, %eax
jg 0x5c9e
cmpl $0x6, %ecx
jg 0x5c89
movq 0x20(%rsp), %r10
leal (%r10,%r14), %r13d
movl 0xc(%rsp), %r10d
movl %r10d, %ebx
jmp 0x5ca5
cmpl $0x6, %eax
jg 0x5c9e
movq 0x20(%rsp), %r10
leal (%r10,%r14), %r13d
movq 0x18(%rsp), %rbx
jmp 0x5ca5
leal (%r8,%r14), %r13d
movl %r11d, %ebx
imull %esi, %r13d
imull %edx, %ebx
leal (%rbx,%r13), %r12d
leal (%rbx,%r13), %r10d
incl %r10d
leal 0x2(%r13,%rbx), %ebx
movb (%rdi,%rbx), %r15b
movb (%rdi,%r10), %bl
movb (%rdi,%r12), %r13b
cmpl $0x2, %ebp
je 0x5d56
cmpl $0x1, %ebp
je 0x5d20
testl %ebp, %ebp
jne 0x5d97
movzbl %r15b, %r10d
xorps %xmm1, %xmm1
cvtsi2sd %r10d, %xmm1
movzbl %bl, %r10d
xorps %xmm2, %xmm2
cvtsi2sd %r10d, %xmm2
mulsd %xmm8, %xmm2
mulsd %xmm9, %xmm1
movzbl %r13b, %r10d
xorps %xmm0, %xmm0
cvtsi2sd %r10d, %xmm0
addsd %xmm2, %xmm1
mulsd %xmm10, %xmm0
addsd %xmm1, %xmm0
addsd %xmm11, %xmm0
jmp 0x5d8e
movzbl %r15b, %r10d
xorps %xmm1, %xmm1
cvtsi2sd %r10d, %xmm1
movzbl %bl, %r10d
xorps %xmm0, %xmm0
cvtsi2sd %r10d, %xmm0
mulsd %xmm6, %xmm0
mulsd %xmm7, %xmm1
addsd %xmm0, %xmm1
movzbl %r13b, %r10d
xorps %xmm0, %xmm0
cvtsi2sd %r10d, %xmm0
mulsd %xmm4, %xmm0
jmp 0x5d8a
movzbl %r15b, %r10d
xorps %xmm1, %xmm1
cvtsi2sd %r10d, %xmm1
movzbl %bl, %r10d
xorps %xmm0, %xmm0
cvtsi2sd %r10d, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movzbl %r13b, %r10d
xorps %xmm0, %xmm0
cvtsi2sd %r10d, %xmm0
mulsd %xmm5, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r10d
movb %r10b, (%r9,%r14)
incq %r14
cmpq $0x8, %r14
jne 0x5c6c
movq 0x18(%rsp), %rbx
incq %rbx
addq $0x8, %r9
cmpq $0x8, %rbx
jne 0x5c47
movq 0x28(%rsp), %rdi
leaq 0x40(%rsp), %rbx
movq %rbx, %rsi
movl %ebp, %edx
callq 0x55ff
movsd 0x2281(%rip), %xmm11    # 0x8058
movsd 0x2270(%rip), %xmm10    # 0x8050
movsd 0x225f(%rip), %xmm9     # 0x8048
movsd 0x224e(%rip), %xmm8     # 0x8040
movsd 0x223e(%rip), %xmm7     # 0x8038
movsd 0x222e(%rip), %xmm6     # 0x8030
movsd 0x221e(%rip), %xmm5     # 0x8028
movsd 0x2206(%rip), %xmm4     # 0x8018
movsd 0x2206(%rip), %xmm3     # 0x8020
incl %ebp
cmpl $0x3, %ebp
jne 0x5c0a
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq