// File: /workspace/github_cpp_makefile_star2_O3/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 $0x98, %rsp
movq %rsi, 0x50(%rsp)
cmpl $0x2, %edi
jge 0x3d43
movq 0x32b0(%rip), %rdi      # 0x6fd8
leaq 0x153a(%rip), %rsi      # 0x5269
movl $0x1a, %edx
callq 0x2120
movl $0x1, %eax
jmp 0x3ef4
leaq 0x18(%rsp), %rbp
movl %edi, %eax
movq %rax, 0x48(%rsp)
movl $0x1, %ebx
leaq 0x28(%rsp), %r15
leaq 0x8(%rsp), %rdx
leaq 0x60(%rsp), %r14
movq 0x50(%rsp), %rax
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
callq 0x2080
leaq 0x80(%rsp), %rdi
movq %r15, %r13
movq %r15, %rsi
callq 0x241f
movq 0x88(%rsp), %rax
movq %rax, 0x58(%rsp)
testq %rax, %rax
je 0x3ec0
leaq 0x80(%rsp), %r15
movq %r15, %rdi
callq 0x2a5a
movq %r15, %rdi
callq 0x2f8d
movq %r15, %rdi
callq 0x3024
movq %r13, %r12
movq %r13, %rdi
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x2200
cmpq $-0x1, %rax
je 0x3e1f
movq %r14, %r15
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x2110
movq %r15, %rdi
leaq 0x148d(%rip), %rsi      # 0x5284
callq 0x21e0
movq %rbp, 0x8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x3e4f
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x3e56
movq %rbp, 0x8(%rsp)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x40e2
movq %r15, %rdi
leaq 0x143c(%rip), %rsi      # 0x5284
callq 0x21e0
jmp 0x3e8f
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x3e8a
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2100
leaq 0x8(%rsp), %r15
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0x3acb
movq 0x58(%rsp), %rdi
callq 0x2140
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3ec0
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2100
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x3edc
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2100
incq %rbx
cmpq %rbx, 0x48(%rsp)
movq %r13, %r15
leaq 0x8(%rsp), %rdx
jne 0x3d63
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3f25
jmp 0x3f41
movq %rax, %rbx
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x3f44
movq 0x70(%rsp), %rsi
jmp 0x3f37
jmp 0x3f41
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3f44
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2100
jmp 0x3f44
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x3f60
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2100
movq %rbx, %rdi
callq 0x21c0