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

    int colors = sosdata[0];
    std::cout<<"图片的颜色格式为：";
    if(colors == 1) {
        std::cout<<"灰度图\n";
    } else if(colors == 3) {
        std::cout<<"YCrCb格式彩色图\n";
    } else if(colors == 4) {
        std::cout<<"CMYK格式彩色图\n";
    }  else {
        std::cout<<"解析图像格式错误\n";
    }
    for(int i=0;i<colors;i++) {
        std::cout<<"颜色分量ID:"<<static_cast<int>(sosdata[i*2 +1])<<"\n";
        byte tmp = sosdata[i*2 +2];
        int DCnum = tmp>>4;
        int ACnum = tmp&0x0F;
        std::cout<<"直流分量使用的哈夫曼表ID:"<<DCnum<<"\n";
        std::cout<<"交流分量使用的哈夫曼表ID:"<<DCnum<<"\n";
    }
    printf("谱选择开始:0x%02X\n",sosdata[7]);
    printf("谱选择结束:0x%02X\n",sosdata[8]);
    printf("谱选择:0x%02X\n",sosdata[9]);
    if(sosdata != nullptr) {
        delete[] sosdata;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq 0x7acd(%rip), %rdi      # 0xafd0
leaq 0x505e(%rip), %rsi      # 0x8568
callq 0x2130
movq -0x8(%rbp), %rdi
callq 0x3d40
movl %eax, -0xc(%rbp)
movq 0x7aae(%rip), %rdi      # 0xafd0
leaq 0x4cc3(%rip), %rsi      # 0x81ec
callq 0x2130
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x5467(%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
movl %eax, -0x1c(%rbp)
movq 0x7a33(%rip), %rdi      # 0xafd0
leaq 0x4e5f(%rip), %rsi      # 0x8403
callq 0x2130
cmpl $0x1, -0x1c(%rbp)
jne 0x35c4
movq 0x7a1a(%rip), %rdi      # 0xafd0
leaq 0x4e62(%rip), %rsi      # 0x841f
callq 0x2130
jmp 0x3611
cmpl $0x3, -0x1c(%rbp)
jne 0x35df
movq 0x79ff(%rip), %rdi      # 0xafd0
leaq 0x4e52(%rip), %rsi      # 0x842a
callq 0x2130
jmp 0x360f
cmpl $0x4, -0x1c(%rbp)
jne 0x35fa
movq 0x79e4(%rip), %rdi      # 0xafd0
leaq 0x4e4d(%rip), %rsi      # 0x8440
callq 0x2130
jmp 0x360d
movq 0x79cf(%rip), %rdi      # 0xafd0
leaq 0x4e4d(%rip), %rsi      # 0x8455
callq 0x2130
jmp 0x360f
jmp 0x3611
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x36f2
movq 0x79a5(%rip), %rdi      # 0xafd0
leaq 0x4f60(%rip), %rsi      # 0x8592
callq 0x2130
movq %rax, %rdi
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x534e(%rip), %rsi      # 0x89aa
callq 0x2130
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
shll %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x21(%rbp)
movzbl -0x21(%rbp), %eax
sarl $0x4, %eax
movl %eax, -0x28(%rbp)
movzbl -0x21(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x2c(%rbp)
movq 0x793f(%rip), %rdi      # 0xafd0
leaq 0x4f0a(%rip), %rsi      # 0x85a2
callq 0x2130
movq %rax, %rdi
movl -0x28(%rbp), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x52f8(%rip), %rsi      # 0x89aa
callq 0x2130
movq 0x7912(%rip), %rdi      # 0xafd0
leaq 0x4f02(%rip), %rsi      # 0x85c7
callq 0x2130
movq %rax, %rdi
movl -0x28(%rbp), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x52cb(%rip), %rsi      # 0x89aa
callq 0x2130
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3618
movq -0x18(%rbp), %rax
movzbl 0x7(%rax), %esi
leaq 0x4eeb(%rip), %rdi      # 0x85ec
movb $0x0, %al
callq 0x2040
movq -0x18(%rbp), %rax
movzbl 0x8(%rax), %esi
leaq 0x4eed(%rip), %rdi      # 0x8604
movb $0x0, %al
callq 0x2040
movq -0x18(%rbp), %rax
movzbl 0x9(%rax), %esi
leaq 0x4eef(%rip), %rdi      # 0x861c
movb $0x0, %al
callq 0x2040
cmpq $0x0, -0x18(%rbp)
je 0x3754
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x3752
movq -0x38(%rbp), %rdi
callq 0x21a0
jmp 0x3754
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)