// File: 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
subq $0x70, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x1, -0x1c(%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 0x4508
movl $0x0, -0x20(%rbp)
movslq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x7d11(%rip), %rdi      # 0xc080
callq 0x4b50
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jae 0x44d7
movslq -0x20(%rbp), %rsi
leaq 0x7cf1(%rip), %rdi      # 0xc080
callq 0x4b80
movl (%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x44c7
movslq -0x20(%rbp), %rsi
leaq 0x7cd6(%rip), %rdi      # 0xc080
callq 0x4b80
movl 0x4(%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x44c7
movslq -0x20(%rbp), %rsi
leaq 0x7cba(%rip), %rdi      # 0xc080
callq 0x4b80
movb 0x8(%rax), %al
movb %al, -0x12(%rbp)
movzbl -0x12(%rbp), %eax
sarl $0x4, %eax
movb %al, -0x21(%rbp)
movzbl -0x12(%rbp), %eax
andl $0xf, %eax
movb %al, -0x22(%rbp)
movzbl -0x12(%rbp), %eax
cmpl $0x0, %eax
jne 0x4402
movb $0x0, -0x8(%rbp)
movb $0x0, -0x7(%rbp)
movl $0x0, -0x4(%rbp)
jmp 0x46c1
movzbl -0x12(%rbp), %eax
cmpl $0xf0, %eax
jne 0x4421
movb $0x0, -0x8(%rbp)
movb $0x10, -0x7(%rbp)
movl $0x0, -0x4(%rbp)
jmp 0x46c1
jmp 0x4423
movq -0x10(%rbp), %rdi
callq 0x3f00
andb $0x1, %al
movb %al, -0x23(%rbp)
movl $0x1, -0x28(%rbp)
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movzbl -0x22(%rbp), %ecx
cmpl %ecx, %eax
jge 0x4494
movq -0x10(%rbp), %rdi
callq 0x3f00
andb $0x1, %al
movb %al, -0x2d(%rbp)
movl -0x28(%rbp), %eax
shll %eax
movl %eax, -0x28(%rbp)
cmpb $0x0, -0x23(%rbp)
je 0x446f
movzbl -0x2d(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x4480
cmpb $0x0, -0x2d(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x443f
cmpb $0x0, -0x23(%rbp)
je 0x44a2
movl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x44aa
xorl %eax, %eax
subl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x28(%rbp)
movb -0x22(%rbp), %al
movb %al, -0x8(%rbp)
movb -0x21(%rbp), %al
movb %al, -0x7(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x46c1
jmp 0x44c9
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x4360
cmpl $0x10, -0x1c(%rbp)
jle 0x4503
movq 0x6af4(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x4182(%rip), %rsi      # 0x8670
movb $0x0, %al
callq 0x21e0
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
jmp 0x46b1
movl $0x0, -0x34(%rbp)
movslq -0x34(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq 0x7b92(%rip), %rdi      # 0xc0b0
callq 0x4b50
movq %rax, %rcx
movq -0x60(%rbp), %rax
cmpq %rcx, %rax
jae 0x4683
movslq -0x34(%rbp), %rsi
leaq 0x7b72(%rip), %rdi      # 0xc0b0
callq 0x4b80
movl (%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x4673
movslq -0x34(%rbp), %rsi
leaq 0x7b57(%rip), %rdi      # 0xc0b0
callq 0x4b80
movl 0x4(%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x4673
movslq -0x34(%rbp), %rsi
leaq 0x7b3b(%rip), %rdi      # 0xc0b0
callq 0x4b80
movb 0x8(%rax), %al
movb %al, -0x12(%rbp)
movzbl -0x12(%rbp), %eax
sarl $0x4, %eax
movb %al, -0x35(%rbp)
movzbl -0x12(%rbp), %eax
andl $0xf, %eax
movb %al, -0x36(%rbp)
movzbl -0x12(%rbp), %eax
cmpl $0x0, %eax
jne 0x45b1
movb $0x0, -0x8(%rbp)
movb $0x0, -0x7(%rbp)
movl $0x0, -0x4(%rbp)
jmp 0x46c1
movzbl -0x12(%rbp), %eax
cmpl $0xf0, %eax
jne 0x45d0
movb $0x0, -0x8(%rbp)
movb $0x10, -0x7(%rbp)
movl $0x0, -0x4(%rbp)
jmp 0x46c1
jmp 0x45d2
movq -0x10(%rbp), %rdi
callq 0x3f00
andb $0x1, %al
movb %al, -0x37(%rbp)
movl $0x1, -0x3c(%rbp)
movl $0x1, -0x40(%rbp)
movl -0x40(%rbp), %eax
movzbl -0x36(%rbp), %ecx
cmpl %ecx, %eax
jge 0x4643
movq -0x10(%rbp), %rdi
callq 0x3f00
andb $0x1, %al
movb %al, -0x41(%rbp)
movl -0x3c(%rbp), %eax
shll %eax
movl %eax, -0x3c(%rbp)
cmpb $0x0, -0x37(%rbp)
je 0x461e
movzbl -0x41(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x462f
cmpb $0x0, -0x41(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x45ee
cmpb $0x0, -0x37(%rbp)
je 0x4651
movl -0x3c(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x4659
xorl %eax, %eax
subl -0x3c(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x3c(%rbp)
movb -0x36(%rbp), %al
movb %al, -0x8(%rbp)
movb -0x35(%rbp), %al
movb %al, -0x7(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x46c1
jmp 0x4675
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x450f
cmpl $0x10, -0x1c(%rbp)
jle 0x46af
movq 0x6948(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x3fd6(%rip), %rsi      # 0x8670
movb $0x0, %al
callq 0x21e0
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
jmp 0x46b1
jmp 0x46b3
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4330
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)