// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %rsi, -0x48(%rbp)
movq %rdi, %r14
leaq -0x2b(%rbp), %rbx
pushq $0x1
popq %r15
movq %rbx, %rsi
movq %r15, %rdx
callq 0x21f0
leaq -0x2a(%rbp), %r12
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x21f0
movzbl (%rbx), %ecx
movzbl (%r12), %eax
shll $0x8, %ecx
orl %eax, %ecx
movl %ecx, -0x30(%rbp)
cmpb $0x1, 0x61db(%rip)      # 0x91da
jne 0x3027
movq 0x5fc8(%rip), %rdi      # 0x8fd0
leaq 0x31cb(%rip), %rsi      # 0x61da
callq 0x2190
movl -0x30(%rbp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20e0
pushq $0x2
popq %rax
cmpl -0x30(%rbp), %eax
jae 0x3102
movl %eax, %r13d
movq %r14, %rdi
leaq -0x29(%rbp), %rsi
pushq $0x1
popq %rdx
callq 0x21f0
movsbl -0x29(%rbp), %ebx
movzbl %bl, %r15d
sarl $0x3, %ebx
andl $-0x2, %ebx
xorl %r12d, %r12d
cmpq $0x10, %r12
je 0x307c
movq %r14, %rdi
leaq -0x29(%rbp), %rsi
pushq $0x1
popq %rdx
callq 0x21f0
movzbl -0x29(%rbp), %eax
movl %eax, -0x90(%rbp,%r12,4)
incq %r12
jmp 0x3056
andl $0xf, %r15d
addl %r15d, %ebx
movl %r13d, %eax
addl $0x11, %eax
imulq $0x30, %rbx, %rbx
addq -0x48(%rbp), %rbx
xorl %r13d, %r13d
xorl %r15d, %r15d
cmpq $0x10, %r13
je 0x302a
movl %eax, -0x38(%rbp)
movl -0x90(%rbp,%r13,4), %ecx
incq %r13
leal (%rcx,%rcx), %eax
leal (%rax,%r15,2), %eax
movl %eax, -0x34(%rbp)
movq %rcx, -0x50(%rbp)
movl %ecx, %r12d
subl $0x1, %r12d
jb 0x30f4
movq %r14, %rdi
leaq -0x29(%rbp), %rsi
pushq $0x1
popq %rdx
callq 0x21f0
movb -0x29(%rbp), %al
movl %r15d, %ecx
shll $0x10, %ecx
orl %r13d, %ecx
movl %ecx, -0x40(%rbp)
movb %al, -0x3c(%rbp)
movq %rbx, %rdi
leaq -0x40(%rbp), %rsi
callq 0x4c44
incl %r15d
jmp 0x30bc
movl -0x38(%rbp), %eax
addl -0x50(%rbp), %eax
movl -0x34(%rbp), %ecx
movl %ecx, %r15d
jmp 0x3097
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq