// File: /workspace/github_cpp_makefile_star2_O3/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 0x60b2
movq 0x3f41(%rip), %rdi      # 0x9fd8
leaq 0x1a92(%rip), %rsi      # 0x7b30
movl $0x1a, %edx
callq 0x2130
movl $0x1, %eax
jmp 0x628d
movl %edi, %eax
movq %rax, 0x48(%rsp)
movl $0x1, %r12d
leaq 0x28(%rsp), %r14
leaq 0x8(%rsp), %rdx
leaq 0x58(%rsp), %rcx
movq %rcx, %r15
movq 0x50(%rsp), %rax
movq (%rax,%r12,8), %rsi
movq %r14, %rdi
movq %rdx, %rbx
callq 0x2080
movq %r14, %rdi
callq 0x48aa
movq %rax, %rbp
testq %rax, %rax
movq %r15, %rcx
je 0x625b
movq 0x2080(%rbp), %rdi
testq %rdi, %rdi
je 0x6196
cmpb $0x0, 0x2088(%rbp)
je 0x6191
movq %rbp, %rdi
callq 0x5327
movq %rbp, %rdi
callq 0x599e
movq %rbp, %rdi
callq 0x5c32
movq %r14, %rdi
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x2200
cmpq $-0x1, %rax
je 0x61a3
movq %r15, %r13
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x2110
movq %r13, %rdi
leaq 0x19e7(%rip), %rsi      # 0x7b4b
callq 0x21e0
leaq 0x18(%rsp), %rsi
movq %rsi, 0x8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x61d6
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x61dc
callq 0x2160
movl $0x20a0, %esi           # imm = 0x20A0
movq %rbp, %rdi
jmp 0x6253
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
movq %rbx, %r13
movq %rbx, %rdi
callq 0x64b6
movq %r13, %rdi
leaq 0x197c(%rip), %rsi      # 0x7b4b
callq 0x21e0
jmp 0x6213
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x6210
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2100
movq %rbx, %r13
movq %rbp, %rdi
movq %r13, %rsi
callq 0x5dcb
movq 0x2080(%rbp), %rdi
testq %rdi, %rdi
je 0x622f
callq 0x2160
movl $0x20a0, %esi           # imm = 0x20A0
movq %rbp, %rdi
callq 0x2100
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x6258
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2100
movq %r15, %rcx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x627a
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2100
movq %r15, %rcx
incq %r12
cmpq %r12, 0x48(%rsp)
movq %rbx, %rdx
jne 0x60ce
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x62bb
jmp 0x62dc
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x62df
movq 0x68(%rsp), %rsi
jmp 0x62d2
jmp 0x62dc
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x62df
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2100
jmp 0x62df
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x62fb
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2100
movq %rbx, %rdi
callq 0x21c0
nop