// File: /workspace/github_cpp_makefile_star2_O2/rapirent[P]JPEG/decoder.c
// Function: calcualte_mcu_block(_IO_FILE*, unsigned char)
void calcualte_mcu_block(FILE *fp, byte component_id)
{
    static int dc_block[5] = {0,0,0,0,0};
    memset(block,0,sizeof(block));
    int dc_table_id = huffman_table_index((component_mapping_huffman[component_id]>> 4)&0x0f);
    byte need_read_bit = decode_huffman(fp,dc_table_id);
    byte leading_bit;
    if (need_read_bit) {
        dc_block[component_id] += codeword_decode(fp,need_read_bit);
    }
    block[0][0] = dc_block[component_id];
    int ac_table_id = huffman_table_index((component_mapping_huffman[component_id]
                                           &0x0f)|0x10);
    byte zerosnum_needread,zerosnum;
    for (int i = 1; i< 64;) {
        zerosnum_needread = decode_huffman(fp,ac_table_id);
        if(zerosnum_needread == 0x00) {
            break;
        }
        if(zerosnum_needread == 0xf0) {
            i+=16;
            continue;
        }
        need_read_bit = zerosnum_needread & 0x0f;
        zerosnum = (zerosnum_needread >> 4) & 0x0f;
        for (byte j = 0; j< zerosnum; j++) {
            block[i/8][i%8] = 0.0;
            i++;
        }
        if (need_read_bit) {
            block[i/8][i%8] = codeword_decode(fp,need_read_bit);
            i++;
        }
    }
    for (int quantize_i = 0; quantize_i<64; quantize_i++) {
        block[quantize_i/8][quantize_i%8] *=
            quantize_table_list[(f0.frame_components[component_id]).qantize_table_id][quantize_i];
    }
    double tmp[8][8];
    for (int x = 0; x < 8; x++) {
        for (int y = 0; y < 8; y++) {
            tmp[x][y] = block[zigzag_index[x][y]/8][zigzag_index[x][y]%8];
        }
    }
    double s[8][8];
    memset(s,0,sizeof(s));
    for (int jj = 0; jj < 8; jj++) {
        for (int x = 0; x < 8; x++) {
            for (int y = 0; y < 8; y++) {
                s[jj][x] += c (y) * tmp[x][y] * cos_cache[(jj + jj + 1) * y];
            }
            s[jj][x] = s[jj][x] / 2.0;
        }
    }
    memset(block,0,sizeof(block));
    for (int ii = 0; ii < 8; ii++) {
        for (int jj = 0; jj < 8; jj++) {
            for (int x = 0; x < 8; x++) {
                block[ii][jj] += c(x) * s[jj][x] * cos_cache[(ii + ii + 1) * x];
            }
            block[ii][jj] = block[ii][jj] / 2.0;
            block[ii][jj] += 128.0;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
movl %esi, %ebp
movq %rdi, %r14
leaq 0x6284(%rip), %rbx      # 0xbcd0
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
xorl %esi, %esi
callq 0x50b0
movl %ebp, %r13d
leaq 0x625b(%rip), %r15      # 0xbcc0
movb (%r13,%r15), %al
shrb $0x4, %al
movzbl %al, %edi
callq 0x53de
movq %r14, %rdi
movl %eax, %esi
callq 0x598e
leaq 0x645a(%rip), %r12      # 0xbee0
testb %al, %al
je 0x5a9f
movzbl %al, %esi
movq %r14, %rdi
callq 0x5940
addl (%r12,%r13,4), %eax
movl %eax, (%r12,%r13,4)
jmp 0x5aa3
movl (%r12,%r13,4), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x6221(%rip)     # 0xbcd0
movb (%r13,%r15), %al
andb $0xf, %al
orb $0x10, %al
movzbl %al, %edi
callq 0x53de
movl %eax, %ebp
pushq $0x1
popq %r15
pushq $0x8
popq %r12
cmpl $0x3f, %r15d
jg 0x5b49
movq %r14, %rdi
movl %ebp, %esi
callq 0x598e
cmpb $-0x10, %al
je 0x5b10
movl %eax, %ecx
movzbl %al, %eax
testl %eax, %eax
je 0x5b49
movl %ecx, %esi
shrb $0x4, %sil
subb $0x1, %sil
jb 0x5b16
movl %r15d, %eax
cltd
idivl %r12d
cltq
movslq %edx, %rdx
shlq $0x6, %rax
addq %rbx, %rax
andq $0x0, (%rax,%rdx,8)
incl %r15d
jmp 0x5aed
addl $0x10, %r15d
jmp 0x5aca
andb $0xf, %cl
je 0x5aca
movzbl %cl, %esi
movq %r14, %rdi
callq 0x5940
movl %eax, %ecx
movl %r15d, %eax
cltd
idivl %r12d
cvtsi2sd %ecx, %xmm0
cltq
movslq %edx, %rcx
shlq $0x6, %rax
addq %rbx, %rax
movsd %xmm0, (%rax,%rcx,8)
incl %r15d
jmp 0x5aca
leaq (,%r13,2), %rax
addq %r13, %rax
leaq 0x6105(%rip), %rcx      # 0xbc60
movzbl 0xa(%rcx,%rax), %eax
shll $0x8, %eax
xorl %ecx, %ecx
leaq 0x5cf4(%rip), %rdx      # 0xb860
cmpq $0x40, %rcx
je 0x5b9b
leaq (%rax,%rcx,4), %rsi
cvtsi2sdl (%rdx,%rsi), %xmm0
movl %ecx, %esi
shrl $0x3, %esi
movl %ecx, %edi
andl $0x7, %edi
shlq $0x6, %rsi
addq %rbx, %rsi
mulsd (%rsi,%rdi,8), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
incq %rcx
jmp 0x5b6c
leaq 0x1ebe(%rip), %rcx      # 0x7a60
leaq 0x200(%rsp), %rsi
xorl %edi, %edi
cmpq $0x8, %rdi
je 0x5bec
xorl %r8d, %r8d
cmpq $0x8, %r8
je 0x5bdf
movl (%rcx,%r8,4), %eax
cltd
idivl %r12d
cltq
movslq %edx, %rdx
shlq $0x6, %rax
addq %rbx, %rax
movsd (%rax,%rdx,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
incq %r8
jmp 0x5bb5
incq %rdi
addq $0x20, %rcx
addq $0x40, %rsi
jmp 0x5bac
movq %rsp, %r14
xorl %r12d, %r12d
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
xorl %esi, %esi
callq 0x50b0
pushq $0x8
popq %rax
leaq 0x200(%rsp), %rcx
leaq 0x560d(%rip), %rdx      # 0xb220
leaq 0x143e(%rip), %r15      # 0x7058
cmpq $0x8, %r12
je 0x5c91
movq %r12, %rsi
shlq $0x6, %rsi
addq %rsp, %rsi
movq %rcx, %rdi
xorl %r8d, %r8d
cmpq $0x8, %r8
je 0x5c88
leaq (%rsi,%r8,8), %r9
movsd (%r9), %xmm0
movq %rdx, %r10
xorl %r11d, %r11d
cmpq $0x8, %r11
je 0x5c72
xorl %r13d, %r13d
testq %r11, %r11
sete %r13b
movsd (%r15,%r13,8), %xmm1
mulsd (%rdi,%r11,8), %xmm1
mulsd (%r10), %xmm1
addsd %xmm1, %xmm0
incq %r11
addq %rax, %r10
jmp 0x5c45
mulsd 0x139e(%rip), %xmm0     # 0x7018
movsd %xmm0, (%r9)
incq %r8
addq $0x40, %rdi
jmp 0x5c30
incq %r12
addq $0x10, %rax
jmp 0x5c1a
xorl %r12d, %r12d
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
xorl %esi, %esi
callq 0x50b0
movsd 0x136d(%rip), %xmm3     # 0x7018
pushq $0x8
popq %rax
leaq 0x556b(%rip), %rcx      # 0xb220
movsd 0x1363(%rip), %xmm0     # 0x7020
cmpq $0x8, %r12
je 0x5d33
movq %r12, %rdx
shlq $0x6, %rdx
addq %rbx, %rdx
movq %r14, %rsi
xorl %edi, %edi
cmpq $0x8, %rdi
je 0x5d2a
leaq (%rdx,%rdi,8), %r8
movsd (%r8), %xmm1
movq %rcx, %r9
xorl %r10d, %r10d
cmpq $0x8, %r10
je 0x5d14
xorl %r11d, %r11d
testq %r10, %r10
sete %r11b
movsd (%r15,%r11,8), %xmm2
mulsd (%rsi,%r10,8), %xmm2
mulsd (%r9), %xmm2
addsd %xmm2, %xmm1
incq %r10
addq %rax, %r9
jmp 0x5ce7
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r8)
incq %rdi
addq $0x40, %rsi
jmp 0x5cd2
incq %r12
addq $0x10, %rax
jmp 0x5cbd
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq