// File: /workspace/github_cpp_makefile_star2_O1/brianwu02[P]ImageProcessing/median.cpp
// Function: main
int main(int argc, char** argv) {
    
    int sz, avg_nbrs;
    imageP I1, I2, paddedImg;
   
    cout << "in      : " << argv[1] << endl;
    cout << "sz      : " << argv[2] << endl;
    cout << "avg_nbrs: " << argv[3] << endl;
    cout << "out     : " << argv[4] << endl;
    
    sz = atoi(argv[2]);
    avg_nbrs = atoi(argv[3]);
    
    if ((sz & 1) == 0) {
        cerr << "sz is must be an odd number." << endl;
        exit(1);
    }

    if (sz != 3) {
        cerr << "sz only working for 3, as requested. exiting." << endl;
        exit(1);
    }

    if (avg_nbrs > sz) {
        cerr << "average number cannot be larger than sz, at least i dont think it can" << endl;
        exit(1);
    }

    I1 = IP_readImage(argv[1]);

    I2 = NEWIMAGE;
    paddedImg = NEWIMAGE;

    padImage(I1, sz, paddedImg);
    median(I1, paddedImg, sz, avg_nbrs, I2);

    //IP_saveImage(paddedImg, argv[4]);
    IP_saveImage(I2, argv[4]);
    IP_freeImage(I1);
    IP_freeImage(I2);
    IP_freeImage(paddedImg);
    return 0;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq 0x3c22(%rip), %r14      # 0x5fd0
leaq 0x1c63(%rip), %rsi      # 0x4018
movl $0xa, %edx
movq %r14, %rdi
callq 0x2110
movq 0x8(%rbx), %r15
testq %r15, %r15
je 0x23e7
movq %r15, %rdi
callq 0x2070
movq 0x3bf6(%rip), %rdi      # 0x5fd0
movq %r15, %rsi
movq %rax, %rdx
callq 0x2110
jmp 0x23ff
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x20e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
leaq 0x1bf6(%rip), %rsi      # 0x4023
movl $0xa, %edx
movq %r14, %rdi
callq 0x2110
movq 0x10(%rbx), %r15
testq %r15, %r15
je 0x245f
movq %r15, %rdi
callq 0x2070
movq 0x3b7e(%rip), %rdi      # 0x5fd0
movq %r15, %rsi
movq %rax, %rdx
callq 0x2110
jmp 0x2477
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x20e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
leaq 0x1b89(%rip), %rsi      # 0x402e
movl $0xa, %edx
movq %r14, %rdi
callq 0x2110
movq 0x18(%rbx), %r15
testq %r15, %r15
je 0x24d7
movq %r15, %rdi
callq 0x2070
movq 0x3b06(%rip), %rdi      # 0x5fd0
movq %r15, %rsi
movq %rax, %rdx
callq 0x2110
jmp 0x24ef
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x20e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
leaq 0x1b1c(%rip), %rsi      # 0x4039
movl $0xa, %edx
movq %r14, %rdi
callq 0x2110
movq 0x20(%rbx), %r15
testq %r15, %r15
je 0x254f
movq %r15, %rdi
callq 0x2070
movq 0x3a8e(%rip), %rdi      # 0x5fd0
movq %r15, %rsi
movq %rax, %rdx
callq 0x2110
jmp 0x2567
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x20e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
movq 0x10(%rbx), %rdi
callq 0x21a0
movl %eax, %r14d
movq 0x18(%rbx), %rdi
callq 0x21a0
testb $0x1, %r14b
je 0x263c
cmpl $0x3, %r14d
jne 0x264c
movl %eax, %ebp
cmpl $0x4, %eax
jge 0x265c
movq 0x8(%rbx), %rdi
callq 0x31b4
movq %rax, %r14
movl $0x10, %edi
callq 0x2160
movq %rax, %r15
movl $0x10, %edi
callq 0x2160
movq %rax, %r12
movq %r14, %rdi
movl $0x3, %esi
movq %rax, %rdx
callq 0x2681
movq %r14, %rdi
movq %r12, %rsi
movl $0x3, %edx
movl %ebp, %ecx
movq %r15, %r8
callq 0x29c5
movq 0x20(%rbx), %rsi
movq %r15, %rdi
callq 0x33da
movq %r14, %rdi
callq 0x358b
movq %r15, %rdi
callq 0x358b
movq %r12, %rdi
callq 0x358b
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x39ad(%rip), %rdi      # 0x5ff0
leaq 0x19fa(%rip), %rsi      # 0x4044
jmp 0x266a
movq 0x399d(%rip), %rdi      # 0x5ff0
leaq 0x1a07(%rip), %rsi      # 0x4061
jmp 0x266a
movq 0x398d(%rip), %rdi      # 0x5ff0
leaq 0x1a25(%rip), %rsi      # 0x408f
callq 0x20f0
movq %rax, %rdi
callq 0x2080
movl $0x1, %edi
callq 0x2130