// File: /workspace/github_cpp_makefile_star2_O2/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 %r12d, %r12d
leaq 0x366f(%rip), %r14      # 0x505a
movq 0x75ce(%rip), %r15      # 0x8fc0
xorl %r13d, %r13d
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1040
cmpl $0x64, %eax
je 0x1a2d
cmpl $0x6d, %eax
jne 0x1a4d
movq (%r15), %rdi
callq 0x1130
movsd %xmm0, 0x76f4(%rip)     # 0x9110
ucomisd 0x3604(%rip), %xmm0     # 0x5028
jne 0x19f5
jp 0x19f5
jmp 0x1b2f
movq (%r15), %rdi
movsbl (%rdi), %ecx
addl $-0x30, %ecx
movl $0x80, %eax
cmpl $0x9, %ecx
ja 0x1a45
callq 0x1170
movl %eax, 0x76bd(%rip)      # 0x9108
jmp 0x19f5
cmpl $-0x1, %eax
je 0x1a6a
cmpl $0x73, %eax
je 0x1a65
cmpl $0x63, %eax
jne 0x1b2f
movb $0x1, %r12b
jmp 0x19f5
movb $0x1, %r13b
jmp 0x19f5
movl %r12d, 0xc(%rsp)
movq 0x7562(%rip), %rax      # 0x8fd8
movslq (%rax), %r12
movl %ebp, %eax
subl %r12d, %eax
cmpl $0x1, %eax
jle 0x1b2f
leaq 0x10(%rsp), %r14
andq $0x0, 0x10(%r14)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14)
movslq %ebp, %rbp
leaq 0x30(%rsp), %r15
cmpq %rbp, %r12
jge 0x1af0
movq (%rbx,%r12,8), %rsi
movq %r15, %rdi
callq 0x239e
movq %r14, %rdi
movq %r15, %rsi
callq 0x4464
movq %r15, %rdi
callq 0x256e
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rsi
movl -0x4(%rsi), %r9d
movl 0x24(%rax), %ecx
cmpl %ecx, %r9d
jne 0x1b4c
movl -0x8(%rsi), %r8d
movl 0x20(%rax), %edx
incq %r12
cmpl %edx, %r8d
je 0x1aa2
movl %r9d, %ecx
jmp 0x1b53
testb $0x1, %r13b
je 0x1b02
leaq 0x10(%rsp), %rdi
callq 0x15d6
jmp 0x1b14
movzbl 0xc(%rsp), %esi
andl $0x1, %esi
leaq 0x10(%rsp), %rdi
callq 0x131c
leaq 0x10(%rsp), %rdi
callq 0x254c
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x749a(%rip), %rax      # 0x8fd0
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x363d(%rip), %rsi      # 0x5180
xorl %eax, %eax
callq 0x1140
jmp 0x1b6b
movl 0x20(%rax), %edx
movl -0x8(%rsi), %r8d
movq 0x7476(%rip), %rax      # 0x8fd0
movq (%rax), %rdi
leaq 0x34fd(%rip), %rsi      # 0x5061
xorl %eax, %eax
callq 0x1140
pushq $0x1
popq %rdi
callq 0x1120
jmp 0x1b75
movq %rax, %rbx
jmp 0x1b87
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x256e
leaq 0x10(%rsp), %rdi
callq 0x254c
movq %rbx, %rdi
callq 0x11b0
nop