// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: get_read_coverage_thres(ma_ug_t*, asg_t*, R_to_U*, unsigned long*, ma_hit_t_alloc*, ma_sub_t*, unsigned long, long long, long long*, long long*)
long long get_read_coverage_thres(ma_ug_t *ug, asg_t *read_g, R_to_U* ruIndex, uint64_t* position_index, 
ma_hit_t_alloc* sources, ma_sub_t* coverage_cut, uint64_t n_read, long long cov_buf_length,
long long* k_mer_only, long long* coverage_only)
{
    uint64_t i, j;
    long long* cov_buf = NULL;
    ma_hit_t *h;
    cov_buf = (long long*)calloc(cov_buf_length, sizeof(long long));
    long long R_bases = 0, C_bases = 0;
    for (i = 0; i < n_read; ++i) 
    {
        C_bases = 0;
        R_bases = coverage_cut[i].e - coverage_cut[i].s;
        for (j = 0; j < (uint64_t)(sources[i].length); j++)
        {
            h = &(sources[i].buffer[j]);
            if(h->el != 1) continue;
            C_bases += Get_qe((*h)) - Get_qs((*h));
        }
        C_bases = C_bases/R_bases;
        if(C_bases < 0 || C_bases >= cov_buf_length) continue;
        cov_buf[C_bases]++;
    }

    long long alter_peak = -1, hom_peak = -1, het_peak = -1;
    if(position_index)
    {
        alter_peak = get_alter_peak(ug, read_g, ruIndex, position_index, sources, coverage_cut, 
        cov_buf_length);
    }
    
    get_read_peak(read_g, cov_buf, cov_buf_length, alter_peak == -1? NULL: &alter_peak, &hom_peak, &het_peak,
    k_mer_only, coverage_only, asm_opt.hg_size);

    free(cov_buf);

    if(hom_peak != -1) return hom_peak*HOM_PEAK_RATE;
    if(het_peak != -1) return het_peak*HET_PEAK_RATE;
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r12
movq %r8, %r13
movq %rcx, %rbp
movq %rdx, 0x20(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movq 0x78(%rsp), %r15
movq 0x70(%rsp), %r14
pushq $0x8
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, %rbx
xorl %ecx, %ecx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
cmpq %r14, %rcx
je 0xc7873
imulq $0xc, %rcx, %rax
movl 0x4(%r12,%rax), %edx
movl (%r12,%rax), %eax
andl %esi, %eax
subl %eax, %edx
imulq $0x18, %rcx, %rax
leaq (%rax,%r13), %rdi
movl 0xc(%r13,%rax), %eax
imulq $0x28, %rax, %r8
xorl %r9d, %r9d
xorl %eax, %eax
cmpq %r9, %r8
je 0xc7851
movq (%rdi), %r10
cmpb $0x1, 0x20(%r10,%r9)
jne 0xc784b
movl 0x8(%r10,%r9), %r11d
subl (%r10,%r9), %r11d
addq %r11, %rax
addq $0x28, %r9
jmp 0xc782f
movl %edx, %edi
cqto
idivq %rdi
testq %rax, %rax
sets %dl
cmpq %r15, %rax
setge %dil
orb %dl, %dil
jne 0xc786e
incq (%rbx,%rax,8)
incq %rcx
jmp 0xc7803
orq $-0x1, 0x30(%rsp)
orq $-0x1, 0x28(%rsp)
orq $-0x1, 0x10(%rsp)
testq %rbp, %rbp
je 0xc78c6
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %r14
movq %r14, %rsi
movq 0x28(%rsp), %rdx
movq %rbp, %rcx
movq %r13, %r8
movq %r12, %r9
pushq %r15
callq 0xc7487
popq %rcx
popq %rdx
leaq 0x30(%rsp), %rdx
movq %rax, (%rdx)
xorl %ecx, %ecx
cmpq $-0x1, %rax
cmovneq %rdx, %rcx
jmp 0xc78cd
xorl %ecx, %ecx
movq 0x8(%rsp), %r14
leaq 0x18be84(%rip), %rax    # 0x253758
subq $0x8, %rsp
leaq 0x30(%rsp), %r12
leaq 0x18(%rsp), %r9
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %r8
pushq 0x200(%rax)
pushq 0x98(%rsp)
pushq 0x98(%rsp)
callq 0xc7103
addq $0x20, %rsp
movq %rbx, %rdi
callq 0x2220
movq (%r12), %rax
cmpq $-0x1, %rax
je 0xc792c
cvtsi2sd %rax, %xmm0
mulsd 0x120336(%rip), %xmm0   # 0x1e7c60
jmp 0xc7944
movq 0x10(%rsp), %rax
cmpq $-0x1, %rax
je 0xc7958
cvtsi2sd %rax, %xmm0
mulsd 0x120344(%rip), %xmm0   # 0x1e7c88
cvttsd2si %xmm0, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x1
popq %rax
jmp 0xc7949