// File: /workspace/github_cpp_makefile_star2_O1/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 0x2e0e
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 0x1a08
movl $0x1, %ecx
movl $0x2, %ebp
leaq 0x48(%rsp), %r13
leaq 0x30(%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 0x21f0
movq 0x90(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movaps 0x30(%rsp), %xmm0
movaps %xmm0, 0x90(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0xa0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0x19bc
subq %rdi, %rsi
callq 0x1100
movupd (%r13), %xmm0
movupd %xmm0, 0x18(%r14)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x19df
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
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 0x195c
leaq 0x30(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x23ce
movq 0x90(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movaps 0x30(%rsp), %xmm0
movaps %xmm0, 0x90(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0xa0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
movabsq $-0x3333333333333333, %r15 # imm = 0xCCCCCCCCCCCCCCCD
je 0x1a6c
subq %rdi, %rsi
callq 0x1100
movupd 0x48(%rsp), %xmm0
movupd %xmm0, 0x18(%r14)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1a8f
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cmpq $0x28, %rax
je 0x1be9
xorl %ebp, %ebp
movl $0x2, 0x8c(%rsp)
xorl %ecx, %ecx
xorl %r13d, %r13d
leal 0x1(%r13), %esi
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r15, %rdx
movq %rsi, 0xc0(%rsp)
cmpq %rsi, %rdx
jbe 0x1bbc
leaq (%rcx,%rcx,4), %r12
movl 0x8c(%rsp), %ecx
movl %ecx, %r14d
movq 0xc0(%rsp), %rcx
leal -0x1(%r14), %r15d
movl %ebp, 0x60(%rsp)
movl %ebp, 0x4(%rsp)
leaq (%rax,%r12,8), %rdi
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x60(%rsp), %rdx
leaq 0x4(%rsp), %rcx
callq 0x2a70
xorpd 0x34ef(%rip), %xmm0     # 0x5020
movl 0x60(%rsp), %eax
movl 0x4(%rsp), %ecx
movlpd %xmm0, 0x30(%rsp)
movl %r13d, 0x38(%rsp)
movl %r15d, 0x3c(%rsp)
movl %eax, 0x40(%rsp)
movl %ecx, 0x44(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x1b82
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x30(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x18(%rsp)
movabsq $-0x3333333333333333, %r15 # imm = 0xCCCCCCCCCCCCCCCD
jmp 0x1b9b
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3ce0
movabsq $-0x3333333333333333, %r15 # imm = 0xCCCCCCCCCCCCCCCD
movl %r14d, %ecx
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r15, %rdx
incl %r14d
cmpq %rcx, %rdx
ja 0x1b02
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
imulq %r15, %rax
decq %rax
incl 0x8c(%rsp)
movq 0xc0(%rsp), %r13
movq %r13, %rcx
cmpq %r13, %rax
ja 0x1ac5
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
cmpq %r15, %r14
je 0x1c33
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 0x3e75
movq %r14, %rdi
movq %r15, %rsi
callq 0x3f34
movq 0x18(%rsp), %rax
cmpq %rax, 0x10(%rsp)
je 0x1e6a
leaq 0x30(%rsp), %r14
leaq 0x4(%rsp), %r12
leaq 0x8(%rsp), %r13
movslq -0x10(%rax), %rcx
movq (%rbx), %rdx
leaq (%rcx,%rcx,4), %r15
movsd 0x18(%rdx,%r15,8), %xmm0
ucomisd 0x33e4(%rip), %xmm0     # 0x5050
jne 0x1c70
jnp 0x1c8a
movslq -0xc(%rax), %rcx
leaq (%rcx,%rcx,4), %rbp
movsd 0x18(%rdx,%rbp,8), %xmm0
ucomisd 0x33ca(%rip), %xmm0     # 0x5050
jne 0x1ca4
jp 0x1ca4
addq $-0x18, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jne 0x1c52
jmp 0x1e6a
movl -0x8(%rax), %ecx
movl -0x4(%rax), %r8d
leaq (%rdx,%r15,8), %rsi
leaq (%rdx,%rbp,8), %rdx
movq %r14, %rdi
callq 0x21f0
xorpd %xmm0, %xmm0
movapd %xmm0, 0x70(%rsp)
movapd %xmm0, 0x60(%rsp)
movq $0x0, 0x80(%rsp)
movq (%rbx), %rax
leaq (%rax,%r15,8), %r15
movq %r15, %rdi
leaq 0x60(%rsp), %rsi
callq 0x2dd6
leaq 0x78(%rsp), %rax
movups (%rax), %xmm0
movups %xmm0, 0x18(%r15)
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x1d0f
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movq $0x0, 0x80(%rsp)
movq (%rbx), %rax
leaq (%rax,%rbp,8), %r15
movq %r15, %rdi
leaq 0x60(%rsp), %rsi
callq 0x2dd6
leaq 0x78(%rsp), %rax
movupd (%rax), %xmm0
movupd %xmm0, 0x18(%r15)
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x1d62
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x1e3f
movl $0x1, %r15d
xorl %ecx, %ecx
leaq (%rcx,%rcx,4), %rcx
movsd 0x18(%rax,%rcx,8), %xmm0
ucomisd 0x32c7(%rip), %xmm0     # 0x5050
jne 0x1d91
jnp 0x1e14
leal -0x1(%r15), %ebp
leaq (%rax,%rcx,8), %rsi
movq %r14, %rdi
movq %r12, %rdx
movq %r13, %rcx
callq 0x2a70
xorpd 0x3271(%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, 0x60(%rsp)
movl %eax, 0x68(%rsp)
movl %ebp, 0x6c(%rsp)
movl %ecx, 0x70(%rsp)
movl %edx, 0x74(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x1e05
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x60(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x18(%rsp)
jmp 0x1e14
leaq 0x10(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0x3ce0
movl %r15d, %ecx
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rsi, %rdx
incl %r15d
cmpq %rcx, %rdx
ja 0x1d77
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2b94
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1c93
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
jmp 0x1c93
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 0x2a70
movl 0x20(%r14), %ebp
movl 0x24(%r14), %r14d
movl %r14d, %eax
imull %ebp, %eax
movslq %eax, %rsi
leaq 0x60(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x3534
leaq 0x60(%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 0x30(%rsp), %rdi
callq 0x21f0
movq 0x60c8(%rip), %rax      # 0x7fb0
movq (%rax), %rsi
leaq 0x30(%rsp), %rdi
callq 0x246c
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1f0c
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x1f23
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1f3a
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x1f57
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
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1f88
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
jmp 0x1f88
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x1fc7
movq 0x70(%rsp), %rsi
jmp 0x1fb5
jmp 0x1fc4
jmp 0x1fbf
jmp 0x1fc4
jmp 0x1fa3
jmp 0x1fc4
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1fc7
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
jmp 0x1fc7
movq %rax, %rbx
jmp 0x1fde
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1fde
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x1ffb
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rdi
callq 0x11b0