// File: /workspace/github_cpp_makefile_star2_O3/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, 0x30(%rsp)
movq %rdx, 0x20(%rsp)
leal -0x8(%rdx), %eax
movq %rax, 0x18(%rsp)
movq %rsi, 0x28(%rsp)
leal -0x8(%rsi), %r15d
xorl %r12d, %r12d
leaq 0x40(%rsp), %rbx
movsd 0x2464(%rip), %xmm3     # 0x8020
movsd 0x2454(%rip), %xmm4     # 0x8018
movsd 0x245c(%rip), %xmm5     # 0x8028
movsd 0x245c(%rip), %xmm6     # 0x8030
movsd 0x245c(%rip), %xmm7     # 0x8038
movsd 0x245b(%rip), %xmm8     # 0x8040
movsd 0x245a(%rip), %xmm9     # 0x8048
movsd 0x2459(%rip), %xmm10    # 0x8050
movsd 0x2458(%rip), %xmm11    # 0x8058
movl 0x6622(%rip), %eax      # 0xc228
subl 0x28(%rsp), %eax
movl 0x6614(%rip), %ecx      # 0xc224
subl 0x20(%rsp), %ecx
movl 0x66bd(%rip), %r8d      # 0xc2d8
movl 0x66bb(%rip), %esi      # 0xc2dc
movq 0x66c0(%rip), %rdi      # 0xc2e8
movq 0x18(%rsp), %rdx
movl %edx, %r10d
imull %r8d, %r10d
movq %rbx, %r9
xorl %r11d, %r11d
movl %r8d, 0xc(%rsp)
movq 0x20(%rsp), %rdx
addl %r11d, %edx
imull %r8d, %edx
movl %edx, 0x14(%rsp)
movq 0x18(%rsp), %rdx
leal (%rdx,%r11), %r13d
imull %r8d, %r13d
movl %r8d, %edx
movq %r11, 0x38(%rsp)
imull %r11d, %edx
movl %r10d, 0x10(%rsp)
movl %r10d, %r8d
xorl %ebx, %ebx
cmpl $0x6, %eax
jg 0x5c89
leal (%r15,%rbx), %r14d
imull %esi, %r14d
cmpl $0x6, %ecx
jg 0x5ca5
addl %r13d, %r14d
jmp 0x5ca8
movl %r8d, %r14d
cmpl $0x7, %ecx
jl 0x5ca8
movq 0x28(%rsp), %r10
leal (%rbx,%r10), %r14d
imull %esi, %r14d
addl 0x14(%rsp), %r14d
jmp 0x5ca8
addl %edx, %r14d
movl %r14d, %r11d
leal 0x1(%r14), %ebp
addl $0x2, %r14d
movb (%rdi,%r14), %r10b
movb (%rdi,%rbp), %bpl
movb (%rdi,%r11), %r14b
cmpl $0x2, %r12d
je 0x5d50
cmpl $0x1, %r12d
je 0x5d1a
testl %r12d, %r12d
jne 0x5d91
movzbl %r10b, %r10d
xorps %xmm1, %xmm1
cvtsi2sd %r10d, %xmm1
movzbl %bpl, %r10d
xorps %xmm2, %xmm2
cvtsi2sd %r10d, %xmm2
mulsd %xmm8, %xmm2
mulsd %xmm9, %xmm1
movzbl %r14b, %r10d
xorps %xmm0, %xmm0
cvtsi2sd %r10d, %xmm0
addsd %xmm2, %xmm1
mulsd %xmm10, %xmm0
addsd %xmm1, %xmm0
addsd %xmm11, %xmm0
jmp 0x5d88
movzbl %r10b, %r10d
xorps %xmm1, %xmm1
cvtsi2sd %r10d, %xmm1
movzbl %bpl, %r10d
xorps %xmm0, %xmm0
cvtsi2sd %r10d, %xmm0
mulsd %xmm6, %xmm0
mulsd %xmm7, %xmm1
addsd %xmm0, %xmm1
movzbl %r14b, %r10d
xorps %xmm0, %xmm0
cvtsi2sd %r10d, %xmm0
mulsd %xmm4, %xmm0
jmp 0x5d84
movzbl %r10b, %r10d
xorps %xmm1, %xmm1
cvtsi2sd %r10d, %xmm1
movzbl %bpl, %r10d
xorps %xmm0, %xmm0
cvtsi2sd %r10d, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movzbl %r14b, %r10d
xorps %xmm0, %xmm0
cvtsi2sd %r10d, %xmm0
mulsd %xmm5, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r10d
movb %r10b, (%r9,%rbx)
incq %rbx
addl %esi, %r8d
cmpq $0x8, %rbx
jne 0x5c72
movq 0x38(%rsp), %r11
incq %r11
addq $0x8, %r9
movl 0xc(%rsp), %r8d
movl 0x10(%rsp), %r10d
addl %r8d, %r10d
cmpq $0x8, %r11
jne 0x5c3f
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rbx
movq %rbx, %rsi
movl %r12d, %edx
callq 0x55fc
movsd 0x2276(%rip), %xmm11    # 0x8058
movsd 0x2265(%rip), %xmm10    # 0x8050
movsd 0x2254(%rip), %xmm9     # 0x8048
movsd 0x2243(%rip), %xmm8     # 0x8040
movsd 0x2233(%rip), %xmm7     # 0x8038
movsd 0x2223(%rip), %xmm6     # 0x8030
movsd 0x2213(%rip), %xmm5     # 0x8028
movsd 0x21fb(%rip), %xmm4     # 0x8018
movsd 0x21fb(%rip), %xmm3     # 0x8020
incl %r12d
cmpl $0x3, %r12d
jne 0x5c00
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq