// File: /workspace/github_cpp_makefile_star2_O3/leobru[P]ACPUfont/averager.cc
// Function: averageSpanningTree(std::vector<Picture, std::allocator<Picture>>&)
void averageSpanningTree(vector<Picture> & pics) {
    Picture mean = pics.front();
    int remaining = pics.size();
    for (uint i = 1; i < pics.size(); ++i) {
        mean = mean.add(pics[i], 0, 0);
    }
    mean = mean.divide();
    vector<std::pair<double, offset> > offsets;
    // Try merging following the min spanning tree of pictures.
    for (uint i = 0; i < pics.size()-1; ++i) {
        for (uint j = i+1; j < pics.size(); ++j) {
            int voff = 0, hoff = 0;
            double best = pics[i].best_offset(pics[j], voff, hoff);
            offsets.push_back(std::make_pair(-best, offset(i, j, voff, hoff)));
        }
    }
    // Sort by negated best; closest pictures are at the end of the array.
    std::sort(offsets.begin(), offsets.end());
    while (!offsets.empty()) {
        offset best = offsets.back().second;
        if (pics[best.what].weight == 0 || pics[best.with].weight == 0) {
            offsets.pop_back();
            continue;
        }
        Picture next = pics[best.what].add(pics[best.with], best.voff, best.hoff);
        pics[best.what] = Picture();
        pics[best.with] = Picture();
        for (uint i = 0; i < pics.size(); ++i) {
            int voff, hoff;
            if (pics[i].weight) {
                double best = next.best_offset(pics[i], voff, hoff);
                offsets.push_back(std::make_pair(-best, offset(pics.size(), i, voff, hoff)));
            }
        }
        pics.push_back(next);
        --remaining;
    }
    // Re-center the result by correlating to the mean
    int voff = 0, hoff = 0;
    mean.best_offset(pics.back(), voff, hoff);
    Picture(mean.width, mean.height).add(pics.back(), voff, hoff).dump(stdout);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
movq (%rdi), %r15
leaq 0x90(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x2e3e
movupd 0x18(%r15), %xmm0
movupd %xmm0, 0x18(%r14)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rcx
cmpq $0x2, %rcx
jb 0x1a8d
movl $0x1, %ecx
movl $0x2, %ebp
leaq 0x28(%rsp), %r13
leaq 0x10(%rsp), %r15
leaq 0x90(%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 0x90(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x90(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0xa0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0x1a58
subq %rdi, %rsi
callq 0x1100
movq 0x10(%rsp), %rdi
movupd (%r13), %xmm0
movupd %xmm0, 0x18(%r14)
testq %rdi, %rdi
je 0x1a64
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
jmp 0x1a64
movupd (%r13), %xmm0
movupd %xmm0, 0x18(%r14)
movl %ebp, %ecx
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rsi, %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0x19d3
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x2426
movq 0x90(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x90(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0xa0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0x1b0c
subq %rdi, %rsi
callq 0x1100
movq 0x10(%rsp), %rdi
movupd 0x28(%rsp), %xmm0
movupd %xmm0, 0x18(%r14)
testq %rdi, %rdi
je 0x1b18
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
jmp 0x1b18
movupd 0x28(%rsp), %xmm0
movupd %xmm0, 0x18(%r14)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
cmpq $0x28, %rdx
je 0x1eb6
xorl %ebp, %ebp
movl $0x2, %r8d
xorl %esi, %esi
xorl %edx, %edx
movl %edx, %r13d
leal 0x1(%r13), %edx
movl %edx, 0x60(%rsp)
movl %edx, %r9d
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rdi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdi, %rdx
cmpq %r9, %rdx
movl %r8d, 0x64(%rsp)
movq %r9, 0xc0(%rsp)
jbe 0x1c47
leaq (%rsi,%rsi,4), %r12
movl %r8d, %r14d
movq %r9, %rsi
leal -0x1(%r14), %r15d
movl %ebp, 0x68(%rsp)
movl %ebp, 0x4(%rsp)
leaq (%rax,%r12,8), %rdi
leaq (%rsi,%rsi,4), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x68(%rsp), %rdx
leaq 0x4(%rsp), %rcx
callq 0x2ac6
xorpd 0x345d(%rip), %xmm0     # 0x5020
movl 0x68(%rsp), %eax
movl 0x4(%rsp), %ecx
movlpd %xmm0, 0x10(%rsp)
movl %r13d, 0x18(%rsp)
movl %r15d, 0x1c(%rsp)
movl %eax, 0x20(%rsp)
movl %ecx, 0x24(%rsp)
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x1c0a
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x10(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x48(%rsp)
jmp 0x1c19
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x3cec
movl %r14d, %esi
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rdi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdi, %rdx
incl %r14d
cmpq %rsi, %rdx
ja 0x1b94
decq %rdx
movl 0x64(%rsp), %r8d
incl %r8d
movq 0xc0(%rsp), %rsi
cmpq %rsi, %rdx
movl 0x60(%rsp), %edx
ja 0x1b4e
movq 0x40(%rsp), %r14
movq 0x48(%rsp), %r15
cmpq %r15, %r14
je 0x1eb6
movq %r15, %rax
subq %r14, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rcx
bsrq %rcx, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x3e81
movq %r14, %rdi
movq %r15, %rsi
callq 0x3f40
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rax
cmpq %rax, %rcx
je 0x1eb6
leaq 0x10(%rsp), %r14
leaq 0x8(%rsp), %r12
movslq -0x10(%rax), %rsi
movq (%rbx), %rdx
leaq (%rsi,%rsi,4), %r13
movsd 0x18(%rdx,%r13,8), %xmm0
ucomisd 0x3364(%rip), %xmm0     # 0x5050
jne 0x1cf0
jnp 0x1d0a
movslq -0xc(%rax), %rsi
leaq (%rsi,%rsi,4), %rbp
movsd 0x18(%rdx,%rbp,8), %xmm0
ucomisd 0x334a(%rip), %xmm0     # 0x5050
jne 0x1d1d
jp 0x1d1d
addq $-0x18, %rax
movq %rax, 0x48(%rsp)
cmpq %rax, %rcx
jne 0x1cd2
jmp 0x1eb6
movl -0x8(%rax), %ecx
movl -0x4(%rax), %r8d
leaq (%rdx,%r13,8), %rsi
leaq (%rdx,%rbp,8), %rdx
movq %r14, %rdi
callq 0x2246
movq (%rbx), %r15
movq (%r15,%r13,8), %rdi
movq 0x10(%r15,%r13,8), %rsi
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15,%r13,8)
movq $0x0, 0x10(%r15,%r13,8)
testq %rdi, %rdi
je 0x1d60
subq %rdi, %rsi
callq 0x1100
leaq (%r15,%r13,8), %rax
xorpd %xmm0, %xmm0
movupd %xmm0, 0x18(%rax)
movq (%rbx), %r15
movq (%r15,%rbp,8), %rdi
movq 0x10(%r15,%rbp,8), %rsi
movupd %xmm0, (%r15,%rbp,8)
movq $0x0, 0x10(%r15,%rbp,8)
testq %rdi, %rdi
je 0x1d95
subq %rdi, %rsi
callq 0x1100
leaq (%r15,%rbp,8), %rax
xorpd %xmm0, %xmm0
movupd %xmm0, 0x18(%rax)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq %rax, %rcx
je 0x1e85
movl $0x1, %ebp
xorl %edx, %edx
leaq (%rdx,%rdx,4), %rdx
movsd 0x18(%rax,%rdx,8), %xmm0
ucomisd 0x3285(%rip), %xmm0     # 0x5050
jne 0x1dd3
jnp 0x1e60
leal -0x1(%rbp), %r15d
leaq (%rax,%rdx,8), %rsi
movq %r14, %rdi
leaq 0x4(%rsp), %rdx
movq %r12, %rcx
callq 0x2ac6
xorpd 0x322d(%rip), %xmm0     # 0x5020
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x3, %rax
imull $0xcccccccd, %eax, %eax # imm = 0xCCCCCCCD
movl 0x4(%rsp), %ecx
movl 0x8(%rsp), %edx
movlpd %xmm0, 0x68(%rsp)
movl %eax, 0x70(%rsp)
movl %r15d, 0x74(%rsp)
movl %ecx, 0x78(%rsp)
movl %edx, 0x7c(%rsp)
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x1e4a
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x68(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x48(%rsp)
jmp 0x1e59
leaq 0x40(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x3cec
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movl %ebp, %edx
movq %rcx, %rsi
subq %rax, %rsi
sarq $0x3, %rsi
movabsq $-0x3333333333333333, %rdi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdi, %rsi
incl %ebp
cmpq %rdx, %rsi
ja 0x1db9
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2bee
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1ea7
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rax
jmp 0x1d13
xorl %eax, %eax
leaq 0x4(%rsp), %rdx
movl %eax, (%rdx)
leaq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movq 0x8(%rbx), %rsi
addq $-0x28, %rsi
leaq 0x90(%rsp), %r14
movq %r14, %rdi
callq 0x2ac6
movl 0x20(%r14), %ebp
movl 0x24(%r14), %r14d
movl %r14d, %eax
imull %ebp, %eax
movslq %eax, %rsi
leaq 0x68(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x351c
leaq 0x68(%rsp), %rsi
movq $0x0, 0x18(%rsi)
movl %ebp, 0x20(%rsi)
movl %r14d, 0x24(%rsi)
movq 0x8(%rbx), %rdx
addq $-0x28, %rdx
movl 0x4(%rsp), %ecx
movl 0x8(%rsp), %r8d
leaq 0x10(%rsp), %rdi
callq 0x2246
movq 0x607c(%rip), %rax      # 0x7fb0
movq (%rax), %rsi
leaq 0x10(%rsp), %rdi
callq 0x24cc
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1f58
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x1f6f
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x1f86
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x1fa3
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2010
jmp 0x1fef
jmp 0x2010
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1fda
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
jmp 0x1fda
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x2013
movq 0x78(%rsp), %rsi
jmp 0x2001
jmp 0x2010
jmp 0x200b
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2013
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
jmp 0x2013
movq %rax, %rbx
jmp 0x202a
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x202a
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x2047
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rdi
callq 0x11b0