// File: /workspace/github_cpp_makefile_star2_O1/OpenFirework[P]MyJPEG_Decoder/./jpeg/jpeg_decoder.cpp
// Function: MyJPEG::jpegDecoder::readinfo(unsigned char*&, unsigned char*&, int&, int&)
int MyJPEG::jpegDecoder::readinfo(byte *&jpegdata, byte *&bgrdata, int &imgwidth, int &imgheidht) {
    init_c();
    init_cos_cache();
    unsigned char start;
    unsigned short two;
    memcpy(&start, jpegdata++, 1);
    if(start == 0xFF) {
        memcpy(&start, jpegdata++, 1);
        if(start == 0xD8) {          //jpeg文件开头标识符：0XFFD8
            std::cout<<"This is a jpeg file and open success!\n";
        }
        else {
            std::cout<<"This is not a jpeg file, decode failed!\n";
        } 
    }

    memcpy(&start, jpegdata++, 1);
    while(start == 0xFF) {
        memcpy(&start, jpegdata++, 1);
        switch (start) {
            case 0xE0:
            case 0xE1:
            case 0xE2:
            case 0xE3:
            case 0xE4:
            case 0xE5:
            case 0xE6:
            case 0xE7:
            case 0xE8:
            case 0xE9:
            case 0xEA:
            case 0xEB:
            case 0xEC:
            case 0xED:
            case 0xEE:
            case 0xEF:
                readAPP0(jpegdata);
                break;
            case 0xFE:
                readCOM(jpegdata);
                break;
            case 0xDB:
                readDQT(jpegdata);
                break;
            case 0xC0:
                readSOF0(jpegdata);
                imgwidth = image.width;
                imgheidht = image.height;
                break;
            case 0xC4:
                reaDHT(jpegdata);
                break;
            case 0xDA:
                readSOS(jpegdata);
                decodeMCU(jpegdata, bgrdata);
                break;
            default:
            break;
        }
        memcpy(&start, jpegdata++, 1);
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
xorl %eax, %eax
movabsq $0x3fd6a09e667f3bcd, %rcx # imm = 0x3FD6A09E667F3BCD
leaq 0x5b24(%rip), %rdx      # 0x8170
movabsq $0x3fe0000000000000, %rsi # imm = 0x3FE0000000000000
leaq 0x5b53(%rip), %rdi      # 0x81b0
testq %rax, %rax
je 0x266c
movq %rsi, (%rax,%rdx)
movq %rsi, (%rax,%rdi)
jmp 0x267a
movq %rcx, 0x5afd(%rip)      # 0x8170
movq %rcx, 0x5b36(%rip)      # 0x81b0
addq $0x8, %rax
cmpq $0x40, %rax
jne 0x265d
leaq 0x5b65(%rip), %r14      # 0x81f0
xorl %r15d, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
mulsd 0x296a(%rip), %xmm0     # 0x5008
mulsd 0x296a(%rip), %xmm0     # 0x5010
callq 0x2240
movsd %xmm0, (%r14)
incq %r15
addq $0x8, %r14
cmpq $0xc8, %r15
jne 0x268e
movq (%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rbx)
cmpb $-0x1, (%rax)
jne 0x2709
leaq 0x2(%rax), %rcx
movq %rcx, (%rbx)
cmpb $-0x28, 0x1(%rax)
jne 0x26f1
movq 0x58ed(%rip), %rdi      # 0x7fd0
leaq 0x2a36(%rip), %rsi      # 0x5120
movl $0x26, %edx
jmp 0x2704
movq 0x58d8(%rip), %rdi      # 0x7fd0
leaq 0x2a48(%rip), %rsi      # 0x5147
movl $0x28, %edx
callq 0x2130
movq (%rbx), %rax
incq %rax
leaq 0x293a(%rip), %rcx      # 0x5050
movq %rax, (%rbx)
cmpb $-0x1, -0x1(%rax)
jne 0x274e
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movzbl (%rax), %edx
addq $0x2, %rax
leal -0xc0(%rdx), %esi
cmpl $0x2f, %esi
ja 0x2741
movslq (%rcx,%rsi,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
cmpl $0xfe, %edx
jne 0x2716
callq 0x22d8
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x22f2
callq 0x22be
callq 0x2270
callq 0x228a
callq 0x22a4