// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]oatk/syncmer.c
// Function: ha_analyze_count
static int ha_analyze_count(int n_cnt, int start_cnt, const int64_t *cnt, int *peak_het, int verbose)
{
    // TODO code review
    const int hist_max = 100;
    int i, start, low_i, max_i, max2_i, max3_i;
    int64_t max, max2, max3, min;

    // determine the start point
    assert(n_cnt > start_cnt);
    *peak_het = -1;
    start = cnt[1] > 0? 1 : 2;

    // find the low point from the left
    low_i = start > start_cnt? start : start_cnt;
    for (i = low_i + 1; i < n_cnt; ++i)
        if (cnt[i] > cnt[i-1])
            break;
    low_i = i - 1;
    if (verbose > 0) fprintf(stderr, "[M::%s] lowest: count[%d] = %ld\n", __func__, low_i, (long)cnt[low_i]);
    if (low_i == n_cnt - 1) return -1; // low coverage

    // find the highest peak
    max_i = low_i + 1, max = cnt[max_i];
    for (i = low_i + 1; i < n_cnt; ++i)
        if (cnt[i] > max)
            max = cnt[i], max_i = i;
    if (verbose > 0) fprintf(stderr, "[M::%s] highest: count[%d] = %ld\n", __func__, max_i, (long)cnt[max_i]);

    // print histogram
    for (i = start; i < n_cnt; ++i) {        
        int x, exceed = 0;
        x = (int)((double)hist_max * cnt[i] / cnt[max_i] + .499);
        if (x > hist_max) exceed = 1, x = hist_max; // may happen if cnt[2] is higher
        if (i > max_i && x == 0) break;
        if (verbose > 0) ha_hist_line(i, x, exceed, cnt[i]);
    }
    {
        int x, exceed = 0;
        int64_t rest = 0;
        for (; i < n_cnt; ++i) rest += cnt[i];
        x = (int)((double)hist_max * rest / cnt[max_i] + .499);
        if (x > hist_max) exceed = 1, x = hist_max;
        if(verbose > 0) ha_hist_line(-1, x, exceed, rest);
    }

    // look for smaller peak on the low end
    max2 = -1; max2_i = -1;
    for (i = max_i - 1; i > low_i; --i)
        if (cnt[i] >= cnt[i-1] && cnt[i] >= cnt[i+1]) 
            if (cnt[i] > max2)
                max2 = cnt[i], max2_i = i;
    if (max2_i > low_i && max2_i < max_i) {
        for (i = max2_i + 1, min = max; i < max_i; ++i)
            if (cnt[i] < min)
                min = cnt[i];
        if (max2 < max * 0.05 || min > max2 * 0.95)
            max2 = -1, max2_i = -1;
    }
    if (verbose > 0) {
        if (max2 > 0)
            fprintf(stderr, "[M::%s] left: count[%d] = %ld\n", __func__, max2_i, (long)cnt[max2_i]);
        else
            fprintf(stderr, "[M::%s] left: none\n", __func__);
    }
    // look for smaller peak on the high end
    max3 = -1; max3_i = -1;
    for (i = max_i + 1; i < n_cnt - 1; ++i)
        if (cnt[i] >= cnt[i-1] && cnt[i] >= cnt[i+1])
            if (cnt[i] > max3)
                max3 = cnt[i], max3_i = i;
    if (max3_i > max_i) {
        for (i = max_i + 1, min = max; i < max3_i; ++i)
            if (cnt[i] < min)
                min = cnt[i];
        if (max3 < max * 0.05 || min > max3 * 0.95 || max3_i > max_i * 2.5)
            max3 = -1, max3_i = -1;
    }
    if (verbose > 0) {
        if (max3 > 0)
            fprintf(stderr, "[M::%s] right: count[%d] = %ld\n", __func__, max3_i, (long)cnt[max3_i]);
        else
            fprintf(stderr, "[M::%s] right: none\n", __func__);
    }
    if (max3_i > 0) {
        *peak_het = max_i;
        return max3_i;
    } else {
        if (max2_i > 0) *peak_het = max2_i;
        return max_i;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r13
orl $-0x1, (%rsi)
movl %edx, %r9d
movq %rdi, %r15
movq 0x8(%rdi), %rbx
pushq $0x6
popq %r14
cmpq $0x3e9, %r14            # imm = 0x3E9
je 0xb3fb
movq (%r15,%r14,8), %rax
cmpq -0x8(%r15,%r14,8), %rax
jg 0xb401
incq %r14
jmp 0xb3e2
movl $0x3e9, %r14d           # imm = 0x3E9
leal -0x1(%r14), %ebp
testl %r9d, %r9d
movl %r9d, 0x4(%rsp)
jg 0xb6f7
cmpl $0x3e8, %ebp            # imm = 0x3E8
jne 0xb424
pushq $-0x1
popq %r14
jmp 0xb6e5
movl %r14d, %eax
movq (%r15,%rax,8), %rbp
movl %r14d, %edx
cmpq $0x3e9, %rax            # imm = 0x3E9
je 0xb449
movq (%r15,%rax,8), %rcx
cmpq %rbp, %rcx
cmovgl %eax, %edx
cmovgq %rcx, %rbp
incq %rax
jmp 0xb42e
movq %rdx, 0x8(%rsp)
movslq %edx, %r12
testl %r9d, %r9d
movq %r13, 0x10(%rsp)
jg 0xb727
xorl %r13d, %r13d
testq %rbx, %rbx
setle %r13b
incq %r13
movsd 0xeb0c(%rip), %xmm2     # 0x19f80
movsd 0xeb0c(%rip), %xmm3     # 0x19f88
pushq $0x64
popq %rbx
cmpq $0x3e9, %r13            # imm = 0x3E9
je 0xb4f0
movq (%r15,%r13,8), %rcx
cvtsi2sd %rcx, %xmm0
mulsd %xmm2, %xmm0
cvtsi2sdq (%r15,%r12,8), %xmm1
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
cvttsd2si %xmm0, %esi
cmpq %r12, %r13
setg %dl
testl %esi, %esi
sete %al
andb %dl, %al
testl %r9d, %r9d
jle 0xb4e7
testb %al, %al
jne 0xb4e7
xorl %edx, %edx
cmpl $0x64, %esi
cmovgel %ebx, %esi
setg %dl
movl %r13d, %edi
callq 0xec46
movsd 0xeab0(%rip), %xmm3     # 0x19f88
movsd 0xeaa0(%rip), %xmm2     # 0x19f80
movl 0x4(%rsp), %r9d
jmp 0xb4eb
testb %al, %al
jne 0xb4f0
incq %r13
jmp 0xb47f
xorl %ecx, %ecx
cmpq $0x3e8, %r13            # imm = 0x3E8
ja 0xb504
addq (%r15,%r13,8), %rcx
incq %r13
jmp 0xb4f2
testl %r9d, %r9d
jle 0xb549
cvtsi2sd %rcx, %xmm0
mulsd 0xea6a(%rip), %xmm0     # 0x19f80
cvtsi2sdq (%r15,%r12,8), %xmm1
divsd %xmm1, %xmm0
addsd 0xea60(%rip), %xmm0     # 0x19f88
cvttsd2si %xmm0, %eax
xorl %edx, %edx
cmpl $0x65, %eax
setge %dl
cmpl $0x64, %eax
cmovll %eax, %ebx
pushq $-0x1
popq %rdi
movl %ebx, %esi
callq 0xec46
movl 0x4(%rsp), %r9d
movslq %r14d, %rcx
pushq $-0x1
popq %rax
pushq $-0x1
popq %r13
movq %r12, %rdx
movq %rdx, %rdi
cmpq %rcx, %rdi
jle 0xb58e
leaq -0x1(%rdi), %rdx
movq -0x8(%r15,%rdi,8), %rsi
cmpq -0x10(%r15,%rdi,8), %rsi
movq %rdx, %rdi
jl 0xb559
cmpq 0x8(%r15,%rdx,8), %rsi
setge %dil
cmpq %rax, %rsi
setg %r8b
testb %r8b, %dil
cmovnel %edx, %r13d
cmovneq %rsi, %rax
jmp 0xb556
movslq %r13d, %rcx
cmpl %r14d, %r13d
jl 0xb5f2
cmpl 0x8(%rsp), %r13d
jge 0xb5f2
leaq 0x1(%rcx), %rsi
movq %rbp, %rdx
cmpq %r12, %rsi
jge 0xb5b9
movq (%r15,%rsi,8), %rdi
cmpq %rdx, %rdi
cmovlq %rdi, %rdx
incq %rsi
jmp 0xb5a4
cvtsi2sd %rax, %xmm0
cvtsi2sd %rbp, %xmm1
mulsd 0xe9c5(%rip), %xmm1     # 0x19f90
ucomisd %xmm0, %xmm1
ja 0xb5e4
cvtsi2sd %rdx, %xmm1
mulsd 0xe9ba(%rip), %xmm0     # 0x19f98
ucomisd %xmm0, %xmm1
jbe 0xb5f2
pushq $-0x1
popq %r13
testl %r9d, %r9d
jle 0xb5fb
jmp 0xb784
testl %r9d, %r9d
jg 0xb757
movq 0x8(%rsp), %rax
incl %eax
movslq %eax, %rcx
pushq $-0x1
popq %rax
pushq $-0x1
popq %rbx
cmpq $0x3e7, %rcx            # imm = 0x3E7
jg 0xb645
movq (%r15,%rcx,8), %rdx
cmpq -0x8(%r15,%rcx,8), %rdx
jl 0xb640
cmpq 0x8(%r15,%rcx,8), %rdx
setge %dil
cmpq %rax, %rdx
setg %r8b
movl %ecx, %esi
testb %r8b, %dil
jne 0xb63b
movl %ebx, %esi
movq %rax, %rdx
movl %esi, %ebx
movq %rdx, %rax
incq %rcx
jmp 0xb60b
movslq %ebx, %rcx
cmpl 0x8(%rsp), %ebx
jle 0xb6be
incq %r12
movq %rbp, %rdx
cmpq %rcx, %r12
jge 0xb669
movq (%r15,%r12,8), %rsi
cmpq %rdx, %rsi
cmovlq %rsi, %rdx
incq %r12
jmp 0xb654
cvtsi2sd %rax, %xmm0
cvtsi2sd %rbp, %xmm1
mulsd 0xe915(%rip), %xmm1     # 0x19f90
ucomisd %xmm0, %xmm1
ja 0xb6ac
cvtsi2sd %rdx, %xmm1
mulsd 0xe90a(%rip), %xmm0     # 0x19f98
ucomisd %xmm0, %xmm1
ja 0xb6ac
cvtsi2sd %ebx, %xmm0
cvtsi2sdl 0x8(%rsp), %xmm1
mulsd 0xe8fa(%rip), %xmm1     # 0x19fa0
ucomisd %xmm1, %xmm0
jbe 0xb6be
testl %r9d, %r9d
movq 0x8(%rsp), %r14
jle 0xb6d8
pushq $-0x1
popq %rbx
jmp 0xb7e1
testl %r9d, %r9d
jg 0xb7ad
movq 0x8(%rsp), %r14
testl %ebx, %ebx
jle 0xb6d8
movl %r14d, %r13d
movl %ebx, %r14d
jmp 0xb6dd
testl %r13d, %r13d
jle 0xb6e5
movq 0x10(%rsp), %rax
movl %r13d, (%rax)
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x158f2(%rip), %rax     # 0x20ff0
movq (%rax), %rdi
movslq %ebp, %rcx
movq (%r15,%rcx,8), %r8
leaq 0xecac(%rip), %rsi      # 0x1a3bb
leaq 0xecc6(%rip), %rdx      # 0x1a3dc
xorl %eax, %eax
callq 0x2280
movl 0x4(%rsp), %r9d
jmp 0xb413
movq 0x158c2(%rip), %rax     # 0x20ff0
movq (%rax), %rdi
movq (%r15,%r12,8), %r8
leaq 0xecb1(%rip), %rsi      # 0x1a3ed
leaq 0xec99(%rip), %rdx      # 0x1a3dc
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2280
movl 0x4(%rsp), %r9d
jmp 0xb45f
testq %rax, %rax
jle 0xb784
movq 0x1588d(%rip), %rax     # 0x20ff0
movq (%rax), %rdi
movq (%r15,%rcx,8), %r8
leaq 0xec9e(%rip), %rsi      # 0x1a40f
leaq 0xec64(%rip), %rdx      # 0x1a3dc
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2280
jmp 0xb7a3
movq 0x15865(%rip), %rax     # 0x20ff0
movq (%rax), %rdi
leaq 0xec99(%rip), %rsi      # 0x1a42e
leaq 0xec40(%rip), %rdx      # 0x1a3dc
xorl %eax, %eax
callq 0x2280
movl 0x4(%rsp), %r9d
jmp 0xb5fb
testq %rax, %rax
movq 0x8(%rsp), %r14
jle 0xb7e1
movq 0x15832(%rip), %rax     # 0x20ff0
movq (%rax), %rdi
movq (%r15,%rcx,8), %r8
leaq 0xec76(%rip), %rsi      # 0x1a442
leaq 0xec09(%rip), %rdx      # 0x1a3dc
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2280
jmp 0xb6cc
movq 0x15808(%rip), %rax     # 0x20ff0
movq (%rax), %rdi
leaq 0xec70(%rip), %rsi      # 0x1a462
leaq 0xebe3(%rip), %rdx      # 0x1a3dc
xorl %eax, %eax
callq 0x2280
jmp 0xb6cc