// File: /workspace/github_c_makefile_star2_O1/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
movl %edx, %r11d
movq %rsi, %r12
movq %rdi, %r14
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
movq 0x8(%rdi), %rdx
movl $0x6, %r15d
movq (%r14,%r15,8), %rax
cmpq -0x8(%r14,%r15,8), %rax
jg 0xe0cc
incq %r15
cmpq $0x3e9, %r15            # imm = 0x3E9
jne 0xe0af
movl $0x3e9, %r15d           # imm = 0x3E9
leal -0x1(%r15), %ebx
testl %r11d, %r11d
jg 0xe41a
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x3e8, %ebx            # imm = 0x3E8
je 0xe409
movl %r15d, %eax
movq (%r14,%rax,8), %rbx
cmpl $0x3e8, %r15d           # imm = 0x3E8
movq %r12, 0x10(%rsp)
movl %r15d, %ebp
ja 0xe11b
movq (%r14,%rax,8), %rcx
cmpq %rbx, %rcx
cmovgl %eax, %ebp
cmovgq %rcx, %rbx
incq %rax
cmpq $0x3e9, %rax            # imm = 0x3E9
jne 0xe102
movslq %ebp, %r12
testl %r11d, %r11d
jg 0xe451
xorl %r13d, %r13d
testq %rdx, %rdx
setle %r13b
incq %r13
movsd 0xfdf4(%rip), %xmm2     # 0x1df30
movsd 0xfdf4(%rip), %xmm3     # 0x1df38
movl $0x64, %edi
movq (%r14,%r13,8), %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd %xmm2, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq (%r14,%r12,8), %xmm1
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
cvttsd2si %xmm0, %esi
cmpq %r12, %r13
setg %al
testl %esi, %esi
sete %dl
andb %al, %dl
movzbl %dl, %eax
shll $0x3, %eax
testl %r11d, %r11d
jle 0xe18a
testb %dl, %dl
je 0xe19c
testl %eax, %eax
jne 0xe1d8
incq %r13
cmpq $0x3e9, %r13            # imm = 0x3E9
jne 0xe149
jmp 0xe1d2
xorl %edx, %edx
cmpl $0x64, %esi
cmovgel %edi, %esi
setg %dl
movl %r13d, %edi
movl %r11d, 0x8(%rsp)
callq 0x290f
movl $0x64, %edi
movsd 0xfd77(%rip), %xmm3     # 0x1df38
movsd 0xfd67(%rip), %xmm2     # 0x1df30
movl 0x8(%rsp), %r11d
xorl %eax, %eax
jmp 0xe18a
movl $0x3e9, %r13d           # imm = 0x3E9
cmpl $0x3e8, %r13d           # imm = 0x3E8
ja 0xe1f7
movl %r13d, %eax
xorl %ecx, %ecx
addq (%r14,%rax,8), %rcx
incq %rax
cmpq $0x3e9, %rax            # imm = 0x3E9
jne 0xe1e6
jmp 0xe1f9
xorl %ecx, %ecx
testl %r11d, %r11d
jg 0xe48c
cmpl %r15d, %ebp
jle 0xe258
movslq %r15d, %rcx
leal -0x1(%rbp), %edx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq $-0x1, %rax
movq %r12, %rsi
movq -0x8(%r14,%rsi,8), %rdi
cmpq -0x10(%r14,%rsi,8), %rdi
jl 0xe24c
cmpq (%r14,%rsi,8), %rdi
setge %r9b
cmpq %rax, %rdi
setg %r10b
movl %edx, %r8d
testb %r10b, %r9b
jne 0xe246
movl %r13d, %r8d
movq %rax, %rdi
movl %r8d, %r13d
movq %rdi, %rax
decq %rsi
decl %edx
cmpq %rcx, %rsi
jg 0xe21d
jmp 0xe265
movq $-0x1, %rax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl %r15d, %r13d
jl 0xe2de
movl %ebp, %ecx
subl %r13d, %ecx
jle 0xe2de
leal 0x1(%r13), %esi
movq %rbx, %rdx
cmpl %ebp, %esi
jge 0xe29d
movslq %r13d, %rdx
leaq (%r14,%rdx,8), %rsi
movl $0x1, %edi
movq %rbx, %rdx
movq (%rsi,%rdi,8), %r8
cmpq %rdx, %r8
cmovlq %r8, %rdx
incq %rdi
cmpl %edi, %ecx
jne 0xe28b
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rbx, %xmm1
mulsd 0xfc8b(%rip), %xmm1     # 0x1df40
ucomisd %xmm0, %xmm1
ja 0xe2d1
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
mulsd 0xfc7d(%rip), %xmm0     # 0x1df48
ucomisd %xmm0, %xmm1
jbe 0xe2de
movq $-0x1, %rax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testl %r11d, %r11d
jg 0xe4e0
leal 0x1(%rbp), %ecx
cmpl $0x3e6, %ebp            # imm = 0x3E6
jg 0xe34a
leaq 0x2(%r12), %rdx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq $-0x1, %rax
movl %ecx, %esi
movq -0x8(%r14,%rdx,8), %rdi
cmpq -0x10(%r14,%rdx,8), %rdi
jl 0xe335
cmpq (%r14,%rdx,8), %rdi
setge %r9b
cmpq %rax, %rdi
setg %r10b
movl %esi, %r8d
testb %r10b, %r9b
jne 0xe32f
movl %r15d, %r8d
movq %rax, %rdi
movl %r8d, %r15d
movq %rdi, %rax
movq %rdx, %rdi
incq %rdi
incl %esi
cmpl $0x3e8, %edx            # imm = 0x3E8
movq %rdi, %rdx
jne 0xe306
jmp 0xe357
movq $-0x1, %rax
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %edx
subl %ebp, %edx
jle 0xe3e6
movq %rbx, %rsi
cmpl %r15d, %ecx
jge 0xe388
leaq (%r14,%r12,8), %rcx
movl $0x1, %edi
movq %rbx, %rsi
movq (%rcx,%rdi,8), %r8
cmpq %rsi, %r8
cmovlq %r8, %rsi
incq %rdi
cmpl %edi, %edx
jne 0xe376
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rbx, %xmm1
mulsd 0xfba0(%rip), %xmm1     # 0x1df40
ucomisd %xmm0, %xmm1
ja 0xe3d9
xorps %xmm1, %xmm1
cvtsi2sd %rsi, %xmm1
mulsd 0xfb92(%rip), %xmm0     # 0x1df48
ucomisd %xmm0, %xmm1
ja 0xe3d9
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd 0xfb7d(%rip), %xmm1     # 0x1df50
ucomisd %xmm1, %xmm0
jbe 0xe3e6
movq $-0x1, %rax
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testl %r11d, %r11d
movq 0x10(%rsp), %rbx
jg 0xe510
testl %r15d, %r15d
jle 0xe401
movl %ebp, %r13d
movl %r15d, %ebp
jmp 0xe406
testl %r13d, %r13d
jle 0xe409
movl %r13d, (%rbx)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x15bcf(%rip), %rax     # 0x23ff0
movq (%rax), %rdi
movslq %ebx, %rcx
movq (%r14,%rcx,8), %r8
leaq 0xff41(%rip), %rsi      # 0x1e373
movq %rdx, %r13
leaq 0xff58(%rip), %rdx      # 0x1e394
xorl %eax, %eax
movl %r11d, %ebp
callq 0x2290
movq %r13, %rdx
movl %ebp, %r11d
jmp 0xe0d9
movq 0x15b98(%rip), %rax     # 0x23ff0
movq (%rax), %rdi
movq (%r14,%r12,8), %r8
leaq 0xff3f(%rip), %rsi      # 0x1e3a5
movq %rdx, 0x8(%rsp)
leaq 0xff22(%rip), %rdx      # 0x1e394
movl %r12d, %ecx
xorl %eax, %eax
movl %r11d, %r13d
callq 0x2290
movq 0x8(%rsp), %rdx
movl %r13d, %r11d
jmp 0xe127
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd 0xfa94(%rip), %xmm0     # 0x1df30
movslq %ebp, %rax
xorps %xmm1, %xmm1
cvtsi2sdq (%r14,%rax,8), %xmm1
divsd %xmm1, %xmm0
addsd 0xfa84(%rip), %xmm0     # 0x1df38
cvttsd2si %xmm0, %eax
xorl %edx, %edx
cmpl $0x65, %eax
setge %dl
cmpl $0x64, %eax
movl $0x64, %esi
cmovll %eax, %esi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl %r11d, %r13d
callq 0x290f
movl %r13d, %r11d
jmp 0xe202
movl %r11d, %r15d
movq 0x15b06(%rip), %rcx     # 0x23ff0
movq (%rcx), %rdi
testq %rax, %rax
jle 0xe540
movslq %r13d, %rcx
movq (%r14,%rcx,8), %r8
leaq 0xfec7(%rip), %rsi      # 0x1e3c7
leaq 0xfe8d(%rip), %rdx      # 0x1e394
xorl %eax, %eax
callq 0x2290
jmp 0xe555
movq 0x15ad9(%rip), %rcx     # 0x23ff0
movq (%rcx), %rdi
testq %rax, %rax
jle 0xe55d
movslq %r15d, %rcx
movq (%r14,%rcx,8), %r8
leaq 0xfecd(%rip), %rsi      # 0x1e3fa
leaq 0xfe60(%rip), %rdx      # 0x1e394
xorl %eax, %eax
callq 0x2290
jmp 0xe3f4
leaq 0xfe9f(%rip), %rsi      # 0x1e3e6
leaq 0xfe46(%rip), %rdx      # 0x1e394
xorl %eax, %eax
callq 0x2290
movl %r15d, %r11d
jmp 0xe2e7
leaq 0xfeb6(%rip), %rsi      # 0x1e41a
leaq 0xfe29(%rip), %rdx      # 0x1e394
xorl %eax, %eax
callq 0x2290
jmp 0xe3f4