// File: /workspace/github_cpp_makefile_star2_O3/rapirent[P]JPEG/decoder.c
// Function: main
int main(int argc,char* argv[])
{
    if (argc != 2  && argc != 3) {
        printf("[ERROR]:\nusage: ./decoder <input_file> [<output_file_name>]");
        exit(1);
    }
    FILE* fp;
    if ((fp = fopen(argv[1], "r")) == NULL) {
        printf("%s can't be opened\n", argv[1]);
        exit(1);
    }
    const char* fwrite = argc ==3 ? argv[2] : "image.bmp";

    byte h;
    byte l;
    bool b_SOI = false;
    bool b_EOI = false;
    init_cos_cache();
    while (fread(&h,1, 1,fp)) {
        fread(&l,1, 1,fp);
        if (h == 0xff) {
            if (!b_SOI && l == SOI) {
                b_SOI = true;
            }
            assert(b_SOI == true);
            switch(l) {
            case DQT:
                read_qt(fp);
                break;
            case SOF0:
                read_frame(fp);
                break;
            case DHT:
                read_ht(fp);
                break;
            case SOS:
                read_sos(fp);
                calculate_mcu(fp,fwrite);
                break;
            case APP0:
            case APP1:
            case APP2:
            case APP3:
            case APP4:
            case APP5:
            case APP6:
            case APP7:
            case APP8:
            case APP9:
            case APP10:
            case APP11:
            case APP12:
            case APP13:
            case APP14:
            case APP15:
                break;
            case EOI:
                b_EOI = true;
                break;
            }
        }
    }
    assert(b_EOI==true);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %r15d
leal -0x4(%r15), %eax
cmpl $-0x3, %eax
jbe 0x6898
movq %rsi, %r14
movq 0x8(%rsi), %rdi
leaq 0x1206(%rip), %rsi      # 0x78cd
callq 0x5140
testq %rax, %rax
je 0x68a8
movq %rax, %rbx
cmpl $0x3, %r15d
jne 0x66e4
movq 0x10(%r14), %r14
jmp 0x66eb
leaq 0x1297(%rip), %r14      # 0x7982
leaq 0x4b2e(%rip), %r15      # 0xb220
xorl %r12d, %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
mulsd 0x903(%rip), %xmm0      # 0x7008
mulsd 0x903(%rip), %xmm0      # 0x7010
callq 0x5210
movsd %xmm0, (%r15)
incq %r12
addq $0x8, %r15
cmpq $0xc8, %r12
jne 0x66f5
leaq 0x6(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x51b0
testq %rax, %rax
je 0x6879
xorl %ebp, %ebp
leaq 0x7(%rsp), %r15
leaq 0x6(%rsp), %r12
xorl %r13d, %r13d
movl $0x1, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x51b0
cmpb $-0x1, 0x6(%rsp)
je 0x6791
movl $0x1, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rbx, %rcx
callq 0x51b0
testq %rax, %rax
jne 0x6756
jmp 0x6843
movb 0x7(%rsp), %al
cmpb $-0x28, %al
movzbl %r13b, %ecx
movl $0x1, %r13d
cmovnel %ecx, %r13d
testb $0x1, %cl
cmovnel %ecx, %r13d
testb $0x1, %r13b
je 0x685a
movzbl %al, %eax
cmpl $0xd8, %eax
jle 0x67d8
cmpl $0xda, %eax
je 0x67f0
cmpl $0xdb, %eax
jne 0x6815
movq %rbx, %rdi
callq 0x5470
jmp 0x6772
cmpl $0xc0, %eax
je 0x6808
cmpl $0xc4, %eax
jne 0x6772
movq %rbx, %rdi
callq 0x5662
jmp 0x6772
movq %rbx, %rdi
callq 0x57ea
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5e04
jmp 0x6772
movq %rbx, %rdi
callq 0x552a
jmp 0x6772
cmpl $0xd9, %eax
jne 0x6772
movl $0x1, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rbx, %rcx
callq 0x51b0
movb $0x1, %bpl
testq %rax, %rax
jne 0x6756
jmp 0x6849
testb $0x1, %bpl
je 0x6879
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x112b(%rip), %rdi      # 0x798c
leaq 0x1080(%rip), %rsi      # 0x78e8
leaq 0x112b(%rip), %rcx      # 0x799a
movl $0x1a1, %edx            # imm = 0x1A1
callq 0x5090
leaq 0x1131(%rip), %rdi      # 0x79b1
leaq 0x1061(%rip), %rsi      # 0x78e8
leaq 0x110c(%rip), %rcx      # 0x799a
movl $0x1c7, %edx            # imm = 0x1C7
callq 0x5090
leaq 0x1093(%rip), %rdi      # 0x7932
xorl %eax, %eax
callq 0x5040
jmp 0x68ba
movq 0x8(%r14), %rsi
leaq 0x10bb(%rip), %rdi      # 0x796e
xorl %eax, %eax
callq 0x5040
movl $0x1, %edi
callq 0x5160