// File: /workspace/github_cpp_makefile_star2_O1/rapirent[P]JPEG/encoder.c
// Function: calculate_mcu_block(_IO_FILE*, char (*) [8], int)
void calculate_mcu_block(FILE *fp,char block[][8],int yuv_id)
{
    double tmp[8][8], s[8][8];
    short quantized_block[64];
    memset(tmp,0,sizeof(tmp));
    memset(s,0,sizeof(s));
    for (int ii = 0; ii < 8; ii++) {
        for (int x = 0; x < 8; x++) {
            for (int y = 0; y < 8; y++) {
                s[ii][x] += (double)block[ii][y] * cos_cache[(y*2 + 1) * x];
            }
            s[ii][x] = c(x) *s[ii][x] / 2.0;
        }
    }
    for (int ii = 0; ii < 8; ii++) {
        for (int jj = 0; jj < 8; jj++) {
            for (int x = 0; x < 8; x++) {
                tmp[ii][jj] += s[x][jj] * cos_cache[(x*2 + 1) * ii];
            }
            tmp[ii][jj] = c(ii) * tmp[ii][jj] / 2.0;
        }
    }
    for (int x = 0; x < 8; x++) {
        for (int y = 0; y < 8; y++) {
            quantized_block[zigzag_index[x][y]] = (short)round(tmp[x][y]/(double)quantize_table[category[yuv_id]][x*8+y]);
        }
    }
    static short dc_block[5] = {0,0,0,0,0};
    int diff = (int)(quantized_block[0] - dc_block[yuv_id]);
    int need_write_length;
    int index;
    dc_block[yuv_id] = quantized_block[0];
    if (!diff) {
        for (int i = 0; i<strlen((char*)dc_diff[category[yuv_id]][0]); i++) {
            write_one_bit(fp, dc_diff[category[yuv_id]][0][i] - '0',false);
        }
    } else {
        need_write_length = find_length(&diff);
        for (int i = 0; i<strlen((char*)dc_diff[category[yuv_id]][need_write_length]); i++) {
            write_one_bit(fp, dc_diff[category[yuv_id]][need_write_length][i] - '0',false);
        }
        codeword_encode(fp,diff,need_write_length);
    }
    int count_zero = 0;
    int value;
    byte cof_index;
    int padding_start_index=63;
    while (padding_start_index>1&&!quantized_block[padding_start_index]) {
        padding_start_index--;
    }
    for (int i = 1; i <= padding_start_index; i++) {
        if (!quantized_block[i]) {
            count_zero++;
            continue;
        }
        if (count_zero>=16) {
            for (int j = 0; j<count_zero/16; j++) {
                for (int k = 0; k<strlen((char*)ac_cof[category[yuv_id]][0xf0]); k++) {
                    write_one_bit(fp,ac_cof[category[yuv_id]][0xf0][k] - '0',false);
                }
            }
            count_zero = count_zero % 16;
        }
        value = quantized_block[i];
        need_write_length = find_length(&value);
        for (int j = 0; j<strlen((char*)ac_cof[category[yuv_id]][((count_zero << 4)&0xf0)|need_write_length]); j++) {
            write_one_bit(fp,ac_cof[category[yuv_id]][((count_zero << 4)&0xf0)|need_write_length][j] - '0',false);
        }
        codeword_encode(fp,value,need_write_length);
        count_zero = 0;
    }
    if (padding_start_index!=63) {
        for (int i = 0; i<strlen((char*)ac_cof[category[yuv_id]][0x00]); i++) {
            write_one_bit(fp,ac_cof[category[yuv_id]][0x00][i] - '0',false);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4d8, %rsp            # imm = 0x4D8
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x2d0(%rsp), %r14
xorl %r13d, %r13d
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
xorl %esi, %esi
callq 0x50c0
leaq 0xd0(%rsp), %r15
movl $0x200, %edx            # imm = 0x200
movq %r15, %rdi
xorl %esi, %esi
callq 0x50c0
leaq 0x6cb0(%rip), %rcx      # 0xc300
leaq 0x2a09(%rip), %rax      # 0x8060
movsd 0x29b9(%rip), %xmm0     # 0x8018
movq %r13, %rdx
shlq $0x6, %rdx
addq %rsp, %rdx
addq $0xd0, %rdx
xorl %esi, %esi
movq %rcx, %rdi
xorl %r8d, %r8d
movsd (%rdx,%r8,8), %xmm1
movq %rdi, %r9
xorl %r10d, %r10d
movsbl (%r12,%r10), %r11d
xorps %xmm2, %xmm2
cvtsi2sd %r11d, %xmm2
mulsd (%r9), %xmm2
addsd %xmm2, %xmm1
incq %r10
addq %rsi, %r9
cmpq $0x8, %r10
jne 0x5684
xorl %r9d, %r9d
testq %r8, %r8
sete %r9b
mulsd (%rax,%r9,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rdx,%r8,8)
incq %r8
addq $0x8, %rdi
addq $0x10, %rsi
cmpq $0x8, %r8
jne 0x5678
incq %r13
addq $0x8, %r12
cmpq $0x8, %r13
jne 0x565f
leaq 0x6c1b(%rip), %rcx      # 0xc300
xorl %edx, %edx
xorl %esi, %esi
xorl %edi, %edi
testq %rsi, %rsi
sete %dil
movsd (%rax,%rdi,8), %xmm1
movq %rsi, %rdi
shlq $0x6, %rdi
addq %rsp, %rdi
addq $0x2d0, %rdi            # imm = 0x2D0
movq %r15, %r8
xorl %r9d, %r9d
movsd (%rdi,%r9,8), %xmm2
movq %rcx, %r10
xorl %r11d, %r11d
movsd (%r8,%r11), %xmm3
mulsd (%r10), %xmm3
addsd %xmm3, %xmm2
addq $0x40, %r11
addq %rdx, %r10
cmpq $0x200, %r11            # imm = 0x200
jne 0x571a
mulsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
movsd %xmm2, (%rdi,%r9,8)
incq %r9
addq $0x8, %r8
cmpq $0x8, %r9
jne 0x570e
incq %rsi
addq $0x8, %rcx
addq $0x10, %rdx
cmpq $0x8, %rsi
jne 0x56e9
movq %rbx, 0x18(%rsp)
movslq %ebp, %r15
leaq 0x6a8c(%rip), %rax      # 0xc200
movzbl (%r15,%rax), %eax
shll $0x6, %eax
leaq 0x33ed(%rip), %r12      # 0x8b70
addq %rax, %r12
leaq 0x3463(%rip), %r13      # 0x8bf0
xorl %ebp, %ebp
xorl %ebx, %ebx
movsd (%r14,%rbx,8), %xmm0
movzbl (%r12,%rbx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
callq 0x5080
cvttsd2si %xmm0, %eax
movslq (%r13,%rbx,4), %rcx
movw %ax, 0x50(%rsp,%rcx,2)
incq %rbx
cmpq $0x8, %rbx
jne 0x5791
incq %rbp
addq $0x40, %r14
addq $0x20, %r13
addq $0x8, %r12
cmpq $0x8, %rbp
jne 0x578f
movswl 0x50(%rsp), %eax
leaq 0x715e(%rip), %rdx      # 0xc942
movswl (%rdx,%r15,2), %ecx
movw %ax, (%rdx,%r15,2)
cmpw %cx, %ax
jne 0x585a
leaq 0x6a06(%rip), %rbp      # 0xc200
movzbl (%r15,%rbp), %eax
leaq (%rax,%rax,2), %rax
shll $0x5, %eax
leaq 0x5933(%rip), %r12      # 0xb140
movq (%rax,%r12), %r14
cmpb $0x0, (%r14)
movq 0x18(%rsp), %rbx
je 0x5927
xorl %r13d, %r13d
movsbl (%r14,%r13), %esi
addl $-0x30, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x54df
incq %r13
movzbl (%r15,%rbp), %eax
leaq (%rax,%rax,2), %rax
shll $0x5, %eax
movq (%rax,%r12), %r14
movq %r14, %rdi
callq 0x5090
cmpq %r13, %rax
ja 0x5823
jmp 0x5927
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl $0x1, %r13d
leaq 0x58d0(%rip), %r12      # 0xb140
movl %ecx, %edx
movq 0x18(%rsp), %rbx
leaq 0x6982(%rip), %rsi      # 0xc200
shrl %edx
incl %r13d
addq $0x8, %r12
cmpl $0x1, %ecx
movl %edx, %ecx
ja 0x587e
leal -0x1(%r13), %ecx
movl $0x1, %edx
shll %cl, %edx
testl %eax, %eax
leal -0x1(%rax,%rdx), %ecx
cmovgl %eax, %ecx
movl %ecx, 0x10(%rsp)
movzbl (%r15,%rsi), %eax
leaq (%rax,%rax,2), %rax
shll $0x5, %eax
movq (%r12,%rax), %r14
cmpb $0x0, (%r14)
je 0x58f7
xorl %ebp, %ebp
movsbl (%r14,%rbp), %esi
addl $-0x30, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x54df
incq %rbp
leaq 0x6926(%rip), %rax      # 0xc200
movzbl (%r15,%rax), %eax
leaq (%rax,%rax,2), %rax
shll $0x5, %eax
movq (%r12,%rax), %r14
movq %r14, %rdi
callq 0x5090
cmpq %rbp, %rax
ja 0x58be
leaq 0x6902(%rip), %rbp      # 0xc200
movl 0x10(%rsp), %r14d
leal -0x2(%r13), %eax
movzbl %al, %eax
xorl %esi, %esi
btl %eax, %r14d
setb %sil
movq %rbx, %rdi
xorl %edx, %edx
callq 0x54df
decl %r13d
cmpl $0x1, %r13d
jg 0x5903
movl $0x40, %eax
leal -0x1(%rax), %ecx
cmpw $0x0, 0x50(%rsp,%rcx,2)
jne 0x5943
decl %eax
cmpl $0x2, %eax
ja 0x592c
movl $0x1, %ecx
movq %rcx, 0x20(%rsp)
testl %ecx, %ecx
jle 0x5b24
movq 0x20(%rsp), %rax
incl %eax
movq %rax, 0x38(%rsp)
xorl %eax, %eax
movl $0x1, %edx
leaq 0x5896(%rip), %r13      # 0xb200
movq %r15, 0x30(%rsp)
movswl 0x50(%rsp,%rdx,2), %ecx
testl %ecx, %ecx
movq %rdx, 0x48(%rsp)
je 0x5afe
movq %rcx, 0x40(%rsp)
movq %rax, 0x28(%rsp)
cmpl $0x10, %eax
jl 0x5a14
movq 0x28(%rsp), %rax
shrl $0x4, %eax
movl %eax, 0xc(%rsp)
xorl %eax, %eax
movl %eax, 0x10(%rsp)
movzbl (%r15,%rbp), %eax
shll $0xb, %eax
movq 0x780(%rax,%r13), %r14
cmpb $0x0, (%r14)
movq %r13, %r12
movq %r15, %r13
movq %rbp, %r15
movq 0x18(%rsp), %rbp
je 0x59ff
xorl %ebx, %ebx
movsbl (%r14,%rbx), %esi
addl $-0x30, %esi
movq %rbp, %rdi
xorl %edx, %edx
callq 0x54df
incq %rbx
movzbl (%r13,%r15), %eax
shll $0xb, %eax
movq 0x780(%rax,%r12), %r14
movq %r14, %rdi
callq 0x5090
cmpq %rbx, %rax
ja 0x59cc
movl 0x10(%rsp), %eax
incl %eax
cmpl 0xc(%rsp), %eax
movq %r15, %rbp
movq %r13, %r15
movq %r12, %r13
jne 0x59a2
movq 0x40(%rsp), %rdi
movl %edi, %eax
negl %eax
cmovsl %edi, %eax
xorl %ecx, %ecx
movl $0x2, %esi
movl %eax, %edx
movl %esi, %r12d
shrl %edx
incl %ecx
leal 0x1(%r12), %esi
cmpl $0x1, %eax
movl %edx, %eax
ja 0x5a29
movl $0x1, %eax
shll %cl, %eax
testw %di, %di
leal -0x1(%rdi,%rax), %eax
cmovgl %edi, %eax
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rax
shll $0x4, %eax
movzbl %al, %edx
orl %ecx, %edx
movzbl (%r15,%rbp), %eax
shll $0xb, %eax
addq %r13, %rax
movq %rdx, 0x10(%rsp)
movq (%rax,%rdx,8), %r14
cmpb $0x0, (%r14)
movq 0x18(%rsp), %rbx
movq %r15, %r13
movq %rbp, %r15
je 0x5ac3
xorl %ebp, %ebp
movsbl (%r14,%rbp), %esi
addl $-0x30, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x54df
incq %rbp
movzbl (%r13,%r15), %eax
shll $0xb, %eax
leaq 0x5756(%rip), %rcx      # 0xb200
addq %rcx, %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %r14
movq %r14, %rdi
callq 0x5090
cmpq %rbp, %rax
ja 0x5a85
movq %r15, %rbp
leaq 0x5733(%rip), %r13      # 0xb200
movq %rbx, %r15
movl 0xc(%rsp), %r14d
leal -0x2(%r12), %eax
movzbl %al, %eax
xorl %esi, %esi
btl %eax, %r14d
setb %sil
xorl %ebx, %ebx
movq %r15, %rdi
xorl %edx, %edx
callq 0x54df
decl %r12d
cmpl $0x1, %r12d
jg 0x5ad5
jmp 0x5b06
incl %eax
movq %rbx, %r15
movq %rax, %rbx
movq 0x48(%rsp), %rdx
incq %rdx
cmpq 0x38(%rsp), %rdx
movq %rbx, %rax
movq %r15, %rbx
movq 0x30(%rsp), %r15
jne 0x596f
cmpl $0x3f, 0x20(%rsp)
je 0x5b75
movzbl (%r15,%rbp), %eax
shll $0xb, %eax
leaq 0x56c6(%rip), %r12      # 0xb200
movq (%rax,%r12), %r14
cmpb $0x0, (%r14)
je 0x5b75
xorl %r13d, %r13d
movsbl (%r14,%r13), %esi
addl $-0x30, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x54df
incq %r13
movzbl (%r15,%rbp), %eax
shll $0xb, %eax
movq (%rax,%r12), %r14
movq %r14, %rdi
callq 0x5090
cmpq %r13, %rax
ja 0x5b47
addq $0x4d8, %rsp            # imm = 0x4D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq