// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]oatk/syncasm.c
// Function: scg_ra_arc_coverage
void scg_ra_arc_coverage(scg_t *g, sr_db_t *sr_db, scg_ra_v *ra_v, int refine, int verbose)
{
    uint64_t i, j, n, m, s, l0, c0, *a;
    asmg_t *utg_g;
    asmg_arc_t *arc;
    double score, intpart;
    kh_dbl_t *dup_s; // spanning duplets
    khint_t k;
    kvec_t(uint8_t) uniq;
    ra_frg_t *ra;
    int absent;
    
    utg_g = g->utg_asmg;

    dup_s = kh_dbl_init();
    kv_init(uniq);
    for (i = 0, n = ra_v->n; i < n; ++i) {
        m = ra_v->a[i].n;
        if (m < 2)
            continue;
        ra = ra_v->a[i].a;
        score = modf(ra_v->a[i].s, &intpart);
        if (score < DBL_EPSILON)
            score = 1.0;

        if (m > uniq.m)
            kv_resize(uint8_t, uniq, m);
        if (score < .99) { // score < 1.0
            // read was not uniquely mapped
            MYBZERO(uniq.a, m);
            for (j = 0; j < m; ++j) {
                a = utg_g->vtx[ra[j].uid>>1].a;
                for (s = ra[j].u_beg; s <= ra[j].u_end; ++s) {
                    if (scm_utg_n(g, a[s]>>1) == 1) {
                        // find a unique syncmer in the alignment
                        uniq.a[j] = 1;
                        break;
                    }
                }
            }
        } else {
            // no need to check one by one
            MYBONE(uniq.a, m);
        }

        for (j = 1; j < m; ++j) {
            arc = asmg_arc(utg_g, ra[j-1].uid, ra[j].uid);
            l0 = asmg_arc_id(*arc);
            c0 = asmg_comp_arc_id(arc);
            if (uniq.a[j-1] && uniq.a[j]) {
                k = kh_dbl_put(dup_s, (uint128_t) l0, &absent);
                if (absent) {
                    kh_val(dup_s, k) = score;
                    k = kh_dbl_put(dup_s, (uint128_t) c0, &absent);
                    kh_val(dup_s, k) = score;
                } else {
                    kh_val(dup_s, k) += score;
                    k = kh_dbl_put(dup_s, (uint128_t) c0, &absent);
                    kh_val(dup_s, k) += score;
                }
            }
        }
    }
    
    for (i = 0, n = utg_g->n_arc; i < n; ++i) {
        arc = &utg_g->arc[i];
        if (arc->del) continue;
        l0 = asmg_arc_id(*arc);
        k = kh_dbl_get(dup_s, l0);
        score = k < kh_end(dup_s)? kh_val(dup_s, k) : 0;
        arc->cov = (uint32_t) score;
    }

    kv_destroy(uniq);
    kh_dbl_destroy(dup_s);

    if (refine)
        scg_refine_arc_coverage(g, verbose);
    else
        asmg_arc_fix_cov(utg_g);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %r8d, 0x24(%rsp)
movl %ecx, 0x28(%rsp)
movq %rdx, %rbx
movq %rdi, %r14
movq 0x8(%rdi), %rax
movq %rax, 0x10(%rsp)
callq 0x65fb
movq %rax, 0x18(%rsp)
movq (%rbx), %rdx
movq $0x0, 0x48(%rsp)
movq $0x0, 0x8(%rsp)
xorl %esi, %esi
movq %rbx, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
cmpq %rdx, %rsi
je 0x93c6
movq 0x10(%rbx), %rax
movq %rsi, %rcx
shlq $0x5, %rcx
movl 0x8(%rax,%rcx), %r13d
cmpq $0x2, %r13
jb 0x93be
movq %rsi, 0x60(%rsp)
addq %rcx, %rax
movq 0x10(%rax), %r15
movsd 0x18(%rax), %xmm0
leaq 0x80(%rsp), %rdi
callq 0x21a0
movapd %xmm0, %xmm1
cmpltsd 0x10637(%rip), %xmm1    # 0x197c8
movapd %xmm1, 0x30(%rsp)
cmpq %r13, 0x48(%rsp)
jae 0x91f6
leaq -0x1(%r13), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq 0x8(%rsp), %rdi
movq %rsi, 0x48(%rsp)
movapd %xmm0, 0x70(%rsp)
callq 0x2350
movapd 0x70(%rsp), %xmm0
movq %rax, 0x8(%rsp)
movapd 0x30(%rsp), %xmm2
movapd %xmm2, %xmm3
andnpd %xmm0, %xmm3
movsd 0x105c4(%rip), %xmm1    # 0x197d0
andpd %xmm1, %xmm2
orpd %xmm3, %xmm2
movsd 0x105bc(%rip), %xmm0    # 0x197d8
movapd %xmm2, 0x30(%rsp)
ucomisd %xmm2, %xmm0
jbe 0x9299
movq 0x8(%rsp), %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x21e0
xorl %eax, %eax
cmpq %r13, %rax
je 0x92ab
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rdx
movq %rax, %rsi
shlq $0x5, %rsi
movq (%r15,%rsi), %rdi
movq 0x8(%r15,%rsi), %rcx
shrq %rdi
imulq $0x28, %rdi, %rdi
movq 0x8(%rdx,%rdi), %rdx
movq 0x10(%r15,%rsi), %rsi
cmpq %rsi, %rcx
ja 0x9294
movq 0x18(%r14), %rdi
movq (%rdx,%rcx,8), %r8
andq $-0x2, %r8
movq 0x8(%rdi,%r8,4), %r9
subq (%rdi,%r8,4), %r9
incq %rcx
cmpq $0x10, %r9
jne 0x9268
movq 0x8(%rsp), %rcx
movb $0x1, (%rcx,%rax)
incq %rax
jmp 0x9239
movq 0x8(%rsp), %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x21e0
addq $0x20, %r15
pushq $0x1
popq %r12
movq %r13, 0x68(%rsp)
cmpq %r13, %r12
jae 0x93af
movq -0x20(%r15), %rsi
movq (%r15), %rdx
movq 0x10(%rsp), %rdi
callq 0x5336
movq 0x28(%rax), %r13
movl 0x20(%rax), %ebx
movq %rax, %rdi
callq 0x6610
movq %rax, %rbp
movq 0x8(%rsp), %rax
cmpb $0x0, -0x1(%rax,%r12)
je 0x939e
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax,%r12)
je 0x939e
shrl $0x1f, %ebx
leaq (%rbx,%r13,2), %rsi
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
xorl %edx, %edx
leaq 0x2c(%rsp), %r13
movq %r13, %rcx
callq 0x6632
movl %eax, %eax
imulq $0x18, %rax, %rax
cmpl $0x0, 0x2c(%rsp)
movq 0x10(%rbx), %rcx
leaq 0x10(%rcx,%rax), %rax
je 0x9364
movaps 0x30(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %rbx, %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x6632
movq 0x10(%rbx), %rcx
movl %eax, %eax
imulq $0x18, %rax, %rax
movapd 0x30(%rsp), %xmm0
jmp 0x9398
movsd (%rax), %xmm0
addsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %rbx, %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x6632
movq 0x10(%rbx), %rcx
movl %eax, %eax
imulq $0x18, %rax, %rax
movsd 0x10(%rcx,%rax), %xmm0
addsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x10(%rcx,%rax)
incq %r12
addq $0x20, %r15
movq 0x68(%rsp), %r13
jmp 0x92b8
movq 0x58(%rsp), %rbx
movq 0x50(%rsp), %rdx
movq 0x60(%rsp), %rsi
incq %rsi
jmp 0x9143
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rbx
pushq $0x20
popq %r15
movq 0x18(%rsp), %r13
subq $0x1, %rbx
jb 0x944c
movq 0x10(%rsp), %rax
movq 0x28(%rax), %r12
movl (%r12,%r15), %ebp
btl $0x1e, %ebp
jb 0x9446
movq 0x8(%r12,%r15), %rax
movl %ebp, %ecx
shrl $0x1f, %ecx
leaq (%rcx,%rax,2), %rsi
movq %r13, %rdi
xorl %edx, %edx
callq 0x69fa
movq 0x10(%r13), %rdx
testq %rdx, %rdx
je 0x9438
movb (%r13), %cl
movl %eax, %esi
shrl %cl, %esi
testl %esi, %esi
movl $0x0, %ecx
jne 0x943a
movl %eax, %eax
imulq $0x18, %rax, %rax
cvttsd2si 0x10(%rdx,%rax), %rcx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
jmp 0x943a
xorl %ecx, %ecx
andl $0x80000000, %ebp       # imm = 0x80000000
orl %ecx, %ebp
movl %ebp, (%r12,%r15)
addq $0x30, %r15
jmp 0x93d8
movq 0x8(%rsp), %rdi
callq 0x2060
movq 0x18(%rsp), %rdi
callq 0x6ac2
cmpl $0x0, 0x28(%rsp)
je 0x9484
movq %r14, %rdi
movl 0x24(%rsp), %esi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x949f
movq 0x10(%rsp), %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x120cb