// File: /workspace/github_cpp_makefile_star2_O1/iibrahimli[P]adsa_project/src/main.cpp
// Function: main
int main(int argc, char *argv[]){

    // main just parses arguments and calls needed functions

    unsigned int resolution = 10;  // thickness of horizontal strips

    if(argc < 5){
        print_help(argv[0]);
        return 1;
    }

    if(!strcmp(argv[1], "--psf")){
        if(argc != 1+4) print_help(argv[0]);

        BMP_image a(argv[2]);
        BMP_image b(argv[3]);
        int maxshift = 0;

        auto psf = calc_psf(a, b, &maxshift, resolution);

        // psf file format: n_strips \n thickness \n maxshift \n psf1 \n ... psfN \n
        write_psf(argv[4], psf, resolution, maxshift);
    }
    else if(!strcmp(argv[1], "--scale")){
        if(argc != 1+4) print_help(argv[0]);
        
        BMP_image a(argv[2]);
        int maxshift = 0;

        auto psf = read_psf(argv[3], &resolution, &maxshift);

        cut_strip(psf_resize(a, psf, resolution), maxshift).save_as(argv[4]);
        
    }
    else if(!strcmp(argv[1], "--merge")){
        vector<const BMP_image*> images;
        images.reserve(argc-3);

        for(int arg=3; arg<argc; ++arg){
            images.push_back(new BMP_image(argv[arg]));
        }
        merge(images).save_as(argv[2]);
        
        // free memory
        for(int i=0; i<images.size(); ++i) delete images[i];
    }
    else{
        print_help(argv[0]);
        return 1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rsi, %rbx
movl $0xa, (%rsp)
cmpl $0x4, %edi
jg 0x4937
movq (%rbx), %rdi
callq 0x2b0b
movl $0x1, %eax
jmp 0x4c36
movl %edi, %r14d
movq 0x8(%rbx), %r15
leaq 0x2bc1(%rip), %rsi      # 0x7506
movq %r15, %rdi
callq 0x22c0
testl %eax, %eax
je 0x4a9b
leaq 0x2bb0(%rip), %rsi      # 0x750c
movq %r15, %rdi
callq 0x22c0
testl %eax, %eax
je 0x4b35
leaq 0x2ba1(%rip), %rsi      # 0x7514
movq %r15, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x4925
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
leal -0x3(%r14), %esi
callq 0x5cca
movl %r14d, %r13d
movl $0x3, %ebp
leaq 0x50(%rsp), %r14
leaq 0xc0(%rsp), %r15
movl $0x68, %edi
callq 0x2210
movq %rax, %r12
movq (%rbx,%rbp,8), %rsi
movq %rax, %rdi
callq 0x5954
movq %r12, 0xc0(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x66e0
incq %rbp
cmpq %rbp, %r13
jne 0x49b0
leaq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x5d60
leaq 0xc0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3ea0
movq 0x10(%rbx), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x5b58
leaq 0xc0(%rsp), %rdi
callq 0x5926
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4a3a
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq 0x50(%rsp), %rdi
cmpq %rdi, 0x58(%rsp)
je 0x4a80
xorl %r14d, %r14d
movq (%rdi,%r14,8), %rbx
testq %rbx, %rbx
je 0x4a67
movq %rbx, %rdi
callq 0x5926
movl $0x68, %esi
movq %rbx, %rdi
callq 0x2220
incq %r14
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rax
subq %rdi, %rax
sarq $0x3, %rax
cmpq %r14, %rax
ja 0x4a49
testq %rdi, %rdi
je 0x4c34
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
jmp 0x4c34
cmpl $0x5, %r14d
je 0x4aa9
movq (%rbx), %rdi
callq 0x2b0b
movq 0x10(%rbx), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x5954
movq 0x18(%rbx), %rsi
leaq 0x50(%rsp), %rdi
callq 0x5954
leaq 0x8(%rsp), %rcx
movl $0x0, (%rcx)
movl (%rsp), %r8d
leaq 0x128(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x3a39
movq 0x20(%rbx), %rdi
movl (%rsp), %edx
movl 0x8(%rsp), %ecx
leaq 0x128(%rsp), %rsi
callq 0x45ab
movq 0x128(%rsp), %rdi
testq %rdi, %rdi
je 0x4b26
movq 0x138(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
leaq 0x50(%rsp), %rdi
callq 0x5926
jmp 0x4c27
cmpl $0x5, %r14d
je 0x4b43
movq (%rbx), %rdi
callq 0x2b0b
movq 0x10(%rbx), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x5954
leaq 0x4(%rsp), %rcx
movl $0x0, (%rcx)
movq 0x18(%rbx), %rsi
leaq 0x8(%rsp), %rdi
movq %rsp, %rdx
callq 0x4791
leaq 0x190(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x59ec
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x5ad8
movl (%rsp), %ecx
leaq 0x128(%rsp), %rdi
leaq 0x190(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq 0x3c68
movl 0x4(%rsp), %edx
leaq 0x50(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x3dcf
movq 0x20(%rbx), %rsi
leaq 0x50(%rsp), %rdi
callq 0x5b58
leaq 0x50(%rsp), %rdi
callq 0x5926
leaq 0x128(%rsp), %rdi
callq 0x5926
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x4c03
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
leaq 0x190(%rsp), %rdi
callq 0x5926
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x4c27
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
leaq 0xc0(%rsp), %rdi
callq 0x5926
xorl %eax, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x5926
jmp 0x4c5d
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4d47
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
jmp 0x4d3d
jmp 0x4d44
jmp 0x4d44
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x5926
jmp 0x4c94
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x5926
jmp 0x4ca6
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x4cc2
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
jmp 0x4cc2
movq %rax, %rbx
leaq 0x190(%rsp), %rdi
callq 0x5926
jmp 0x4cd4
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x4d23
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
jmp 0x4d23
jmp 0x4d20
movq %rax, %rbx
movq 0x128(%rsp), %rdi
testq %rdi, %rdi
je 0x4d14
movq 0x138(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
jmp 0x4d14
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x5926
jmp 0x4d23
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x5926
jmp 0x4d5e
movq %rax, %rbx
movl $0x68, %esi
movq %r12, %rdi
callq 0x2220
jmp 0x4d47
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x4d5e
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq %rbx, %rdi
callq 0x23a0