// File: /workspace/github_c_makefile_star2_O1/c-zhou[P]oatk/path.c
// Function: graph_sequence_coverage_lower_bound
static double graph_sequence_coverage_lower_bound(asg_t *asg, double cov_nq)
{
    uint32_t i, n_seg, len, cov;
    uint64_t *seqcovs, tot_seg_len, tot_cov, len_thresh;
    double cov_bound;
    asmg_t *g;

    g = asg->asmg;
    n_seg = 0;
    tot_seg_len = 0;
    MYMALLOC(seqcovs, g->n_vtx);
    MYBONE(seqcovs, g->n_vtx);
    for (i = 0; i < g->n_vtx; ++i) {
        if (g->vtx[i].del) continue;
        len = g->vtx[i].len;
        cov = g->vtx[i].cov;
        
        ++n_seg;
        tot_seg_len += len;
        seqcovs[i] = (uint64_t) cov << 32 | len;
    }

    qsort(seqcovs, g->n_vtx, sizeof(uint64_t), u64_cmpfunc);
    len_thresh = tot_seg_len * cov_nq;
    i = 0;
    len = (uint32_t) seqcovs[i];
    tot_seg_len = tot_cov = 0;
    while (tot_seg_len + len <= len_thresh) {
        tot_cov += (seqcovs[i] >> 32) * len;
        tot_seg_len += len;
        len = (uint32_t) seqcovs[++i];
    }
    if (tot_seg_len < len_thresh)
        tot_cov += (seqcovs[i] >> 32) * (len_thresh - tot_seg_len);
    cov_bound = (double) tot_cov / len_thresh;
    free(seqcovs);

    cov_bound *= 1 - cov_nq;

#ifdef DEBUG_SEG_COV_BOUND
    fprintf(stderr, "[DEBUG_SEG_COV_BOUND::%s] estimated sequence coverage lower boundary: %.3f\n", __func__, cov_bound);
#endif

    return cov_bound;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq 0x20(%rdi), %r15
movq (%r15), %r14
shlq $0x3, %r14
movq %r14, %rdi
callq 0x32f0
movq %rax, %rbx
movq %rax, %rdi
movl $0xff, %esi
movq %r14, %rdx
callq 0x31b0
movq (%r15), %rsi
testq %rsi, %rsi
je 0x5289
movq 0x10(%r15), %rax
movl $0x1, %ecx
xorl %edi, %edi
xorl %edx, %edx
leaq (%rdi,%rdi,4), %r8
movl 0x20(%rax,%r8,8), %esi
btl $0x1e, %esi
jb 0x5233
leaq (%rax,%r8,8), %r8
movl 0x18(%r8), %r8d
andl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
addq %r8, %rdx
shlq $0x20, %rsi
orq %r8, %rsi
movq %rsi, (%rbx,%rdi,8)
movl %ecx, %edi
movq (%r15), %rsi
incl %ecx
cmpq %rdi, %rsi
ja 0x5208
movq %rdx, %xmm0
punpckldq 0x14344(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1434c(%rip), %xmm0    # 0x195a0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x14248(%rip), %xmm1    # 0x194b0
cvttsd2si %xmm1, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x1423c(%rip), %xmm1    # 0x194b8
cvttsd2si %xmm1, %r14
andq %rcx, %r14
orq %rax, %r14
jmp 0x528c
xorl %r14d, %r14d
leaq 0xb58a(%rip), %rcx      # 0x1081d
movl $0x8, %edx
movq %rbx, %rdi
callq 0x30c0
movl (%rbx), %esi
xorl %ecx, %ecx
cmpq %r14, %rsi
jbe 0x52af
xorl %edx, %edx
xorl %eax, %eax
jmp 0x52d4
movq %rsi, %rdi
xorl %eax, %eax
movq %rsi, %rdx
movl %ecx, %esi
movl 0x4(%rbx,%rsi,8), %esi
imulq %rdi, %rsi
addq %rsi, %rax
incl %ecx
movl (%rbx,%rcx,8), %edi
leaq (%rdi,%rdx), %rsi
cmpq %r14, %rsi
jbe 0x52b4
movl %ecx, %ecx
movq %r14, %rsi
subq %rdx, %rsi
jbe 0x52e7
movl 0x4(%rbx,%rcx,8), %ecx
imulq %rsi, %rcx
addq %rcx, %rax
movq %rax, %xmm0
movq 0x1429c(%rip), %xmm1    # 0x19590
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x142a0(%rip), %xmm2    # 0x195a0
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %r14, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd %xmm1, %xmm3
movapd %xmm3, (%rsp)
movq %rbx, %rdi
callq 0x3060
movapd (%rsp), %xmm0
mulsd 0x14151(%rip), %xmm0    # 0x19498
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq