// File: /workspace/github_cpp_makefile_star2_O3/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 0x2e3e
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 0x157d
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 0x2246
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 0x154d
subq %rdi, %rsi
callq 0x1100
movq 0x30(%rsp), %rdi
leaq 0x48(%rsp), %rax
movups (%rax), %xmm0
movq %rsp, %rax
movups %xmm0, 0x18(%rax)
testq %rdi, %rdi
je 0x155c
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
jmp 0x155c
leaq 0x48(%rsp), %rax
movups (%rax), %xmm0
movq %rsp, %rax
movups %xmm0, 0x18(%rax)
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 0x14d3
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0x2426
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 0x15e9
subq %rdi, %rsi
callq 0x1100
movq 0x30(%rsp), %rdi
movups 0x48(%rsp), %xmm0
movq %rsp, %rax
movups %xmm0, 0x18(%rax)
testq %rdi, %rdi
je 0x15f5
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
jmp 0x15f5
movups 0x48(%rsp), %xmm0
movq %rsp, %rax
movups %xmm0, 0x18(%rax)
leaq 0x3a5c(%rip), %rdi      # 0x5058
leaq 0x3a5e(%rip), %rsi      # 0x5061
callq 0x1110
movq %rsp, %rdi
movq %rax, %rsi
callq 0x24cc
testb %bpl, %bpl
je 0x16db
movq %rsp, %rdi
xorl %esi, %esi
callq 0x2594
movl %eax, %ebp
movq %rsp, %rdi
movl $0x1, %esi
callq 0x2594
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 0x2762
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 0x16b1
subq %rdi, %rsi
callq 0x1100
movq 0x30(%rsp), %rdi
movups 0x48(%rsp), %xmm0
movq %rsp, %rax
movups %xmm0, 0x18(%rax)
testq %rdi, %rdi
je 0x16bd
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
jmp 0x16bd
movups 0x48(%rsp), %xmm0
movq %rsp, %rax
movups %xmm0, 0x18(%rax)
leaq 0x399f(%rip), %rdi      # 0x5063
leaq 0x3996(%rip), %rsi      # 0x5061
callq 0x1110
movq %rsp, %rdi
movq %rax, %rsi
callq 0x24cc
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
sarq $0x3, %rsi
imulq %r13, %rsi
leaq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x2926
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq %rax, %rcx
je 0x176d
movl $0x1, %r14d
xorl %r13d, %r13d
movabsq $-0x3333333333333333, %r12 # imm = 0xCCCCCCCCCCCCCCCD
leal -0x1(%r14), %ebp
leaq (,%r13,4), %rcx
addq %r13, %rcx
leaq (%rax,%rcx,8), %rsi
movq %rsp, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x29a8
movq 0x60(%rsp), %r15
shlq $0x4, %r13
movsd %xmm0, (%r15,%r13)
movl %ebp, 0x8(%r15,%r13)
movl %r14d, %r13d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
incl %r14d
cmpq %r13, %rdx
ja 0x1718
jmp 0x1772
movq 0x60(%rsp), %r15
movq 0x68(%rsp), %r12
cmpq %r12, %r15
je 0x17b0
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 0x377f
movq %r15, %rdi
movq %r12, %rsi
callq 0x3832
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq %rax, %rcx
je 0x18c4
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 0x2ac6
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 0x2246
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 0x188a
subq %rdi, %rsi
callq 0x1100
movq 0x30(%rsp), %rdi
leaq 0x48(%rsp), %rax
movups (%rax), %xmm0
movq %rsp, %rax
movups %xmm0, 0x18(%rax)
testq %rdi, %rdi
je 0x1899
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
jmp 0x1899
leaq 0x48(%rsp), %rax
movups (%rax), %xmm0
movq %rsp, %rax
movups %xmm0, 0x18(%rax)
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 0x17cd
movq 0x66e5(%rip), %rax      # 0x7fb0
movq (%rax), %rsi
movq %rsp, %rdi
callq 0x24cc
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x18ed
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1903
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 0x191e
jmp 0x191e
jmp 0x191e
jmp 0x191e
jmp 0x191e
jmp 0x1923
movq %rax, %rbx
jmp 0x193d
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x193d
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1953
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rdi
callq 0x11b0