// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x400, %rsp            # imm = 0x400
movl %esi, %ebp
movq %rdi, %r14
leaq 0x619a(%rip), %rbx      # 0xbcd0
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5080
movl %ebp, %r15d
leaq 0x6171(%rip), %r12      # 0xbcc0
movb (%r15,%r12), %al
shrb $0x4, %al
movzbl %al, %edi
callq 0x53e4
movq %r14, %rdi
movl %eax, %esi
callq 0x5a1a
testb %al, %al
je 0x5b82
movzbl %al, %esi
movq %r14, %rdi
callq 0x59c5
leaq 0x6362(%rip), %rcx      # 0xbee0
addl %eax, (%rcx,%r15,4)
leaq 0x6357(%rip), %rax      # 0xbee0
cvtsi2sdl (%rax,%r15,4), %xmm0
movsd %xmm0, 0x6139(%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 0x5a1a
cmpb $-0x10, %al
je 0x5c50
movzbl %al, %ecx
testl %ecx, %ecx
je 0x5c5e
cmpb $0x10, %al
jb 0x5c0a
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 0x5bd5
andb $0xf, %al
je 0x5c54
movzbl %al, %esi
movq %r14, %rdi
callq 0x59c5
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 0x5c54
addl $0x10, %r12d
cmpl $0x40, %r12d
jl 0x5baf
leaq (%r15,%r15,2), %rax
leaq 0x5ff7(%rip), %rcx      # 0xbc60
movzbl 0xa(%rcx,%rax), %eax
shll $0x8, %eax
xorl %ecx, %ecx
leaq 0x5be6(%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 0x5c7a
leaq 0x1daf(%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 0x5cbd
incq %rdx
addq $0x20, %rax
addq $0x40, %rcx
cmpq $0x8, %rdx
jne 0x5cbb
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 0x54ed(%rip), %rdx      # 0xb220
leaq 0x131e(%rip), %r15      # 0x7058
movq %r12, %rsi
shlq $0x6, %rsi
addq %rsp, %rsi
movq %rcx, %rdi
xorl %r8d, %r8d
movsd (%rsi,%r8,8), %xmm0
movq %rdx, %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
testq %r10, %r10
sete %r11b
movsd (%r15,%r11,8), %xmm1
mulsd (%rdi,%r10,8), %xmm1
mulsd (%r9), %xmm1
addsd %xmm1, %xmm0
incq %r10
addq %rax, %r9
cmpq $0x8, %r10
jne 0x5d56
mulsd 0x128f(%rip), %xmm0     # 0x7018
movsd %xmm0, (%rsi,%r8,8)
incq %r8
addq $0x40, %rdi
cmpq $0x8, %r8
jne 0x5d4a
incq %r12
addq $0x10, %rax
cmpq $0x8, %r12
jne 0x5d3a
xorl %r12d, %r12d
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5080
movsd 0x1255(%rip), %xmm3     # 0x7018
movl $0x8, %eax
leaq 0x5451(%rip), %rcx      # 0xb220
movsd 0x1249(%rip), %xmm0     # 0x7020
movq %r12, %rdx
shlq $0x6, %rdx
addq %rbx, %rdx
movq %r14, %rsi
xorl %edi, %edi
movsd (%rdx,%rdi,8), %xmm1
movq %rcx, %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
testq %r9, %r9
sete %r10b
movsd (%r15,%r10,8), %xmm2
mulsd (%rsi,%r9,8), %xmm2
mulsd (%r8), %xmm2
addsd %xmm2, %xmm1
incq %r9
addq %rax, %r8
cmpq $0x8, %r9
jne 0x5df1
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rdx,%rdi,8)
incq %rdi
addq $0x40, %rsi
cmpq $0x8, %rdi
jne 0x5de6
incq %r12
addq $0x10, %rax
cmpq $0x8, %r12
jne 0x5dd7
addq $0x400, %rsp            # imm = 0x400
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq