// File: /workspace/github_cpp_makefile_star2_O1/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 0x3052(%rip), %r14      # 0x5072
movq 0x5f99(%rip), %r13      # 0x7fc0
xorl %r12d, %r12d
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1040
cmpl $0x6c, %eax
jg 0x2062
cmpl $0x64, %eax
jne 0x2089
movq (%r13), %rdi
movsbl (%rdi), %ecx
addl $-0x30, %ecx
movl $0x80, %eax
cmpl $0x9, %ecx
ja 0x205a
callq 0x1170
movl %eax, 0x60a8(%rip)      # 0x8108
jmp 0x202a
cmpl $0x6d, %eax
jne 0x209c
movq (%r13), %rdi
callq 0x1130
movsd %xmm0, 0x6098(%rip)     # 0x8110
ucomisd 0x2fd0(%rip), %xmm0     # 0x5050
jne 0x202a
jp 0x202a
jmp 0x2184
cmpl $-0x1, %eax
je 0x20aa
cmpl $0x63, %eax
jne 0x2184
movb $0x1, %r15b
jmp 0x202a
cmpl $0x73, %eax
jne 0x2184
movb $0x1, %r12b
jmp 0x202a
movl %r15d, 0xc(%rsp)
movq 0x5f22(%rip), %rax      # 0x7fd8
movslq (%rax), %rax
movl %ebp, %ecx
subl %eax, %ecx
cmpl $0x1, %ecx
jle 0x21b5
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
cmpl %eax, %ebp
jle 0x2145
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 0x2bdc
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4722
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x211f
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rax
movl -0x4(%rax), %r9d
movl 0x24(%rdx), %ecx
cmpl %ecx, %r9d
jne 0x218c
movl -0x8(%rax), %esi
cmpl 0x20(%rdx), %esi
jne 0x218c
incq %r15
cmpl %r15d, %ebp
jne 0x20f0
testb $0x1, %r12b
je 0x2157
leaq 0x10(%rsp), %rdi
callq 0x18e4
jmp 0x2169
movzbl 0xc(%rsp), %esi
andl $0x1, %esi
leaq 0x10(%rsp), %rdi
callq 0x144c
leaq 0x10(%rsp), %rdi
callq 0x2d62
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x1227
movq 0x5e3d(%rip), %rsi      # 0x7fd0
movq (%rsi), %rdi
movl 0x20(%rdx), %edx
movl -0x8(%rax), %r8d
leaq 0x2ed5(%rip), %rsi      # 0x5079
xorl %eax, %eax
callq 0x1140
movl $0x1, %edi
callq 0x1120
movq %rbx, %rdi
callq 0x1200
jmp 0x21bf
movq %rax, %rbx
jmp 0x21de
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x21de
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
leaq 0x10(%rsp), %rdi
callq 0x2d62
movq %rbx, %rdi
callq 0x11b0