// File: /workspace/github_cpp_makefile_star2_O1/dannye[P]jed/src/decoder.cpp
// Function: main
int main(int argc, char** argv) {
    // validate arguments
    if (argc < 2) {
        std::cout << "Error - Invalid arguments\n";
        return 1;
    }

    for (int i = 1; i < argc; ++i) {
        const std::string filename(argv[i]);

        // read image
        JPGImage* image = readJPG(filename);
        // validate image
        if (image == nullptr) {
            continue;
        }
        if (image->blocks == nullptr) {
            delete image;
            continue;
        }
        if (image->valid == false) {
            delete[] image->blocks;
            delete image;
            continue;
        }

        // dequantize DCT coefficients
        dequantize(image);

        // Inverse Discrete Cosine Transform
        inverseDCT(image);

        // color conversion
        YCbCrToRGB(image);

        // write BMP file
        const std::size_t pos = filename.find_last_of('.');
        const std::string outFilename = (pos == std::string::npos) ?
            (filename + ".bmp") :
            (filename.substr(0, pos) + ".bmp");
        writeBMP(image, outFilename);

        delete[] image->blocks;
        delete image;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, 0x50(%rsp)
cmpl $0x2, %edi
jge 0x63a4
movq 0x3c4f(%rip), %rdi      # 0x9fd8
leaq 0x17a0(%rip), %rsi      # 0x7b30
movl $0x1a, %edx
callq 0x2130
movl $0x1, %eax
jmp 0x6596
leaq 0x30(%rsp), %r12
movl %edi, %eax
movq %rax, 0x48(%rsp)
movl $0x1, %r15d
leaq 0x20(%rsp), %r14
movq %rsp, %rdx
leaq 0x58(%rsp), %rax
movq %rax, %rbx
movq 0x50(%rsp), %rax
movq (%rax,%r15,8), %rsi
movq %r14, %rdi
movq %rdx, %r13
callq 0x2080
movq %r14, %rdi
callq 0x49bb
movq %rax, %rbp
testq %rax, %rax
movq %rbx, %rax
je 0x6564
movq 0x2080(%rbp), %rdi
testq %rdi, %rdi
je 0x6497
cmpb $0x0, 0x2088(%rbp)
je 0x6492
movq %rbp, %rdi
callq 0x55ac
movq %rbp, %rdi
callq 0x5ccb
movq %rbp, %rdi
callq 0x5f3e
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x2200
cmpq $-0x1, %rax
movq %rax, 0x40(%rsp)
je 0x64a4
movq %rbx, %r12
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x2110
movq %r12, %rdi
leaq 0x16e4(%rip), %rsi      # 0x7b4b
callq 0x21e0
leaq 0x10(%rsp), %rsi
movq %rsi, (%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x64d6
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x64dc
callq 0x2160
movl $0x20a0, %esi           # imm = 0x20A0
movq %rbp, %rdi
jmp 0x655c
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %r14
movq %r13, %rdi
callq 0x6800
movq %r14, %rdi
leaq 0x167c(%rip), %rsi      # 0x7b4b
callq 0x21e0
jmp 0x64f4
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
cmpq $-0x1, 0x40(%rsp)
leaq 0x30(%rsp), %r12
je 0x651d
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x651d
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2100
movq %rbp, %rdi
movq %r13, %rsi
callq 0x60b7
movq 0x2080(%rbp), %rdi
testq %rdi, %rdi
je 0x6539
callq 0x2160
movl $0x20a0, %esi           # imm = 0x20A0
movq %rbp, %rdi
callq 0x2100
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x6561
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2100
movq %rbx, %rax
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x657e
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2100
movq %rbx, %rax
incq %r15
cmpq %r15, 0x48(%rsp)
movq %r13, %rdx
leaq 0x20(%rsp), %r14
jne 0x63c3
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x65c4
jmp 0x65e4
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x65e7
movq 0x68(%rsp), %rsi
jmp 0x65da
jmp 0x65e4
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x65e7
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2100
jmp 0x65e7
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x6603
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2100
movq %rbx, %rdi
callq 0x21c0
nop