// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl $0x64, -0x28(%rbp)
movl -0x8(%rbp), %eax
cmpl -0xc(%rbp), %eax
jle 0x1322e
jmp 0x1324d
leaq 0x1b12e(%rip), %rdi     # 0x2e363
leaq 0x1ad7a(%rip), %rsi     # 0x2dfb6
movl $0x30f, %edx            # imm = 0x30F
leaq 0x1b12d(%rip), %rcx     # 0x2e375
callq 0x21e0
movq -0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x2, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovgl %ecx, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0xc(%rbp), %eax
jle 0x13283
movl -0x30(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x13289
movl -0xc(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x132ce
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jle 0x132c1
jmp 0x132ce
jmp 0x132c3
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x13298
movl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x1330b
movq 0x20d14(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rdx
movq (%rax,%rdx,8), %r8
leaq 0x1b0b4(%rip), %rsi     # 0x2e3b1
leaq 0x1b0ce(%rip), %rdx     # 0x2e3d2
movb $0x0, %al
callq 0x2290
movl -0x34(%rbp), %eax
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x13324
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x13882
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x13383
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x48(%rbp), %rax
jle 0x13376
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x13378
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x13346
cmpl $0x0, -0x24(%rbp)
jle 0x133b7
movq 0x20c68(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
movl -0x38(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rdx
movq (%rax,%rdx,8), %r8
leaq 0x1b03a(%rip), %rsi     # 0x2e3e3
leaq 0x1b022(%rip), %rdx     # 0x2e3d2
movb $0x0, %al
callq 0x2290
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x13463
movl $0x0, -0x68(%rbp)
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cvtsi2sdq (%rax,%rcx,8), %xmm1
movsd 0x1ab42(%rip), %xmm0    # 0x2df28
mulsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
cvtsi2sdq (%rax,%rcx,8), %xmm1
divsd %xmm1, %xmm0
movsd 0x1ab2c(%rip), %xmm1    # 0x2df30
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x64(%rbp)
cmpl $0x64, -0x64(%rbp)
jle 0x13423
movl $0x1, -0x68(%rbp)
movl $0x64, -0x64(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0x13433
cmpl $0x0, -0x64(%rbp)
jne 0x13433
jmp 0x13463
cmpl $0x0, -0x24(%rbp)
jle 0x13453
movl -0x2c(%rbp), %edi
movl -0x64(%rbp), %esi
movl -0x68(%rbp), %edx
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
callq 0x189e0
jmp 0x13455
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x133bd
movl $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x13499
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x13472
cvtsi2sdq -0x78(%rbp), %xmm1
movsd 0x1aa81(%rip), %xmm0    # 0x2df28
mulsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
cvtsi2sdq (%rax,%rcx,8), %xmm1
divsd %xmm1, %xmm0
movsd 0x1aa6b(%rip), %xmm1    # 0x2df30
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x6c(%rbp)
cmpl $0x64, -0x6c(%rbp)
jle 0x134e4
movl $0x1, -0x70(%rbp)
movl $0x64, -0x6c(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x134fe
movl -0x6c(%rbp), %esi
movl -0x70(%rbp), %edx
movq -0x78(%rbp), %rcx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x189e0
movq $-0x1, -0x50(%rbp)
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movl -0x38(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0x13593
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jl 0x13586
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jl 0x13586
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x50(%rbp), %rax
jle 0x13584
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x13586
jmp 0x13588
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x13516
movl -0x3c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0x13640
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x13640
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x135f3
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x60(%rbp), %rax
jge 0x135e6
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
jmp 0x135e8
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x135bc
cvtsi2sdq -0x50(%rbp), %xmm1
cvtsi2sdq -0x48(%rbp), %xmm0
movsd 0x1a931(%rip), %xmm2    # 0x2df38
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
ja 0x1362f
cvtsi2sdq -0x60(%rbp), %xmm0
cvtsi2sdq -0x50(%rbp), %xmm1
movsd 0x1a91b(%rip), %xmm2    # 0x2df40
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1363e
movq $-0x1, -0x50(%rbp)
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
jmp 0x13640
cmpl $0x0, -0x24(%rbp)
jle 0x1369e
cmpq $0x0, -0x50(%rbp)
jle 0x1367d
movq 0x209a4(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
movl -0x3c(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rdx
movq (%rax,%rdx,8), %r8
leaq 0x1ad98(%rip), %rsi     # 0x2e405
leaq 0x1ad5e(%rip), %rdx     # 0x2e3d2
movb $0x0, %al
callq 0x2290
jmp 0x1369c
movq 0x20974(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
leaq 0x1ad96(%rip), %rsi     # 0x2e424
leaq 0x1ad3d(%rip), %rdx     # 0x2e3d2
movb $0x0, %al
callq 0x2290
jmp 0x1369e
movq $-0x1, -0x58(%rbp)
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1373b
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jl 0x1372b
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jl 0x1372b
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x58(%rbp), %rax
jle 0x13729
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x1372b
jmp 0x1372d
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x136b6
movl -0x40(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0x137f8
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x1378f
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x60(%rbp), %rax
jge 0x13782
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
jmp 0x13784
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x13758
cvtsi2sdq -0x58(%rbp), %xmm1
cvtsi2sdq -0x48(%rbp), %xmm0
movsd 0x1a795(%rip), %xmm2    # 0x2df38
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
ja 0x137e7
cvtsi2sdq -0x60(%rbp), %xmm0
cvtsi2sdq -0x58(%rbp), %xmm1
movsd 0x1a77f(%rip), %xmm2    # 0x2df40
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
ja 0x137e7
cvtsi2sdl -0x40(%rbp), %xmm0
cvtsi2sdl -0x38(%rbp), %xmm1
movsd 0x1a76b(%rip), %xmm2    # 0x2df48
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x137f6
movq $-0x1, -0x58(%rbp)
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
jmp 0x137f8
cmpl $0x0, -0x24(%rbp)
jle 0x13856
cmpq $0x0, -0x58(%rbp)
jle 0x13835
movq 0x207ec(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
movl -0x40(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rdx
movq (%rax,%rdx,8), %r8
leaq 0x1ac13(%rip), %rsi     # 0x2e438
leaq 0x1aba6(%rip), %rdx     # 0x2e3d2
movb $0x0, %al
callq 0x2290
jmp 0x13854
movq 0x207bc(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
leaq 0x1ac12(%rip), %rsi     # 0x2e458
leaq 0x1ab85(%rip), %rdx     # 0x2e3d2
movb $0x0, %al
callq 0x2290
jmp 0x13856
cmpl $0x0, -0x40(%rbp)
jle 0x1386d
movl -0x38(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x13882
cmpl $0x0, -0x3c(%rbp)
jle 0x1387c
movl -0x3c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop