// File: /workspace/github_cpp_makefile_star2_O1/OpenFirework[P]MyJPEG_Decoder/./jpeg/jpeg_decoder.cpp
// Function: readAC(unsigned char*&, unsigned char)
acCode readAC(byte *&framedata, unsigned char number) {
    unsigned char x;
    unsigned int len = 0;
    for (int count = 1; ; count++) {
        len = len << 1;
        len += (unsigned int)getBit(framedata);
        if(number == 0) {
            for(int v=0;v<YACHT.size();v++) {
                if((YACHT[v].codeLength==count) && (YACHT[v].encodeValue==len)) {
                    x = YACHT[v].realVale;
                    unsigned char zeros = x >> 4;
                    unsigned char codeLen = x & 0x0F;
                    if (x == 0) {
                        return acCode{0,0,0};
                    } else if (x == 0xF0) {
                        return acCode{0, 16, 0};
                    }
                    unsigned  char first = getBit(framedata);
                    int code = 1;
                    for (int i = 1; i < codeLen; i++) {
                        unsigned char b = getBit(framedata);
                        code = code << 1;
                        code += first ? b : !b;
                    }
                    code = first ? code : -code;
                    return acCode{codeLen, zeros, code};
                }
            }
            if (count > 16) {fprintf(stderr, "key not found\n"); count = 1; len = 0;}
        } else {
            for(int v=0;v<UVACHT.size();v++) {
                if((UVACHT[v].codeLength==count) && (UVACHT[v].encodeValue==len)) {
                    x = UVACHT[v].realVale;
                    unsigned char zeros = x >> 4;
                    unsigned char codeLen = x & 0x0F;
                    if (x == 0) {
                        return acCode{0,0,0};
                    } else if (x == 0xF0) {
                        return acCode{0, 16, 0};
                    }
                    unsigned  char first = getBit(framedata);
                    int code = 1;
                    
                    for (int i = 1; i < codeLen; i++) {
                        unsigned char b = getBit(framedata);
                        code = code << 1;
                        code += first ? b : !b;
                    }
                    code = first ? code : -code;
                    return acCode{codeLen, zeros, code};
                }
            }
            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, %r14d
movq %rdi, %r12
xorl %r15d, %r15d
movl $0x1, %r13d
movl %eax, -0x30(%rbp)
movl %eax, -0x2c(%rbp)
movq %rax, -0x38(%rbp)
movl %esi, -0x3c(%rbp)
movq %r12, %rdi
callq 0x2d09
movzbl %al, %eax
leal (%rax,%r15,2), %r15d
testb %r14b, %r14b
je 0x3087
movq 0x6088(%rip), %rcx      # 0x9098
movq 0x6079(%rip), %rax      # 0x9090
subq %rax, %rcx
setne %bl
je 0x3070
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 %r13d, -0x8(%rax)
jne 0x3056
cmpl %r15d, -0x4(%rax)
je 0x3127
cmpq %rsi, %rcx
seta %bl
addq $0xc, %rax
leaq (%rdx,%rsi), %rdi
incq %rdi
incq %rsi
cmpq $0x1, %rdi
jne 0x3046
testb $0x1, %bl
jne 0x32a0
cmpl $0x11, %r13d
jge 0x30f9
incl %r13d
jmp 0x2ff5
movq 0x5fda(%rip), %rcx      # 0x9068
movq 0x5fcb(%rip), %rax      # 0x9060
subq %rax, %rcx
setne %bl
je 0x30ea
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 %r13d, -0x8(%rax)
jne 0x30d0
cmpl %r15d, -0x4(%rax)
je 0x314e
cmpq %rsi, %rcx
seta %bl
addq $0xc, %rax
leaq (%rdx,%rsi), %rdi
incq %rdi
incq %rsi
cmpq $0x1, %rdi
jne 0x30c4
testb $0x1, %bl
jne 0x32a0
cmpl $0x10, %r13d
jle 0x307f
movq 0x4ed8(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
movl $0xe, %esi
movl $0x1, %edx
leaq 0x21b9(%rip), %rdi      # 0x52cd
callq 0x2250
xorl %r15d, %r15d
movl $0x1, %r13d
jmp 0x307f
movzbl (%rax), %eax
testl %eax, %eax
je 0x317d
cmpl $0xf0, %eax
jne 0x318e
movl $0x0, -0x30(%rbp)
movb $0x10, %al
movl %eax, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0x3070
movzbl (%rax), %eax
testl %eax, %eax
je 0x3211
cmpl $0xf0, %eax
jne 0x3222
movl $0x0, -0x30(%rbp)
movb $0x10, %al
movl %eax, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0x30ea
movl %eax, %ecx
movl %ecx, -0x30(%rbp)
movl %eax, -0x2c(%rbp)
movq %rax, -0x38(%rbp)
jmp 0x3070
movl %r13d, -0x4c(%rbp)
movq %r15, -0x48(%rbp)
movl %eax, -0x2c(%rbp)
movq %r12, %r15
movl %eax, %r12d
andl $0xf, %r12d
movq %r15, %rdi
callq 0x2d09
movl %eax, %r13d
movl $0x1, %r14d
movl %r12d, -0x30(%rbp)
cmpb $0x2, %r12b
jb 0x31e4
movl -0x30(%rbp), %r12d
decl %r12d
movl $0x1, %r14d
movq %r15, %rdi
callq 0x2d09
xorb %r13b, %al
xorb $0x1, %al
movzbl %al, %eax
leal (%rax,%r14,2), %r14d
decl %r12d
jne 0x31cb
movl -0x2c(%rbp), %eax
shrb $0x4, %al
movl %eax, -0x2c(%rbp)
movl %r14d, %eax
negl %eax
testb %r13b, %r13b
cmovnel %r14d, %eax
movq %rax, -0x38(%rbp)
movl -0x3c(%rbp), %r14d
movq %r15, %r12
movq -0x48(%rbp), %r15
movl -0x4c(%rbp), %r13d
jmp 0x3070
movl %eax, %ecx
movl %ecx, -0x30(%rbp)
movl %eax, -0x2c(%rbp)
movq %rax, -0x38(%rbp)
jmp 0x30ea
movq %r15, -0x48(%rbp)
movl %eax, -0x2c(%rbp)
movl %eax, %r15d
andl $0xf, %r15d
movq %r12, %rdi
callq 0x2d09
movl %eax, %ecx
movl $0x1, %r14d
movl %r15d, -0x30(%rbp)
cmpb $0x2, %r15b
movq %r12, %r15
jb 0x3278
movl -0x30(%rbp), %r12d
decl %r12d
movl $0x1, %r14d
movb %cl, -0x38(%rbp)
movq %r15, %rdi
callq 0x2d09
movb -0x38(%rbp), %cl
xorb %cl, %al
xorb $0x1, %al
movzbl %al, %eax
leal (%rax,%r14,2), %r14d
decl %r12d
jne 0x325d
movl -0x2c(%rbp), %eax
shrb $0x4, %al
movl %eax, -0x2c(%rbp)
movl %r14d, %eax
negl %eax
testb %cl, %cl
cmovnel %r14d, %eax
movq %rax, -0x38(%rbp)
movl -0x3c(%rbp), %r14d
movq %r15, %r12
movq -0x48(%rbp), %r15
jmp 0x30ea
movl -0x2c(%rbp), %eax
movq -0x38(%rbp), %rdx
shlq $0x20, %rdx
movzbl %al, %ecx
shll $0x8, %ecx
orq %rdx, %rcx
movzbl -0x30(%rbp), %eax
orq %rcx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq