// File: 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
subq $0x70, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x1, -0x20(%rbp)
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3f00
andb $0x1, %al
movzbl %al, %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movzbl -0x11(%rbp), %eax
cmpl $0x0, %eax
jne 0x418f
movl $0x0, -0x24(%rbp)
movslq -0x24(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x8029(%rip), %rdi      # 0xc068
callq 0x4b50
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jae 0x415e
movslq -0x24(%rbp), %rsi
leaq 0x8009(%rip), %rdi      # 0xc068
callq 0x4b80
movl (%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0x414e
movslq -0x24(%rbp), %rsi
leaq 0x7fee(%rip), %rdi      # 0xc068
callq 0x4b80
movl 0x4(%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x414e
movslq -0x24(%rbp), %rsi
leaq 0x7fd2(%rip), %rdi      # 0xc068
callq 0x4b80
movb 0x8(%rax), %al
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jne 0x40b6
movl $0x0, -0x4(%rbp)
jmp 0x42ff
movq -0x10(%rbp), %rdi
callq 0x3f00
andb $0x1, %al
movb %al, -0x25(%rbp)
movl $0x1, -0x2c(%rbp)
movl $0x1, -0x30(%rbp)
movl -0x30(%rbp), %eax
movzbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x4127
movq -0x10(%rbp), %rdi
callq 0x3f00
andb $0x1, %al
movb %al, -0x31(%rbp)
movl -0x2c(%rbp), %eax
shll %eax
movl %eax, -0x2c(%rbp)
cmpb $0x0, -0x25(%rbp)
je 0x4102
movzbl -0x31(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x4113
cmpb $0x0, -0x31(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x40d2
cmpb $0x0, -0x25(%rbp)
je 0x4135
movl -0x2c(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x413d
xorl %eax, %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x42ff
jmp 0x4150
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4030
cmpl $0x10, -0x20(%rbp)
jle 0x418a
movq 0x6e6d(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x44fb(%rip), %rsi      # 0x8670
movb $0x0, %al
callq 0x21e0
movl $0x1, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
jmp 0x42ef
movl $0x0, -0x38(%rbp)
movslq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq 0x7ef3(%rip), %rdi      # 0xc098
callq 0x4b50
movq %rax, %rcx
movq -0x60(%rbp), %rax
cmpq %rcx, %rax
jae 0x42c1
movslq -0x38(%rbp), %rsi
leaq 0x7ed3(%rip), %rdi      # 0xc098
callq 0x4b80
movl (%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0x42b1
movslq -0x38(%rbp), %rsi
leaq 0x7eb8(%rip), %rdi      # 0xc098
callq 0x4b80
movl 0x4(%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x42b1
movslq -0x38(%rbp), %rsi
leaq 0x7e9c(%rip), %rdi      # 0xc098
callq 0x4b80
movb 0x8(%rax), %al
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jne 0x421c
movl $0x0, -0x4(%rbp)
jmp 0x42ff
movq -0x10(%rbp), %rdi
callq 0x3f00
andb $0x1, %al
movb %al, -0x39(%rbp)
movl $0x1, -0x40(%rbp)
movl $0x1, -0x44(%rbp)
movl -0x44(%rbp), %eax
movzbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x428d
movq -0x10(%rbp), %rdi
callq 0x3f00
andb $0x1, %al
movb %al, -0x45(%rbp)
movl -0x40(%rbp), %eax
shll %eax
movl %eax, -0x40(%rbp)
cmpb $0x0, -0x39(%rbp)
je 0x4268
movzbl -0x45(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x4279
cmpb $0x0, -0x45(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x4238
cmpb $0x0, -0x39(%rbp)
je 0x429b
movl -0x40(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x42a3
xorl %eax, %eax
subl -0x40(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x42ff
jmp 0x42b3
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x4196
cmpl $0x10, -0x20(%rbp)
jle 0x42ed
movq 0x6d0a(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x4398(%rip), %rsi      # 0x8670
movb $0x0, %al
callq 0x21e0
movl $0x1, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
jmp 0x42ef
jmp 0x42f1
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x4000
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)