// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x18, %rsp
movq 0x20(%rdi), %r12
movq (%r12), %r14
leaq (,%r14,8), %r15
movq %r15, %rdi
callq 0x32f0
movq %rax, %rbx
movq %rax, %rdi
movl $0xff, %esi
movq %r15, %rdx
callq 0x31b0
xorl %r15d, %r15d
xorl %eax, %eax
movl %eax, %eax
cmpq %rax, %r14
jbe 0x49ab
movq 0x10(%r12), %rdx
imulq $0x28, %rax, %rsi
movl 0x20(%rdx,%rsi), %ecx
btl $0x1e, %ecx
jb 0x49a7
addq %rsi, %rdx
movl 0x18(%rdx), %edx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
addq %rdx, %r15
shlq $0x20, %rcx
orq %rdx, %rcx
movq %rcx, (%rbx,%rax,8)
incl %eax
jmp 0x4973
leaq 0xa3aa(%rip), %rcx      # 0xed5c
pushq $0x8
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x30c0
movq %r15, %xmm0
punpckldq 0x11bc3(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x11bcb(%rip), %xmm0    # 0x165a0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x11acf(%rip), %xmm1    # 0x164b8
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
subsd 0x11ac3(%rip), %xmm1    # 0x164c0
cvttsd2si %xmm1, %rax
andq %rdx, %rax
orq %rcx, %rax
xorl %esi, %esi
xorl %ecx, %ecx
movq %rbx, %r8
xorl %edx, %edx
movl (%r8), %r8d
leaq (%r8,%rsi), %rdi
movl %edx, %r9d
cmpq %rax, %rdi
ja 0x4a37
movl 0x4(%rbx,%r9,8), %esi
imulq %r8, %rsi
addq %rsi, %rcx
incl %edx
leaq (%rbx,%rdx,8), %r8
movq %rdi, %rsi
jmp 0x4a11
movq %rax, %rdx
subq %rsi, %rdx
jbe 0x4a4b
movl 0x4(%rbx,%r9,8), %esi
imulq %rdx, %rsi
addq %rsi, %rcx
movq %rcx, %xmm0
movq 0x11b38(%rip), %xmm1    # 0x16590
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x11b3c(%rip), %xmm2    # 0x165a0
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %rax, %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 0x119f5(%rip), %xmm0    # 0x164a0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq