// File: /workspace/github_cpp_makefile_star2_O3/leobru[P]ACPUfont/averager.cc
// Function: main
int main(int argc, char**argv) {
    // Take at least 2 files, mean mode (default) or spanning tree mode.
    bool spanning = false;
    bool contrastMean = false;
    int opt;
    static const char usage[] =
        "Usage: %s [-s] [-t] [-mF] [-dN] file1 file2 ...\n\
	-s - use spanning tree combining (default - adding to the mean)\n\
	-c - contrast the mean in the default mode\n\
	-mF - use power F of the pixel count when computing MSE, default 2.0\n\
	-dN - decontrast while adding samples, N=threshold, 0: automatic selection, nondigit: 128\n";

    while ((opt = getopt(argc, argv, "scd:m:")) != -1) {
        switch (opt) {
        case 's':
            spanning = true;
            break;
        case 'c':
            contrastMean = true;
            break;
        case 'd':
            Picture::decontrast = isdigit(*optarg) ? atoi(optarg) : 128;
            break;
        case 'm':
            Picture::msepower = atof(optarg);
            if (Picture::msepower != 0.0)
                break;
        default: /* '?' */
            fprintf(stderr, usage, argv[0]);
            exit(1);
        }
    }
    if (argc - optind < 2) {
        fprintf(stderr, usage, argv[0]);
        exit(1);
    }

    vector<Picture> pics;
    for (int arg = optind; arg < argc; ++arg) {
        pics.push_back(Picture(argv[arg]));
        if (pics.back().height != pics.front().height || pics.back().width != pics.front().width) {
            fprintf(stderr, "Files must have same dimensions, got %dx%d and %dx%d\n",
                    pics.front().width, pics.front().height, pics.back().width, pics.back().height);
            exit(1);
        }
    }
    
    if (spanning) {
        averageSpanningTree(pics);
    } else {
    averageToMean(pics, contrastMean);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movl %edi, %ebp
xorl %r15d, %r15d
leaq 0x3006(%rip), %r14      # 0x5072
movq 0x5f4d(%rip), %r13      # 0x7fc0
xorl %r12d, %r12d
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1040
cmpl $0x6c, %eax
jg 0x20ae
cmpl $0x64, %eax
jne 0x20d5
movq (%r13), %rdi
movsbl (%rdi), %ecx
addl $-0x30, %ecx
movl $0x80, %eax
cmpl $0x9, %ecx
ja 0x20a6
callq 0x1170
movl %eax, 0x605c(%rip)      # 0x8108
jmp 0x2076
cmpl $0x6d, %eax
jne 0x20e8
movq (%r13), %rdi
callq 0x1130
movsd %xmm0, 0x604c(%rip)     # 0x8110
ucomisd 0x2f84(%rip), %xmm0     # 0x5050
jne 0x2076
jp 0x2076
jmp 0x21d4
cmpl $-0x1, %eax
je 0x20f6
cmpl $0x63, %eax
jne 0x21d4
movb $0x1, %r15b
jmp 0x2076
cmpl $0x73, %eax
jne 0x21d4
movb $0x1, %r12b
jmp 0x2076
movl %r15d, 0xc(%rsp)
movq 0x5ed6(%rip), %rax      # 0x7fd8
movslq (%rax), %rax
movl %ebp, %ecx
subl %eax, %ecx
cmpl $0x1, %ecx
jle 0x220a
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
cmpl %eax, %ebp
jle 0x2195
leaq (%rbx,%rax,8), %r13
movl %ecx, %ebp
xorl %r15d, %r15d
leaq 0x30(%rsp), %rbx
leaq 0x10(%rsp), %r14
movq (%r13,%r15,8), %rsi
movq %rbx, %rdi
callq 0x2c36
movq %r14, %rdi
movq %rbx, %rsi
callq 0x46fc
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x216b
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rsi
movl -0x4(%rsi), %r9d
movl 0x24(%rax), %ecx
cmpl %ecx, %r9d
jne 0x21e1
movl -0x8(%rsi), %r8d
movl 0x20(%rax), %edx
cmpl %edx, %r8d
jne 0x21dc
incq %r15
cmpl %r15d, %ebp
jne 0x213c
testb $0x1, %r12b
je 0x21a7
leaq 0x10(%rsp), %rdi
callq 0x195b
jmp 0x21b9
movzbl 0xc(%rsp), %esi
andl $0x1, %esi
leaq 0x10(%rsp), %rdi
callq 0x146c
leaq 0x10(%rsp), %rdi
callq 0x2dc4
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x1227
movl %r9d, %ecx
jmp 0x21e8
movl 0x20(%rax), %edx
movl -0x8(%rsi), %r8d
movq 0x5de1(%rip), %rax      # 0x7fd0
movq (%rax), %rdi
leaq 0x2e80(%rip), %rsi      # 0x5079
xorl %eax, %eax
callq 0x1140
movl $0x1, %edi
callq 0x1120
movq %rbx, %rdi
callq 0x1200
jmp 0x2214
movq %rax, %rbx
jmp 0x2233
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2233
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
leaq 0x10(%rsp), %rdi
callq 0x2dc4
movq %rbx, %rdi
callq 0x11b0
nop