// File: /workspace/github_cpp_makefile_star2_O3/qhan1028[P]JPEG-Decoder/jpeg-decoder.cpp
// Function: process_DHT(std::basic_ifstream<char, std::char_traits<char>>&, std::map<std::pair<unsigned char, unsigned short>, unsigned char, std::less<std::pair<unsigned char, unsigned short>>, std::allocator<std::pair<std::pair<unsigned char, unsigned short> const, unsigned char>>>*)
bool process_DHT(ifstream& jpegfile, htable_t* htable) {
    unsigned int pointer = 0;
    char c, c1, c2;

    /* DHT length */
    jpegfile.read(&c1, 1); pointer++;
    jpegfile.read(&c2, 1); pointer++;

    unsigned int len = to_num(c1, c2);

    if (debug)
        cout << "[DHT] len = " << len << endl;

    while (pointer < len) {
        /* H table ID */
        jpegfile.read(&c, 1); pointer++;
        c = to_uint(c);
        unsigned int tc = c >> 4;
        unsigned int th = c & 0x0F;

        unsigned int hid = tc * 2 + th;

        /* counts */
        unsigned int counts[16];
        for (unsigned int i = 0; i < 16; i++) {
            jpegfile.read(&c, 1); pointer++;
            counts[i] = to_uint(c);
        }

        /* compute target symbols and get its corresponding codes */
        uint16_t symbol = 0;
        for (unsigned int i = 0; i < 16; i++) {
            for (unsigned int j = 0; j < counts[i]; j++) {
                jpegfile.read(&c, 1); pointer++; // code
                htable[hid].insert(
                    pair<hkey_t, uint8_t>(hkey_t(i + 1, symbol), to_uint(c))
                );
                symbol++;
            }
            symbol = symbol << 1;
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, -0x60(%rbp)
movq %rdi, %rbx
leaq -0x32(%rbp), %r15
movl $0x1, %edx
movq %r15, %rsi
callq 0x2220
leaq -0x31(%rbp), %r12
movl $0x1, %edx
movq %rbx, -0x40(%rbp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2220
movzbl (%r15), %ebx
movzbl (%r12), %eax
shll $0x8, %ebx
orl %eax, %ebx
cmpb $0x1, 0x5e95(%rip)      # 0x91fa
jne 0x33b6
movq 0x5c62(%rip), %r15      # 0x8fd0
leaq 0x2e65(%rip), %rsi      # 0x61da
movl $0xc, %edx
movq %r15, %rdi
callq 0x2210
movl %ebx, %esi
movq %r15, %rdi
callq 0x2110
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
cmpl $0x3, %ebx
movq -0x40(%rbp), %rcx
jb 0x34b9
movl $0x2, %eax
leaq -0x29(%rbp), %r14
movl %ebx, -0x44(%rbp)
movl %eax, -0x30(%rbp)
movl $0x1, %edx
movq %rcx, %rdi
movq %rcx, %r13
movq %r14, %r15
movq %r14, %rsi
callq 0x2220
movsbl -0x29(%rbp), %ebx
movzbl %bl, %r14d
sarl $0x3, %ebx
andl $-0x2, %ebx
xorl %r12d, %r12d
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x2220
movzbl -0x29(%rbp), %eax
movl %eax, -0xa0(%rbp,%r12,4)
incq %r12
cmpq $0x10, %r12
jne 0x33f9
andl $0xf, %r14d
addl %r14d, %ebx
movl -0x30(%rbp), %eax
addl $0x11, %eax
leaq (%rbx,%rbx,2), %rbx
shlq $0x4, %rbx
addq -0x60(%rbp), %rbx
xorl %edx, %edx
xorl %r12d, %r12d
movq %r15, %r14
movq %r13, %rcx
leaq -0x50(%rbp), %r13
movl -0xa0(%rbp,%rdx,4), %r15d
incq %rdx
testl %r15d, %r15d
je 0x34a5
movl %eax, -0x30(%rbp)
movl %r15d, -0x48(%rbp)
movq %rdx, -0x58(%rbp)
movl $0x1, %edx
movq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x2220
movb -0x29(%rbp), %al
movl %r12d, %ecx
shll $0x10, %ecx
addl -0x58(%rbp), %ecx
movl %ecx, -0x50(%rbp)
movb %al, -0x4c(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x55ea
movq -0x40(%rbp), %rcx
incl %r12d
decl %r15d
jne 0x3461
movl -0x30(%rbp), %eax
addl -0x48(%rbp), %eax
movq -0x58(%rbp), %rdx
addl %r12d, %r12d
cmpq $0x10, %rdx
jne 0x3446
movl -0x44(%rbp), %ebx
cmpl %ebx, %eax
jb 0x33cf
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq