// File: /workspace/github_cpp_makefile_star2_O1/OpenFirework[P]MyJPEG_Decoder/./jpeg/jpeg_decoder.cpp
// Function: readDC(unsigned char*&, unsigned char)
int readDC(byte *&framedata, unsigned char number) {
    unsigned int len = 0;
    unsigned char codeLen;
    for (int count = 1; ; count++) {
        len = len << 1;
        len += (unsigned int)getBit(framedata);
        if(number == 0) {
            for(int v=0;v<YDCHT.size();v++) {
                if((YDCHT[v].codeLength==count) && (YDCHT[v].encodeValue==len)) {
                    codeLen = YDCHT[v].realVale;
                    if (codeLen == 0) { return 0; }
                    unsigned char first = getBit(framedata);
                    int ret = 1;
                    for (int i = 1; i < codeLen; i++) {
                        unsigned char b = getBit(framedata);
                        ret = ret << 1;
                        ret += first ? b : !b;
                    }
                    ret = first ? ret : -ret;
                    return ret;
                }
            }
            if (count > 16) {fprintf(stderr, "key not found\n"); count = 1; len = 0; }
        } else {
            for(int v=0;v<UVDCHT.size();v++) {
                if((UVDCHT[v].codeLength==count) && (UVDCHT[v].encodeValue==len)) {
                    codeLen = UVDCHT[v].realVale;
                    if (codeLen == 0) { return 0; }
                    unsigned char first = getBit(framedata);
                    int ret = 1;
                    for (int i = 1; i < codeLen; i++) {
                        unsigned char b = getBit(framedata);
                        ret = ret << 1;
                        ret += first ? b : !b;
                    }
                    ret = first ? ret : -ret;
                    return ret;
                }
            }
            if (count > 16) {fprintf(stderr, "key not found\n"); count = 1; len = 0; }
        }
        
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %r13d
movq %rdi, %r14
xorl %r15d, %r15d
movl $0x1, %ebx
movl %esi, -0x3c(%rbp)
movq %rdi, -0x38(%rbp)
movq %r14, %rdi
callq 0x2d09
movzbl %al, %eax
leal (%rax,%r15,2), %r15d
testb %r13b, %r13b
je 0x2e1a
movq 0x62d0(%rip), %rcx      # 0x9080
movq 0x62c1(%rip), %rax      # 0x9078
subq %rax, %rcx
setne %r12b
je 0x2f64
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq $0x1, %rcx
movl $0x0, %edx
sbbq %rcx, %rdx
addq $0x8, %rax
movl $0x1, %esi
cmpl %ebx, -0x8(%rax)
jne 0x2dfa
cmpl %r15d, -0x4(%rax)
je 0x2e8b
cmpq %rsi, %rcx
seta %r12b
addq $0xc, %rax
leaq (%rdx,%rsi), %rdi
incq %rdi
incq %rsi
cmpq $0x1, %rdi
jne 0x2deb
jmp 0x2f64
movq 0x622f(%rip), %rcx      # 0x9050
movq 0x6220(%rip), %rax      # 0x9048
subq %rax, %rcx
setne %r12b
je 0x2f81
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq $0x1, %rcx
movl $0x0, %edx
sbbq %rcx, %rdx
addq $0x8, %rax
movl $0x1, %esi
cmpl %ebx, -0x8(%rax)
jne 0x2e6b
cmpl %r15d, -0x4(%rax)
je 0x2ef4
cmpq %rsi, %rcx
seta %r12b
addq $0xc, %rax
leaq (%rdx,%rsi), %rdi
incq %rdi
incq %rsi
cmpq $0x1, %rdi
jne 0x2e5c
jmp 0x2f81
movzbl (%rax), %r14d
testl %r14d, %r14d
je 0x2f59
movq %r15, -0x48(%rbp)
movq -0x38(%rbp), %rdi
callq 0x2d09
movl %eax, %r15d
movl $0x1, %r13d
cmpl $0x1, %r14d
je 0x2ed7
decl %r14d
movl $0x1, %r13d
movq -0x38(%rbp), %rdi
callq 0x2d09
xorb %r15b, %al
xorb $0x1, %al
movzbl %al, %eax
leal (%rax,%r13,2), %r13d
decl %r14d
jne 0x2ebd
movl %r13d, %eax
negl %eax
testb %r15b, %r15b
cmovnel %r13d, %eax
movl %eax, -0x2c(%rbp)
movl -0x3c(%rbp), %r13d
movq -0x38(%rbp), %r14
movq -0x48(%rbp), %r15
jmp 0x2f64
movzbl (%rax), %r14d
testl %r14d, %r14d
je 0x2f76
movq %r15, -0x48(%rbp)
movq -0x38(%rbp), %rdi
callq 0x2d09
movl %eax, %r15d
movl $0x1, %r13d
cmpl $0x1, %r14d
je 0x2f3c
decl %r14d
movl $0x1, %r13d
movq -0x38(%rbp), %rdi
callq 0x2d09
xorb %r15b, %al
xorb $0x1, %al
movzbl %al, %eax
leal (%rax,%r13,2), %r13d
decl %r14d
jne 0x2f22
movl %r13d, %eax
negl %eax
testb %r15b, %r15b
cmovnel %r13d, %eax
movl %eax, -0x2c(%rbp)
movl -0x3c(%rbp), %r13d
movq -0x38(%rbp), %r14
movq -0x48(%rbp), %r15
jmp 0x2f81
movl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %r14
testb $0x1, %r12b
jne 0x2fb6
cmpl $0x11, %ebx
jge 0x2f8c
incl %ebx
jmp 0x2d95
movl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %r14
testb $0x1, %r12b
jne 0x2fb6
cmpl $0x10, %ebx
jle 0x2f6f
movq 0x5045(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
movl $0xe, %esi
movl $0x1, %edx
leaq 0x2326(%rip), %rdi      # 0x52cd
callq 0x2250
xorl %r15d, %r15d
movl $0x1, %ebx
jmp 0x2f6f
movl -0x2c(%rbp), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq