// File: 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
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x4c73(%rip), %rdi      # 0x5fd0
leaq 0x2ca0(%rip), %rsi      # 0x4004
callq 0x10b0
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x10b0
movq %rax, %rdi
movq 0x4c3d(%rip), %rsi      # 0x5fc0
callq 0x10c0
movq 0x4c41(%rip), %rdi      # 0x5fd0
leaq 0x2c79(%rip), %rsi      # 0x400f
callq 0x10b0
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x10b0
movq %rax, %rdi
movq 0x4c0b(%rip), %rsi      # 0x5fc0
callq 0x10c0
movq 0x4c0f(%rip), %rdi      # 0x5fd0
leaq 0x2c52(%rip), %rsi      # 0x401a
callq 0x10b0
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x10b0
movq %rax, %rdi
movq 0x4bd9(%rip), %rsi      # 0x5fc0
callq 0x10c0
movq 0x4bdd(%rip), %rdi      # 0x5fd0
leaq 0x2c2b(%rip), %rsi      # 0x4025
callq 0x10b0
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x10b0
movq %rax, %rdi
movq 0x4ba7(%rip), %rsi      # 0x5fc0
callq 0x10c0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x1160
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x1160
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1475
movq 0x4ba0(%rip), %rdi      # 0x5ff0
leaq 0x2bd9(%rip), %rsi      # 0x4030
callq 0x10b0
movq %rax, %rdi
movq 0x4b5a(%rip), %rsi      # 0x5fc0
callq 0x10c0
movl $0x1, %edi
callq 0x10f0
cmpl $0x3, -0x14(%rbp)
je 0x14a7
movq 0x4b6e(%rip), %rdi      # 0x5ff0
leaq 0x2bc4(%rip), %rsi      # 0x404d
callq 0x10b0
movq %rax, %rdi
movq 0x4b28(%rip), %rsi      # 0x5fc0
callq 0x10c0
movl $0x1, %edi
callq 0x10f0
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jle 0x14db
movq 0x4b3a(%rip), %rdi      # 0x5ff0
leaq 0x2bbe(%rip), %rsi      # 0x407b
callq 0x10b0
movq %rax, %rdi
movq 0x4af4(%rip), %rsi      # 0x5fc0
callq 0x10c0
movl $0x1, %edi
callq 0x10f0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2be0
movq %rax, -0x20(%rbp)
movl $0x10, %edi
callq 0x1120
movq %rax, -0x28(%rbp)
movl $0x10, %edi
callq 0x1120
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x30(%rbp), %rdx
callq 0x1570
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movq -0x28(%rbp), %r8
callq 0x1980
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x2f00
movq -0x20(%rbp), %rdi
callq 0x3100
movq -0x28(%rbp), %rdi
callq 0x3100
movq -0x30(%rbp), %rdi
callq 0x3100
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)