// File: /workspace/github_cpp_makefile_star2_O1/dannye[P]jed/src/encoder.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
        BMPImage image = readBMP(filename);
        // validate image
        if (image.blocks == nullptr) {
            continue;
        }

        // color conversion
        RGBToYCbCr(image);

        // Forward Discrete Cosine Transform
        forwardDCT(image);

        // quantize DCT coefficients
        quantize(image);

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

        delete[] image.blocks;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, 0x48(%rsp)
cmpl $0x2, %edi
jge 0x3fc5
movq 0x302e(%rip), %rdi      # 0x6fd8
leaq 0x12c8(%rip), %rsi      # 0x5279
movl $0x1a, %edx
callq 0x2120
movl $0x1, %eax
jmp 0x415f
leaq 0x10(%rsp), %rbp
movl %edi, %eax
movq %rax, 0x40(%rsp)
movl $0x1, %ebx
leaq 0x20(%rsp), %r14
movq %rsp, %r15
movq 0x48(%rsp), %rax
movq (%rax,%rbx,8), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x2080
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x241f
movq 0x78(%rsp), %r13
testq %r13, %r13
je 0x4133
movq %rbp, %r15
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
callq 0x2a64
movq %rbp, %rdi
callq 0x304a
movq %rbp, %rdi
callq 0x30e1
movq %r14, %rdi
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x2200
movq %rax, %rbp
cmpq $-0x1, %rax
je 0x408f
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rbp, %rcx
callq 0x2110
movq %r12, %rdi
leaq 0x122b(%rip), %rsi      # 0x5294
callq 0x21e0
movq %r15, (%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x40bc
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x40c3
movq %r15, (%rsp)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
movq %rsp, %r14
movq %r14, %rdi
callq 0x4356
movq %r14, %rdi
leaq 0x11df(%rip), %rsi      # 0x5294
callq 0x21e0
jmp 0x40db
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
cmpq $-0x1, %rbp
movq %r15, %rbp
movq %rsp, %r15
leaq 0x20(%rsp), %r14
je 0x4108
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x4108
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2100
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
callq 0x3d4c
movq %r13, %rdi
callq 0x2140
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0x4133
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2100
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x414f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2100
incq %rbx
cmpq %rbx, 0x40(%rsp)
jne 0x3fde
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
jne 0x41a8
jmp 0x41ba
jmp 0x41b7
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x41ba
movq 0x60(%rsp), %rsi
jmp 0x41ad
jmp 0x41b7
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0x41ba
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2100
jmp 0x41ba
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x41d6
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2100
movq %rbx, %rdi
callq 0x21c0