// File: /workspace/github_cpp_makefile_star2_O1/rapirent[P]JPEG/decoder.c
// Function: read_ht(_IO_FILE*)
void read_ht(FILE* fp)
{
    byte huffman_length[16];
    int len = read_word_to_bigendian(fp);
    len = len - 2;
    int ht_node_num;
    byte ht_length;
    byte class_id;
    byte ht_value;
    while (len > 0) {
        fread(&class_id,1,1,fp);
        len--;
        ht_node_num = 0;
        for(int i = 0; i<16; i++) {
            fread(&(ht_length),1,1,fp);
            huffman_length[i] = ht_length;
            len--;
            ht_node_num += huffman_length[i];
        }

        huffman_tables[huffman_table_index(class_id)].ht_node_num = ht_node_num;
        huffman_leaf* ht_leaf = (huffman_leaf*)malloc((ht_node_num)*sizeof(
                                    huffman_leaf));
        word codeword = 0;
        for(int height=0, leaf_index = 0; height<16; height++) {
            for(int j = 0; j<huffman_length[height]; j++) {

                fread(&(ht_value),1,1,fp);
                len--;
                ht_leaf[leaf_index].value = ht_value;
                ht_leaf[leaf_index].codeword = (codeword++);
                ht_leaf[leaf_index].codeword_len = height+1;
                leaf_index++;
            }
            codeword = codeword<<1;
        }
        huffman_tables[huffman_table_index(class_id)].start = ht_leaf;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %r13
callq 0x536c
cmpw $0x3, %ax
jb 0x57eb
movzwl %ax, %r12d
addl $-0x2, %r12d
leaq 0xd(%rsp), %r15
leaq 0xe(%rsp), %rbx
movq %r13, 0x20(%rsp)
movl $0x1, %esi
movl $0x1, %edx
leaq 0xf(%rsp), %rdi
movq %r13, %rcx
callq 0x51b0
xorl %r14d, %r14d
xorl %ebp, %ebp
movl $0x1, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r13, %rcx
callq 0x51b0
movzbl 0xd(%rsp), %eax
movb %al, 0x40(%rsp,%r14)
addl %eax, %ebp
incq %r14
cmpq $0x10, %r14
jne 0x56b5
addl $-0x11, %r12d
movzbl 0xf(%rsp), %edi
movl %edi, 0x10(%rsp)
callq 0x53e4
shll $0x4, %eax
leaq 0x6585(%rip), %rcx      # 0xbc80
movl %ebp, 0x8(%rax,%rcx)
movl %ebp, %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rdi
callq 0x5180
movq %rax, 0x28(%rsp)
addq $0x8, %rax
movq %rax, 0x30(%rsp)
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
movzbl 0x40(%rsp,%rdx), %esi
testl %esi, %esi
je 0x57b7
movl %r12d, 0x1c(%rsp)
movl %ecx, 0x18(%rsp)
movslq %ecx, %rcx
movq %rdx, 0x38(%rsp)
leal 0x1(%rdx), %r14d
leaq (%rcx,%rcx,2), %rcx
movq 0x30(%rsp), %rdx
leaq (%rdx,%rcx,4), %r13
movl %esi, 0x14(%rsp)
movl %esi, %r12d
negl %r12d
xorl %r15d, %r15d
movl %eax, %ebp
movl $0x1, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq 0x20(%rsp), %rcx
callq 0x51b0
movb 0xe(%rsp), %al
movb %al, (%r13)
leal 0x1(%rbp), %eax
movw %bp, -0x8(%r13)
movl %r14d, -0x4(%r13)
addq $0xc, %r13
decl %r15d
cmpl %r15d, %r12d
jne 0x575e
movl 0x1c(%rsp), %r12d
subl 0x14(%rsp), %r12d
movl 0x18(%rsp), %ecx
subl %r15d, %ecx
leaq 0xd(%rsp), %r15
movq 0x20(%rsp), %r13
movq 0x38(%rsp), %rdx
addl %eax, %eax
incq %rdx
cmpq $0x10, %rdx
jne 0x5722
movl 0x10(%rsp), %edi
callq 0x53e4
shll $0x4, %eax
leaq 0x64a7(%rip), %rcx      # 0xbc80
movq 0x28(%rsp), %rdx
movq %rdx, (%rax,%rcx)
testl %r12d, %r12d
jg 0x5699
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq