// File: /workspace/github_cpp_makefile_star2_O1/leobru[P]ACPUfont/averager.cc
// Function: Picture::find_knee(bool) const
int find_knee(bool upper) const {
        vector<int> pixels = *this;
        if (upper) {
            std::sort(pixels.begin(), pixels.end(), std::greater<int>());
        } else {
            std::sort(pixels.begin(), pixels.end());
        }
        // The background/flush color ends where the normalized histogram derivative
        // is greater than 1 for the first time. 
        int totpix = pixels.size();
        int range = std::abs(pixels.back()-pixels.front());
        int grouplen = totpix/(range+1);
        // We've found the knee when the mean of the current group differs
        // from the mean of the previous group by more than weight.
        double prev = std::accumulate(pixels.begin(), pixels.begin()+grouplen, 0)/(double)grouplen;
        for (int i = 1; i < range; ++i) {
            double cur = std::accumulate(pixels.begin()+i*grouplen, pixels.begin()+(i+1)*grouplen, 0)/(double)grouplen;
            if (upper ? cur < prev-weight : cur > prev+weight) {
                 return prev;
            }
            cur = prev;
        }
        // Nothing interesting found, return the median
        return pixels[totpix/2];
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebx
movq %rdi, %r14
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2e0e
movq (%r15), %r12
movq 0x8(%r15), %r15
testl %ebx, %ebx
je 0x258e
cmpq %r15, %r12
je 0x25c0
movq %r15, %rax
subq %r12, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x2e8e
movq %r12, %rdi
movq %r15, %rsi
callq 0x2f71
jmp 0x25c0
cmpq %r15, %r12
je 0x25c0
movq %r15, %rax
subq %r12, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x31e1
movq %r12, %rdi
movq %r15, %rsi
callq 0x32c4
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
movl -0x4(%rcx), %eax
subq %rdi, %rcx
shrq $0x2, %rcx
subl (%rdi), %eax
movl %eax, %esi
negl %esi
cmovsl %eax, %esi
leal 0x1(%rsi), %r8d
movl %ecx, %eax
cltd
idivl %r8d
movslq %eax, %rdx
testl %edx, %edx
je 0x2610
leaq (,%rdx,4), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
addl (%rdi,%r9), %r10d
addq $0x4, %r9
cmpq %r9, %r8
jne 0x25fc
cvtsi2sd %r10d, %xmm0
jmp 0x2614
xorpd %xmm0, %xmm0
cvtsi2sd %edx, %xmm1
divsd %xmm1, %xmm0
movsd 0x18(%r14), %xmm3
movapd %xmm0, %xmm2
addsd %xmm3, %xmm2
cvttsd2si %xmm0, %ebp
subsd %xmm3, %xmm0
movl %esi, %r8d
movq %r8, 0x8(%rsp)
cmpl $0x1, %esi
adcl $0x0, %esi
leaq (,%rdx,4), %r8
movq %r8, %r9
negq %r9
leaq (%rdi,%rdx,4), %r11
movl $0x1, %r15d
movq %r15, %r14
cmpq %rsi, %r15
je 0x26bd
movl %eax, %r12d
imull %r14d, %r12d
leaq 0x1(%r14), %r15
movl %r15d, %r13d
imull %edx, %r13d
xorpd %xmm3, %xmm3
cmpl %r13d, %r12d
je 0x2699
xorl %r12d, %r12d
xorl %r13d, %r13d
addl (%r11,%r12), %r13d
addq $0x4, %r12
movq %r9, %r10
addq %r12, %r10
jne 0x2681
xorps %xmm3, %xmm3
cvtsi2sd %r13d, %xmm3
divsd %xmm1, %xmm3
movb $0x1, %r12b
testb %bl, %bl
je 0x26ac
ucomisd %xmm3, %xmm0
ja 0x26b2
jmp 0x26b5
ucomisd %xmm2, %xmm3
jbe 0x26b5
xorl %r12d, %r12d
addq %r8, %r11
testb %r12b, %r12b
jne 0x2658
cmpq 0x8(%rsp), %r14
jb 0x26d2
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
cltq
movl (%rdi,%rax,4), %ebp
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x270a
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rdi
callq 0x11b0