// File: OpenFirework[P]MyJPEG_Decoder/./jpeg/jpeg_decoder.cpp
// Function: readAPP0(unsigned char*&)
void readAPP0(byte *&jpegdata) {
    std::cout<<"\n************APP0 INFO*******************\n";
    int length = readSectionLength(jpegdata);
    std::cout<<"本数据段的长度为："<<length<<"\n";
    byte *appdata = new byte[length-2];  //length 包括前面的长度信息数据所占的2个字节
    memcpy(appdata, jpegdata, length-2);
    jpegdata = jpegdata + (length-2);
    //开始输出本段的信息
    std::cout<<"标识符：";
    std::cout<<std::setw(5)<<appdata<<";\t";
    std::cout<<"版本号：";
    std::cout<<static_cast<int>(appdata[5])<<"."<<static_cast<int>(appdata[6])<<"\n";
    std::cout<<"X和Y的密度单位: "<<static_cast<int>(appdata[7])<<"; ---注释：0：无单位；1：点数/英寸；2：点数/厘米\n";
    int x = appdata[8]*256 + appdata[9];
    int y = appdata[10]*256 + appdata[11];
    std::cout<<"X方向像素密度:"<<x<<";  Y方向像素密度:"<<y<<"\n";
    std::cout<<"缩略图水平像素数目:"<<static_cast<int>(appdata[12])<<"; 缩略图垂直像素数目:"<<static_cast<int>(appdata[13])<<"\n";
    if(length == 16) {
        std::cout<<"该jpeg文件没有缩略图RGB位图\n";
    } else {
        std::cout<<"该jpeg文件有缩略图RGB位图\n";
    }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq 0x87bd(%rip), %rdi      # 0xafd0
leaq 0x59a7(%rip), %rsi      # 0x81c1
callq 0x2130
movq -0x8(%rbp), %rdi
callq 0x3d40
movl %eax, -0xc(%rbp)
movq 0x879e(%rip), %rdi      # 0xafd0
leaq 0x59b3(%rip), %rsi      # 0x81ec
callq 0x2130
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x6157(%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 0x872d(%rip), %rdi      # 0xafd0
leaq 0x595e(%rip), %rsi      # 0x8208
callq 0x2130
movl $0x5, %edi
callq 0x4a90
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %esi
movq 0x870a(%rip), %rdi      # 0xafd0
callq 0x2180
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x2160
movq %rax, %rdi
leaq 0x5934(%rip), %rsi      # 0x8215
callq 0x2130
movq 0x86e3(%rip), %rdi      # 0xafd0
leaq 0x5924(%rip), %rsi      # 0x8218
callq 0x2130
movq -0x18(%rbp), %rax
movzbl 0x5(%rax), %esi
movq 0x86c8(%rip), %rdi      # 0xafd0
callq 0x2250
movq %rax, %rdi
leaq 0x590e(%rip), %rsi      # 0x8225
callq 0x2130
movq %rax, %rdi
movq -0x18(%rbp), %rax
movzbl 0x6(%rax), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x6074(%rip), %rsi      # 0x89aa
callq 0x2130
movq 0x868e(%rip), %rdi      # 0xafd0
leaq 0x58de(%rip), %rsi      # 0x8227
callq 0x2130
movq %rax, %rdi
movq -0x18(%rbp), %rax
movzbl 0x7(%rax), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x58d6(%rip), %rsi      # 0x823e
callq 0x2130
movq -0x18(%rbp), %rax
movzbl 0x8(%rax), %eax
shll $0x8, %eax
movq -0x18(%rbp), %rcx
movzbl 0x9(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movzbl 0xa(%rax), %eax
shll $0x8, %eax
movq -0x18(%rbp), %rcx
movzbl 0xb(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movq 0x862c(%rip), %rdi      # 0xafd0
leaq 0x58d8(%rip), %rsi      # 0x8283
callq 0x2130
movq %rax, %rdi
movl -0x20(%rbp), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x58d3(%rip), %rsi      # 0x8298
callq 0x2130
movq %rax, %rdi
movl -0x24(%rbp), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x5fcb(%rip), %rsi      # 0x89aa
callq 0x2130
movq 0x85e5(%rip), %rdi      # 0xafd0
leaq 0x58be(%rip), %rsi      # 0x82b0
callq 0x2130
movq %rax, %rdi
movq -0x18(%rbp), %rax
movzbl 0xc(%rax), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x58bc(%rip), %rsi      # 0x82cd
callq 0x2130
movq %rax, %rdi
movq -0x18(%rbp), %rax
movzbl 0xd(%rax), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x5f7a(%rip), %rsi      # 0x89aa
callq 0x2130
cmpl $0x10, -0xc(%rbp)
jne 0x2a50
movq 0x858e(%rip), %rdi      # 0xafd0
leaq 0x58a3(%rip), %rsi      # 0x82ec
callq 0x2130
jmp 0x2a63
movq 0x8579(%rip), %rdi      # 0xafd0
leaq 0x58b5(%rip), %rsi      # 0x8313
callq 0x2130
cmpq $0x0, -0x18(%rbp)
je 0x2a83
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x2a81
movq -0x30(%rbp), %rdi
callq 0x21a0
jmp 0x2a83
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)