// File: /workspace/github_c_makefile_star2_O3/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 $0x78, %rsp
movl %r8d, 0x1c(%rsp)
movl %ecx, 0x20(%rsp)
movq %rdx, %rbx
movq %rdi, %r12
movq 0x8(%rdi), %r15
xorl %r13d, %r13d
movl $0x1, %esi
movl $0x20, %edx
xorl %edi, %edi
callq 0x1d660
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rax)
movq (%rbx), %rdx
testq %rdx, %rdx
movq %r12, 0x30(%rsp)
je 0xc20b
xorl %esi, %esi
xorl %r13d, %r13d
movq $0x0, 0x28(%rsp)
movq %rbx, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %r15, 0x38(%rsp)
movq 0x10(%rbx), %rax
movq %rsi, %rcx
shlq $0x5, %rcx
movl 0x8(%rax,%rcx), %r14d
cmpq $0x2, %r14
jb 0xc1ff
movq %rsi, 0x58(%rsp)
addq %rcx, %rax
movq 0x10(%rax), %rbp
movsd 0x18(%rax), %xmm0
leaq 0x70(%rsp), %rdi
callq 0x21a0
movapd %xmm0, %xmm1
cmpltsd 0x1389c(%rip), %xmm1    # 0x1f840
movapd %xmm1, (%rsp)
cmpq %r14, 0x28(%rsp)
jae 0xc004
leaq -0x1(%r14), %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 %r13, %rdi
movq %rsi, 0x28(%rsp)
movapd %xmm0, 0x60(%rsp)
callq 0x2350
movapd 0x60(%rsp), %xmm0
movq %rax, %r13
movapd (%rsp), %xmm2
movapd %xmm2, %xmm3
andnpd %xmm0, %xmm3
movsd 0x1382f(%rip), %xmm1    # 0x1f848
andpd %xmm1, %xmm2
orpd %xmm3, %xmm2
movsd 0x13827(%rip), %xmm0    # 0x1f850
movapd %xmm2, (%rsp)
movq %r13, %rdi
ucomisd %xmm2, %xmm0
jbe 0xc0a4
xorl %esi, %esi
movq %r14, %rdx
callq 0x21e0
xorl %eax, %eax
movq %rax, %rsi
shlq $0x5, %rsi
movq 0x8(%rbp,%rsi), %rcx
movq 0x10(%rbp,%rsi), %rdx
cmpq %rdx, %rcx
ja 0xc09a
movq 0x10(%r15), %rdi
movq (%rbp,%rsi), %rsi
shrq %rsi
leaq (%rsi,%rsi,4), %rsi
movq 0x8(%rdi,%rsi,8), %rsi
movq 0x18(%r12), %rdi
movq (%rsi,%rcx,8), %r8
andq $-0x2, %r8
movq 0x8(%rdi,%r8,4), %r9
subq (%rdi,%r8,4), %r9
cmpq $0x10, %r9
je 0xc094
incq %rcx
cmpq %rdx, %rcx
jbe 0xc073
jmp 0xc09a
movb $0x1, (%r13,%rax)
incq %rax
cmpq %r14, %rax
jne 0xc043
jmp 0xc0b1
movl $0xff, %esi
movq %r14, %rdx
callq 0x21e0
movl $0x1, %r12d
movq %r14, 0x40(%rsp)
leaq -0x1(%r12), %rax
movq %rax, %rcx
shlq $0x5, %rcx
movq (%rbp,%rcx), %rdx
movq %r12, %rcx
shlq $0x5, %rcx
movq (%rbp,%rcx), %rcx
movq 0x28(%r15), %rdi
movq 0x30(%r15), %rsi
movq (%rsi,%rdx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
leaq (%rdi,%rdx), %rsi
cmpq %rcx, 0x8(%rdi,%rdx)
jne 0xc0fd
movq %rsi, %rdx
jmp 0xc10a
leaq 0x30(%rsi), %rdx
cmpq %rcx, 0x38(%rsi)
movq %rdx, %rsi
jne 0xc0fd
xorq (%rdx), %rcx
xorl %ebx, %ebx
cmpq $0x1, %rcx
setne %cl
cmpb $0x0, (%r13,%rax)
je 0xc1df
cmpb $0x0, (%r13,%r12)
je 0xc1df
movq %r13, %r15
movq 0x28(%rdx), %rax
movl 0x20(%rdx), %edx
shrl $0x1f, %edx
leaq (%rdx,%rax,2), %rsi
movb %cl, %bl
xorq %rsi, %rbx
movq 0x10(%rsp), %r13
movq %r13, %rdi
xorl %edx, %edx
leaq 0x24(%rsp), %r14
movq %r14, %rcx
callq 0x8932
cmpl $0x0, 0x24(%rsp)
movq 0x10(%r13), %rcx
movl %eax, %eax
leaq (%rax,%rax,2), %rax
leaq 0x10(%rcx,%rax,8), %rax
je 0xc19a
movaps (%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x8932
movq 0x10(%r13), %rcx
movl %eax, %eax
leaq (%rax,%rax,2), %rax
movapd (%rsp), %xmm0
jmp 0xc1cc
movsd (%rax), %xmm0
addsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x8932
movq 0x10(%r13), %rcx
movl %eax, %eax
leaq (%rax,%rax,2), %rax
movsd 0x10(%rcx,%rax,8), %xmm0
addsd (%rsp), %xmm0
movsd %xmm0, 0x10(%rcx,%rax,8)
movq %r15, %r13
movq 0x38(%rsp), %r15
movq 0x40(%rsp), %r14
incq %r12
cmpq %r14, %r12
jne 0xc0bc
movq 0x30(%rsp), %r12
movq 0x50(%rsp), %rbx
movq 0x48(%rsp), %rdx
movq 0x58(%rsp), %rsi
incq %rsi
cmpq %rdx, %rsi
jne 0xbf62
movq 0x18(%r15), %rcx
testq %rcx, %rcx
je 0xc398
xorl %esi, %esi
movq %rcx, (%rsp)
movq 0x28(%r15), %r10
leaq (%rsi,%rsi,2), %rax
shlq $0x4, %rax
movl 0x20(%r10,%rax), %r11d
btl $0x1e, %r11d
jb 0xc38c
addq %rax, %r10
movq 0x10(%rsp), %rdx
movq 0x10(%rdx), %r14
xorl %eax, %eax
testq %r14, %r14
je 0xc379
movq 0x28(%r10), %rdi
movl %r11d, %r8d
movl (%rdx), %eax
movl $0x1, %r12d
movl %eax, %ecx
shll %cl, %r12d
shrl $0x1f, %r8d
leaq (%r8,%rdi,2), %rbp
movq %rbp, %rcx
notq %rcx
movq %rbp, %rdi
shlq $0x15, %rdi
addq %rcx, %rdi
movq %rdi, %rcx
shrq $0x18, %rcx
xorq %rdi, %rcx
imulq $0x109, %rcx, %rcx      # imm = 0x109
movq %rcx, %rdi
shrq $0xe, %rdi
xorq %rcx, %rdi
leaq (%rdi,%rdi,4), %rcx
leaq (%rdi,%rcx,4), %rcx
movq %rcx, %rdi
shrq $0x1c, %rdi
xorq %rcx, %rdi
movq %rdi, %rcx
movabsq $-0x7fffffff00000000, %r8 # imm = 0x8000000100000000
imulq %r8, %rcx
movabsq $-0xf01bca91, %r8       # imm = 0xFFFFFFFF0FE4356F
xorq %r8, %rcx
shlq $0x35, %rdi
movabsq $0x1e037952000000, %r8  # imm = 0x1E037952000000
addq %r8, %rdi
addq %rcx, %rdi
movq %rdi, %rcx
shrq $0x18, %rcx
xorq %rdi, %rcx
imulq $0x109, %rcx, %rcx      # imm = 0x109
movq %rcx, %rdi
shrq $0xe, %rdi
xorq %rcx, %rdi
leaq (%rdi,%rdi,4), %rcx
leaq (%rdi,%rcx,4), %rcx
movq %rcx, %rdi
shrq $0x1c, %rdi
xorl %ecx, %edi
imull $0x1e3779b9, %edi, %r8d # imm = 0x1E3779B9
movl %eax, %ecx
negb %cl
shrl %cl, %r8d
leal -0x1(%r12), %ecx
movq 0x8(%rdx), %r9
movl %r8d, %edi
movl %edi, %edx
shrl $0x5, %edx
movl (%r9,%rdx,4), %edx
btl %edi, %edx
jae 0xc352
movl %edi, %edx
leaq (%rdx,%rdx,2), %rdx
movq (%r14,%rdx,8), %rbx
xorq %rbp, %rbx
orq 0x8(%r14,%rdx,8), %rbx
je 0xc34f
incl %edi
andl %ecx, %edi
cmpl %r8d, %edi
jne 0xc322
jmp 0xc352
movl %edi, %r12d
movl %r12d, %edx
movl %eax, %ecx
shrl %cl, %edx
testl %edx, %edx
movq (%rsp), %rcx
movl $0x0, %eax
jne 0xc379
movl %r12d, %eax
leaq (%rax,%rax,2), %rax
cvttsd2si 0x10(%r14,%rax,8), %rax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
andl $0x80000000, %r11d      # imm = 0x80000000
orl %eax, %r11d
movl %r11d, 0x20(%r10)
movq 0x30(%rsp), %r12
incq %rsi
cmpq %rcx, %rsi
jne 0xc21e
movq %r13, %rdi
callq 0x2060
movq 0x10(%rsp), %r14
testq %r14, %r14
je 0xc3d1
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rbx
movq %rbx, %rdi
callq 0x1d6fb
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x1d6fb
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1d6fb
cmpl $0x0, 0x20(%rsp)
je 0xc3f2
movq %r12, %rdi
movl 0x1c(%rsp), %esi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc408
movq %r15, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x15c8e