// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0x8, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, %rbx
testq %r14, %r14
je 0x109fad
xorl %ecx, %ecx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leaq (%rcx,%rcx,2), %rdx
movl 0xc(%r13,%rdx,8), %eax
testq %rax, %rax
je 0x109f7b
leaq (,%rdx,8), %rdi
addq %r13, %rdi
movq (%rdi), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,4), %r8
xorl %r9d, %r9d
xorl %eax, %eax
cmpb $0x1, 0x20(%rdi,%r9)
jne 0x109f70
movl 0x8(%rdi,%r9), %r10d
subl (%rdi,%r9), %r10d
addq %r10, %rax
addq $0x28, %r9
cmpq %r9, %r8
jne 0x109f5c
jmp 0x109f7d
xorl %eax, %eax
movl 0x4(%r12,%rdx,4), %edi
movl (%r12,%rdx,4), %edx
andl %esi, %edx
subl %edx, %edi
cqto
idivq %rdi
testq %rax, %rax
sets %dl
cmpq %r15, %rax
setge %dil
orb %dl, %dil
jne 0x109fa5
incq (%rbx,%rax,8)
incq %rcx
cmpq %r14, %rcx
jne 0x109f33
movq 0x88(%rsp), %r11
movq 0x80(%rsp), %r10
movq $-0x1, %rax
movq %rax, 0x30(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, 0x10(%rsp)
testq %rbp, %rbp
je 0x10a025
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
movq %r10, %r12
movq %r11, %r13
callq 0x109b8a
movq %r13, %r11
movq %r12, %r10
movq %r14, %rdi
addq $0x10, %rsp
leaq 0x30(%rsp), %rdx
movq %rax, (%rdx)
xorl %ecx, %ecx
cmpq $-0x1, %rax
cmovneq %rdx, %rcx
jmp 0x10a02c
xorl %ecx, %ecx
movq 0x8(%rsp), %rdi
leaq 0x18b725(%rip), %rax    # 0x295758
subq $0x8, %rsp
leaq 0x30(%rsp), %r12
leaq 0x18(%rsp), %r9
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %r8
pushq 0x200(%rax)
pushq %r11
pushq %r10
callq 0x109743
addq $0x20, %rsp
movq %rbx, %rdi
callq 0x2220
movq (%r12), %rax
cmpq $-0x1, %rax
je 0x10a07e
cvtsi2sd %rax, %xmm0
mulsd 0x12bce4(%rip), %xmm0   # 0x235d60
jmp 0x10a096
movq 0x10(%rsp), %rax
cmpq $-0x1, %rax
je 0x10a0aa
cvtsi2sd %rax, %xmm0
mulsd 0x12bcf2(%rip), %xmm0   # 0x235d88
cvttsd2si %xmm0, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $-0x1, %rax
jmp 0x10a09b