// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %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, 0x5e92(%rip)      # 0x91fa
jne 0x33b9
movq 0x5c5f(%rip), %r15      # 0x8fd0
leaq 0x2e62(%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 0x34ce
movl $0x2, %eax
leaq -0x29(%rbp), %r14
movl %ebx, -0x44(%rbp)
movl %eax, -0x30(%rbp)
movl $0x1, %edx
movq %rcx, %rbx
movq %rcx, %rdi
movq %r14, %r15
movq %r14, %rsi
callq 0x2220
movsbl -0x29(%rbp), %r13d
movzbl %r13b, %r14d
sarl $0x3, %r13d
andl $-0x2, %r13d
xorl %r12d, %r12d
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2220
movzbl -0x29(%rbp), %eax
movl %eax, -0xb0(%rbp,%r12,4)
incq %r12
cmpq $0x10, %r12
jne 0x33ff
andl $0xf, %r14d
addl %r14d, %r13d
movl -0x30(%rbp), %eax
addl $0x11, %eax
leaq (,%r13,2), %rdx
addq %r13, %rdx
shlq $0x4, %rdx
addq -0x60(%rbp), %rdx
xorl %esi, %esi
xorl %r12d, %r12d
movq %r15, %r14
movq %rbx, %rcx
leaq -0x54(%rbp), %r13
movl -0xb0(%rbp,%rsi,4), %ebx
testl %ebx, %ebx
je 0x34b7
movl %eax, -0x30(%rbp)
movq %rsi, -0x68(%rbp)
leal 0x1(%rsi), %eax
movl %eax, -0x4c(%rbp)
movl %ebx, -0x48(%rbp)
movq %rdx, %r15
movl $0x1, %edx
movq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x2220
movb -0x29(%rbp), %al
movl %r12d, %ecx
shll $0x10, %ecx
addl -0x4c(%rbp), %ecx
movl %ecx, -0x54(%rbp)
movb %al, -0x50(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x566e
movq -0x40(%rbp), %rcx
incl %r12d
decl %ebx
jne 0x3471
movl -0x30(%rbp), %eax
addl -0x48(%rbp), %eax
movq %r15, %rdx
movq -0x68(%rbp), %rsi
addl %r12d, %r12d
incq %rsi
cmpq $0x10, %rsi
jne 0x3453
movl -0x44(%rbp), %ebx
cmpl %ebx, %eax
jb 0x33d2
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq