// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
subq $0x20, %rsp
movl %esi, %ebx
movq %rdi, %r14
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2e3e
movq (%r15), %r12
movq 0x8(%r15), %r15
testl %ebx, %ebx
je 0x25f4
cmpq %r15, %r12
je 0x2626
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 0x2ebe
movq %r12, %rdi
movq %r15, %rsi
callq 0x2fa1
jmp 0x2626
cmpq %r15, %r12
je 0x2626
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 0x31ed
movq %r12, %rdi
movq %r15, %rsi
callq 0x32d0
movq 0x8(%rsp), %rdi
movq 0x10(%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, %r9
testl %r9d, %r9d
je 0x2677
leaq (,%r9,4), %rdx
xorl %r8d, %r8d
xorl %r10d, %r10d
addl (%rdi,%r8), %r10d
addq $0x4, %r8
cmpq %r8, %rdx
jne 0x2663
cvtsi2sd %r10d, %xmm0
jmp 0x267b
xorpd %xmm0, %xmm0
cmpl $0x2, %esi
jb 0x2710
cvtsi2sd %r9d, %xmm1
divsd %xmm1, %xmm0
movsd 0x18(%r14), %xmm4
movapd %xmm0, %xmm2
addsd %xmm4, %xmm2
movapd %xmm0, %xmm3
subsd %xmm4, %xmm3
movl %esi, %edx
leaq (,%r9,4), %rsi
movq %rsi, %r8
negq %r8
leaq (%rdi,%r9,4), %r9
movl $0x1, %r10d
movl %r10d, %r11d
imull %eax, %r11d
incq %r10
movl %r10d, %ebp
imull %eax, %ebp
xorpd %xmm4, %xmm4
cmpl %r11d, %ebp
je 0x26f2
xorl %r11d, %r11d
xorl %ebp, %ebp
addl (%r9,%r11), %ebp
addq $0x4, %r11
movq %r8, %r14
addq %r11, %r14
jne 0x26db
xorps %xmm4, %xmm4
cvtsi2sd %ebp, %xmm4
divsd %xmm1, %xmm4
testb %bl, %bl
je 0x2702
ucomisd %xmm4, %xmm3
jbe 0x2708
jmp 0x2720
ucomisd %xmm2, %xmm4
ja 0x2720
addq %rsi, %r9
cmpq %rdx, %r10
jne 0x26bd
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
cltq
movl (%rdi,%rax,4), %ebx
jmp 0x2724
cvttsd2si %xmm0, %ebx
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movl %ebx, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x275a
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rdi
callq 0x11b0