// File: OpenFirework[P]MyJPEG_Decoder/./jpeg/jpeg_decoder.cpp
// Function: reaDHT(unsigned char*&)
void reaDHT(byte *&jpegdata) {
    std::cout<<"\n************DHT INFO*******************\n";
    int length = readSectionLength(jpegdata);
    std::cout<<"本数据段的长度为："<<length<<"\n";
    byte *dhtdata = new byte[length-2];  //length 包括前面的长度信息数据所占的2个字节
    memcpy(dhtdata, jpegdata, length-2);
    jpegdata = jpegdata + (length-2);

    int type = dhtdata[0]>>4;
    int tableid = dhtdata[0]&0x0F;
    if(type == 0) { 
        std::cout<<"DC哈夫曼表; "<<"Table ID:"<<tableid<<"\n";
    } else if (type ==1){
        std::cout<<"AC哈夫曼表; "<<"Table ID:"<<tableid<<"\n";
    } else {
        std::cout<<"读取哈夫曼表失败，数据不正确\n";
    }

    int huf[16] = {0};
    for(int i=0;i<16;i++) {
        std::cout<<static_cast<int>(dhtdata[i+1])<<" ";
        huf[i] = dhtdata[i+1];
    }
    std::cout<<"\n";

    if(type == 0 && tableid ==0) {   //Y分量的DC（直流）哈夫曼码表
        createhuftable(huf, dhtdata+17, length-2-17, YDCHT);   
    } else if(type == 0 && tableid ==1) {   //UV分量的DC（直流）哈夫曼码表,这两个分量公用相同的DC，AC哈夫曼表
        createhuftable(huf, dhtdata+17, length-2-17, UVDCHT);   
    } else if(type == 1 && tableid == 0) {   //Y分量的AC（交流）哈夫曼码表,
        createhuftable(huf, dhtdata+17, length-2-17, YACHT);   
    } else if(type == 1 && tableid == 1) {   //UV分量的AC（交流）哈夫曼码表,这两个分量公用相同的DC，AC哈夫曼表
        createhuftable(huf, dhtdata+17, length-2-17, UVACHT); 
    }

    if(dhtdata != nullptr) {
        delete[] dhtdata;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq 0x7d8d(%rip), %rdi      # 0xafd0
leaq 0x529c(%rip), %rsi      # 0x84e6
callq 0x2130
movq -0x8(%rbp), %rdi
callq 0x3d40
movl %eax, -0xc(%rbp)
movq 0x7d6e(%rip), %rdi      # 0xafd0
leaq 0x4f83(%rip), %rsi      # 0x81ec
callq 0x2130
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x5727(%rip), %rsi      # 0x89aa
callq 0x2130
movl -0xc(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rdi
callq 0x2030
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movl -0xc(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rdx
callq 0x2110
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movl -0xc(%rbp), %eax
subl $0x2, %eax
cltq
addq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
sarl $0x4, %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
andl $0xf, %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x332a
movq 0x7cdd(%rip), %rdi      # 0xafd0
leaq 0x5216(%rip), %rsi      # 0x8510
callq 0x2130
movq %rax, %rdi
leaq 0x5218(%rip), %rsi      # 0x8521
callq 0x2130
movq %rax, %rdi
movl -0x20(%rbp), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x5687(%rip), %rsi      # 0x89aa
callq 0x2130
jmp 0x3383
cmpl $0x1, -0x1c(%rbp)
jne 0x336e
movq 0x7c99(%rip), %rdi      # 0xafd0
leaq 0x51ed(%rip), %rsi      # 0x852b
callq 0x2130
movq %rax, %rdi
leaq 0x51d4(%rip), %rsi      # 0x8521
callq 0x2130
movq %rax, %rdi
movl -0x20(%rbp), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x5643(%rip), %rsi      # 0x89aa
callq 0x2130
jmp 0x3381
movq 0x7c5b(%rip), %rdi      # 0xafd0
leaq 0x51c0(%rip), %rsi      # 0x853c
callq 0x2130
jmp 0x3383
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x20c0
movl $0x0, -0x64(%rbp)
cmpl $0x10, -0x64(%rbp)
jge 0x33f0
movq -0x18(%rbp), %rax
movl -0x64(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %esi
movq 0x7c18(%rip), %rdi      # 0xafd0
callq 0x2250
movq %rax, %rdi
leaq 0x4e75(%rip), %rsi      # 0x823c
callq 0x2130
movq -0x18(%rbp), %rax
movl -0x64(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %ecx
movslq -0x64(%rbp), %rax
movl %ecx, -0x60(%rbp,%rax,4)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x339a
movq 0x7bd9(%rip), %rdi      # 0xafd0
leaq 0x55ac(%rip), %rsi      # 0x89aa
callq 0x2130
cmpl $0x0, -0x1c(%rbp)
jne 0x3435
cmpl $0x0, -0x20(%rbp)
jne 0x3435
leaq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x11, %rsi
movl -0xc(%rbp), %edx
subl $0x2, %edx
subl $0x11, %edx
leaq 0x8c3d(%rip), %rcx      # 0xc068
callq 0x3da0
jmp 0x34c6
cmpl $0x0, -0x1c(%rbp)
jne 0x3464
cmpl $0x1, -0x20(%rbp)
jne 0x3464
leaq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x11, %rsi
movl -0xc(%rbp), %edx
subl $0x2, %edx
subl $0x11, %edx
leaq 0x8c3b(%rip), %rcx      # 0xc098
callq 0x3da0
jmp 0x34c4
cmpl $0x1, -0x1c(%rbp)
jne 0x3493
cmpl $0x0, -0x20(%rbp)
jne 0x3493
leaq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x11, %rsi
movl -0xc(%rbp), %edx
subl $0x2, %edx
subl $0x11, %edx
leaq 0x8bf4(%rip), %rcx      # 0xc080
callq 0x3da0
jmp 0x34c2
cmpl $0x1, -0x1c(%rbp)
jne 0x34c0
cmpl $0x1, -0x20(%rbp)
jne 0x34c0
leaq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x11, %rsi
movl -0xc(%rbp), %edx
subl $0x2, %edx
subl $0x11, %edx
leaq 0x8bf5(%rip), %rcx      # 0xc0b0
callq 0x3da0
jmp 0x34c2
jmp 0x34c4
jmp 0x34c6
cmpq $0x0, -0x18(%rbp)
je 0x34e6
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, %rax
je 0x34e4
movq -0x70(%rbp), %rdi
callq 0x21a0
jmp 0x34e6
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)