// File: /workspace/github_cpp_makefile_star2_O3/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 0x61f9(%rip), %rbx      # 0xbcd0
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5080
movl %ebp, %r15d
leaq 0x61d0(%rip), %r12      # 0xbcc0
movb (%r15,%r12), %al
shrb $0x4, %al
movzbl %al, %edi
callq 0x53e4
movq %r14, %rdi
movl %eax, %esi
callq 0x5a0a
testb %al, %al
je 0x5b29
movzbl %al, %esi
movq %r14, %rdi
callq 0x59b5
leaq 0x63c1(%rip), %rcx      # 0xbee0
addl (%rcx,%r15,4), %eax
movl %eax, (%rcx,%r15,4)
jmp 0x5b34
leaq 0x63b0(%rip), %rax      # 0xbee0
movl (%rax,%r15,4), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x6190(%rip)     # 0xbcd0
movb (%r15,%r12), %al
andb $0xf, %al
orb $0x10, %al
movzbl %al, %edi
callq 0x53e4
movl %eax, %ebp
movl $0x1, %r12d
movq %r14, %rdi
movl %ebp, %esi
callq 0x5a0a
cmpb $-0x10, %al
je 0x5bf9
movzbl %al, %ecx
testl %ecx, %ecx
je 0x5c07
cmpb $0x10, %al
jb 0x5bb3
movl %eax, %ecx
shrb $0x4, %cl
leal 0x7(%r12), %edx
testl %r12d, %r12d
cmovnsl %r12d, %edx
movl %edx, %esi
sarl $0x3, %esi
movslq %esi, %rsi
andl $-0x8, %edx
movl %r12d, %edi
subl %edx, %edi
movslq %edi, %rdx
shlq $0x6, %rsi
addq %rbx, %rsi
movq $0x0, (%rsi,%rdx,8)
incl %r12d
decb %cl
jne 0x5b7e
andb $0xf, %al
je 0x5bfd
movzbl %al, %esi
movq %r14, %rdi
callq 0x59b5
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
leal 0x7(%r12), %eax
testl %r12d, %r12d
cmovnsl %r12d, %eax
movl %eax, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
andl $-0x8, %eax
movl %r12d, %edx
subl %eax, %edx
movslq %edx, %rax
shlq $0x6, %rcx
addq %rbx, %rcx
movsd %xmm0, (%rcx,%rax,8)
incl %r12d
jmp 0x5bfd
addl $0x10, %r12d
cmpl $0x40, %r12d
jl 0x5b58
leaq (%r15,%r15,2), %rax
leaq 0x604e(%rip), %rcx      # 0xbc60
movzbl 0xa(%rcx,%rax), %eax
shll $0x8, %eax
xorl %ecx, %ecx
leaq 0x5c3d(%rip), %rdx      # 0xb860
leaq (%rax,%rcx,4), %rsi
xorps %xmm0, %xmm0
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
cmpq $0x40, %rcx
jne 0x5c23
leaq 0x1e06(%rip), %rax      # 0x7a60
leaq 0x200(%rsp), %rcx
xorl %edx, %edx
xorl %esi, %esi
movl (%rax,%rsi,4), %edi
leal 0x7(%rdi), %r8d
testl %edi, %edi
cmovnsl %edi, %r8d
movl %r8d, %r9d
sarl $0x3, %r9d
movslq %r9d, %r9
andl $-0x8, %r8d
subl %r8d, %edi
movslq %edi, %rdi
shlq $0x6, %r9
addq %rbx, %r9
movsd (%r9,%rdi,8), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
incq %rsi
cmpq $0x8, %rsi
jne 0x5c66
incq %rdx
addq $0x20, %rax
addq $0x40, %rcx
cmpq $0x8, %rdx
jne 0x5c64
movq %rsp, %r14
xorl %r12d, %r12d
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
xorl %esi, %esi
callq 0x5080
movl $0x8, %eax
leaq 0x200(%rsp), %rcx
leaq 0x5544(%rip), %rdx      # 0xb220
leaq 0x1375(%rip), %r15      # 0x7058
movq %r12, %rsi
shlq $0x6, %rsi
addq %rsp, %rsi
movq %rcx, %rdi
xorl %r8d, %r8d
leaq (%rsi,%r8,8), %r9
movsd (%r9), %xmm0
movq %rdx, %r10
xorl %r11d, %r11d
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
cmpq $0x8, %r11
jne 0x5d02
mulsd 0x12e3(%rip), %xmm0     # 0x7018
movsd %xmm0, (%r9)
incq %r8
addq $0x40, %rdi
cmpq $0x8, %r8
jne 0x5cf3
incq %r12
addq $0x10, %rax
cmpq $0x8, %r12
jne 0x5ce3
xorl %r12d, %r12d
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5080
movsd 0x12aa(%rip), %xmm3     # 0x7018
movl $0x8, %eax
leaq 0x54a6(%rip), %rcx      # 0xb220
movsd 0x129e(%rip), %xmm0     # 0x7020
movq %r12, %rdx
shlq $0x6, %rdx
addq %rbx, %rdx
movq %r14, %rsi
xorl %edi, %edi
leaq (%rdx,%rdi,8), %r8
movsd (%r8), %xmm1
movq %rcx, %r9
xorl %r10d, %r10d
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
cmpq $0x8, %r10
jne 0x5da0
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r8)
incq %rdi
addq $0x40, %rsi
cmpq $0x8, %rdi
jne 0x5d91
incq %r12
addq $0x10, %rax
cmpq $0x8, %r12
jne 0x5d82
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq