// File: /workspace/github_cpp_makefile_star2_O3/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 0x2b07
movl $0x1, %eax
jmp 0x4c3a
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 0x4b39
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 0x5cda
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 0x596a
movq %r12, 0xc0(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x670a
incq %rbp
cmpq %rbp, %r13
jne 0x49b0
leaq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x5d76
leaq 0xc0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3ea7
movq 0x10(%rbx), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x5b68
leaq 0xc0(%rsp), %rdi
callq 0x593c
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 0x4a5a
movq %rbx, %rdi
callq 0x593c
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 0x4c38
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
jmp 0x4c38
cmpl $0x5, %r14d
je 0x4aa9
movq (%rbx), %rdi
callq 0x2b07
movq 0x10(%rbx), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x596a
movq 0x18(%rbx), %rsi
leaq 0x50(%rsp), %rdi
callq 0x596a
leaq 0x8(%rsp), %rcx
movl $0x0, (%rcx)
leaq 0x128(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movl $0xa, %r8d
callq 0x3a41
movq 0x20(%rbx), %rdi
movl 0x8(%rsp), %ecx
leaq 0x128(%rsp), %rsi
movl $0xa, %edx
callq 0x45ab
movq 0x128(%rsp), %rdi
testq %rdi, %rdi
je 0x4b2a
movq 0x138(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
leaq 0x50(%rsp), %rdi
callq 0x593c
jmp 0x4c2b
cmpl $0x5, %r14d
je 0x4b47
movq (%rbx), %rdi
callq 0x2b07
movq 0x10(%rbx), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x596a
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 0x5a02
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x5ae8
movl (%rsp), %ecx
leaq 0x128(%rsp), %rdi
leaq 0x190(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq 0x3c6f
movl 0x4(%rsp), %edx
leaq 0x50(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x3dd6
movq 0x20(%rbx), %rsi
leaq 0x50(%rsp), %rdi
callq 0x5b68
leaq 0x50(%rsp), %rdi
callq 0x593c
leaq 0x128(%rsp), %rdi
callq 0x593c
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x4c07
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
leaq 0x190(%rsp), %rdi
callq 0x593c
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x4c2b
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
leaq 0xc0(%rsp), %rdi
callq 0x593c
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 0x593c
jmp 0x4c61
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4d4b
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
jmp 0x4d41
jmp 0x4d48
jmp 0x4d48
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x593c
jmp 0x4c98
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x593c
jmp 0x4caa
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x4cc6
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
jmp 0x4cc6
movq %rax, %rbx
leaq 0x190(%rsp), %rdi
callq 0x593c
jmp 0x4cd8
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x4d27
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
jmp 0x4d27
jmp 0x4d24
movq %rax, %rbx
movq 0x128(%rsp), %rdi
testq %rdi, %rdi
je 0x4d18
movq 0x138(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
jmp 0x4d18
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x593c
jmp 0x4d27
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x593c
jmp 0x4d62
movq %rax, %rbx
movl $0x68, %esi
movq %r12, %rdi
callq 0x2220
jmp 0x4d4b
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x4d62
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq %rbx, %rdi
callq 0x23a0