// File: /workspace/github_cpp_makefile_star2_O1/leobru[P]ACPUfont/averager.cc
// Function: averageToMean(std::vector<Picture, std::allocator<Picture>>&, bool)
void averageToMean(vector<Picture> & pics, bool contrastMean) {
    Picture mean = pics.front();
    for (uint i = 1; i < pics.size(); ++i) {
        mean = mean.add(pics[i], 0, 0);
    }
    mean = mean.divide();
    mean.dump(fopen("mean.pgm", "w"));
    if (contrastMean) {
        int pivot = (mean.find_knee(false) + mean.find_knee(true))/2;
        mean = mean.contrast(pivot, 2);
        mean.dump(fopen("contrasted.pgm", "w"));
    }
    Picture & res = mean;
    // Sort by closeness to the mean
    vector<std::pair<double, int> > order(pics.size());
    for (uint i = 0; i < pics.size(); ++i) {
        order[i] = std::make_pair(mean.mse(pics[i], 0, 0), i);
    }
    std::sort(order.begin(), order.end());
    for (uint i = 0; i < pics.size(); ++i) { 
        int voff = 0, hoff = 0;
        res.best_offset(pics[order[i].second], voff, hoff);
        res = res.add(pics[order[i].second], voff, hoff);
    }
    res.dump(stdout);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movq (%rdi), %r15
movq %rsp, %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x2e0e
movups 0x18(%r15), %xmm0
movups %xmm0, 0x18(%r14)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x3333333333333333, %r13 # imm = 0xCCCCCCCCCCCCCCCD
imulq %r13, %rcx
cmpq $0x2, %rcx
jb 0x154c
movl $0x1, %ecx
movl $0x2, %r14d
leaq 0x30(%rsp), %r15
movq %rsp, %r12
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rdx
movq %r15, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x21f0
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movaps 0x30(%rsp), %xmm0
movaps %xmm0, (%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0x1505
subq %rdi, %rsi
callq 0x1100
leaq 0x48(%rsp), %rax
movups (%rax), %xmm0
movq %rsp, %rax
movups %xmm0, 0x18(%rax)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x152b
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movl %r14d, %ecx
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
incl %r14d
cmpq %rcx, %rdx
ja 0x14b3
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0x23ce
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movaps 0x30(%rsp), %xmm0
movaps %xmm0, (%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0x1593
subq %rdi, %rsi
callq 0x1100
movups 0x48(%rsp), %xmm0
movq %rsp, %rax
movups %xmm0, 0x18(%rax)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x15b6
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
leaq 0x3a9b(%rip), %rdi      # 0x5058
leaq 0x3a9d(%rip), %rsi      # 0x5061
callq 0x1110
movq %rsp, %rdi
movq %rax, %rsi
callq 0x246c
testb %bpl, %bpl
je 0x168e
movq %rsp, %rdi
xorl %esi, %esi
callq 0x252c
movl %eax, %ebp
movq %rsp, %rdi
movl $0x1, %esi
callq 0x252c
addl %ebp, %eax
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
movl $0x2, %ecx
callq 0x2712
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movaps 0x30(%rsp), %xmm0
movaps %xmm0, (%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0x164d
subq %rdi, %rsi
callq 0x1100
movups 0x48(%rsp), %xmm0
movq %rsp, %rax
movups %xmm0, 0x18(%rax)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1670
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
leaq 0x39ec(%rip), %rdi      # 0x5063
leaq 0x39e3(%rip), %rsi      # 0x5061
callq 0x1110
movq %rsp, %rdi
movq %rax, %rsi
callq 0x246c
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
sarq $0x3, %rsi
imulq %r13, %rsi
leaq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x28d2
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x170a
movl $0x1, %r14d
xorl %r12d, %r12d
movq %rsp, %r15
leal -0x1(%r14), %ebp
leaq (%r12,%r12,4), %rcx
leaq (%rax,%rcx,8), %rsi
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2952
movq 0x60(%rsp), %rax
shlq $0x4, %r12
movsd %xmm0, (%rax,%r12)
movl %ebp, 0x8(%rax,%r12)
movl %r14d, %r12d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r13, %rcx
incl %r14d
cmpq %r12, %rcx
ja 0x16c1
movq 0x60(%rsp), %r15
movq 0x68(%rsp), %r12
cmpq %r12, %r15
je 0x1746
movq %r12, %rax
subq %r15, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x378f
movq %r15, %rdi
movq %r12, %rsi
callq 0x3842
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x184d
movl $0x1, %r14d
xorl %r12d, %r12d
movq %rsp, %r15
leaq 0x30(%rsp), %rbp
xorl %r13d, %r13d
movl %r12d, 0x5c(%rsp)
movl %r12d, 0x58(%rsp)
movq 0x60(%rsp), %rcx
shlq $0x4, %r13
movslq 0x8(%rcx,%r13), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rsi
movq %r15, %rdi
leaq 0x5c(%rsp), %rdx
leaq 0x58(%rsp), %rcx
callq 0x2a70
movq 0x60(%rsp), %rax
movslq 0x8(%rax,%r13), %rax
leaq (%rax,%rax,4), %rdx
shlq $0x3, %rdx
addq (%rbx), %rdx
movl 0x5c(%rsp), %ecx
movl 0x58(%rsp), %r8d
movq %rbp, %rdi
movq %r15, %rsi
callq 0x21f0
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movaps 0x30(%rsp), %xmm0
movaps %xmm0, (%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0x17fc
subq %rdi, %rsi
callq 0x1100
leaq 0x48(%rsp), %rax
movups (%rax), %xmm0
movq %rsp, %rax
movups %xmm0, 0x18(%rax)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1822
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movl %r14d, %r13d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rcx
incl %r14d
cmpq %r13, %rcx
ja 0x1767
movq 0x675c(%rip), %rax      # 0x7fb0
movq (%rax), %rsi
movq %rsp, %rdi
callq 0x246c
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x1876
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x188c
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x18a7
jmp 0x18a7
jmp 0x18a7
jmp 0x18a7
jmp 0x18a7
jmp 0x18ac
movq %rax, %rbx
jmp 0x18c6
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x18c6
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x18dc
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rdi
callq 0x11b0