// File: /workspace/github_c_makefile_star2_O1/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, 0x34(%rsp)
movl %ecx, 0x38(%rsp)
movq %rdx, %rbx
movq %rdi, %r12
movq 0x8(%rdi), %r15
xorl %r13d, %r13d
movl $0x1, %esi
movl $0x20, %edx
xorl %edi, %edi
callq 0x1b528
movq %rax, %rbp
movq $0x0, 0x18(%rax)
movq %rbx, 0x78(%rsp)
movq (%rbx), %rdx
testq %rdx, %rdx
movq %r12, 0x28(%rsp)
movq %rax, 0x8(%rsp)
je 0xb88f
xorl %esi, %esi
xorl %r13d, %r13d
movq $0x0, 0x40(%rsp)
movq %rdx, 0x68(%rsp)
movq %r15, 0x48(%rsp)
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq %rsi, %rcx
shlq $0x5, %rcx
movl 0x8(%rax,%rcx), %r14d
cmpq $0x2, %r14
jb 0xb883
movq %rsi, 0x70(%rsp)
addq %rcx, %rax
movq 0x10(%rax), %rbp
movsd 0x18(%rax), %xmm0
leaq 0x80(%rsp), %rdi
callq 0x21a0
movapd %xmm0, %xmm1
cmpltsd 0x121c8(%rip), %xmm1    # 0x1d7c8
movapd %xmm1, 0x10(%rsp)
cmpq %r14, 0x40(%rsp)
jae 0xb661
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, 0x40(%rsp)
movapd %xmm0, 0x50(%rsp)
callq 0x2360
movapd 0x50(%rsp), %xmm0
movq %rax, %r13
movapd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm3
andnpd %xmm0, %xmm3
movsd 0x12159(%rip), %xmm1    # 0x1d7d0
andpd %xmm1, %xmm2
orpd %xmm3, %xmm2
movsd 0x12151(%rip), %xmm0    # 0x1d7d8
movapd %xmm2, 0x10(%rsp)
movq %r13, %rdi
ucomisd %xmm2, %xmm0
jbe 0xb70e
xorl %esi, %esi
movq %r14, %rdx
callq 0x21e0
cmpq $0x1, %r14
movq %r14, %rax
adcq $0x0, %rax
xorl %ecx, %ecx
movq %rcx, %rdi
shlq $0x5, %rdi
movq 0x8(%rbp,%rdi), %rdx
movq 0x10(%rbp,%rdi), %rsi
cmpq %rsi, %rdx
ja 0xb704
movq 0x10(%r15), %r8
movq (%rbp,%rdi), %rdi
shrq %rdi
leaq (%rdi,%rdi,4), %rdi
movq 0x8(%r8,%rdi,8), %rdi
movq 0x18(%r12), %r8
movq (%rdi,%rdx,8), %r9
andq $-0x2, %r9
movq 0x8(%r8,%r9,4), %r10
subq (%r8,%r9,4), %r10
cmpq $0x10, %r10
je 0xb6fe
incq %rdx
cmpq %rsi, %rdx
jbe 0xb6dd
jmp 0xb704
movb $0x1, (%r13,%rcx)
incq %rcx
cmpq %rax, %rcx
jne 0xb6ad
jmp 0xb71b
movl $0xff, %esi
movq %r14, %rdx
callq 0x21e0
cmpq $0x3, %r14
movl $0x2, %eax
cmovbq %rax, %r14
movl $0x1, %r12d
movq %r14, 0x50(%rsp)
leaq -0x1(%r12), %rax
movq %rax, %rcx
shlq $0x5, %rcx
movq (%rbp,%rcx), %rcx
movq %r12, %rdx
shlq $0x5, %rdx
movq (%rbp,%rdx), %rdx
movq 0x28(%r15), %rdi
movq 0x30(%r15), %rsi
movq (%rsi,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
leaq (%rdi,%rcx), %rsi
cmpq %rdx, 0x8(%rdi,%rcx)
jne 0xb774
movq %rsi, %rcx
jmp 0xb781
leaq 0x30(%rsi), %rcx
cmpq %rdx, 0x38(%rsi)
movq %rcx, %rsi
jne 0xb774
movq 0x8(%rcx), %rdx
xorq (%rcx), %rdx
xorl %ebx, %ebx
cmpq $0x1, %rdx
setne %dl
cmpb $0x0, (%r13,%rax)
je 0xb863
cmpb $0x0, (%r13,%r12)
je 0xb863
movq %r13, %r15
movq 0x28(%rcx), %rax
movl 0x20(%rcx), %ecx
shrl $0x1f, %ecx
leaq (%rcx,%rax,2), %rsi
movb %dl, %bl
xorq %rsi, %rbx
movq 0x8(%rsp), %r13
movq %r13, %rdi
xorl %edx, %edx
leaq 0x3c(%rsp), %r14
movq %r14, %rcx
callq 0x84df
cmpl $0x0, 0x3c(%rsp)
movl %eax, %eax
leaq (%rax,%rax,2), %rax
je 0xb814
movq 0x10(%r13), %rcx
movaps 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rcx,%rax,8)
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x84df
movq 0x10(%r13), %rcx
movl %eax, %eax
leaq (%rax,%rax,2), %rax
movapd 0x10(%rsp), %xmm0
jmp 0xb850
movq 0x10(%r13), %rcx
movsd 0x10(%rcx,%rax,8), %xmm0
addsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rcx,%rax,8)
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x84df
movq 0x10(%r13), %rcx
movl %eax, %eax
leaq (%rax,%rax,2), %rax
movsd 0x10(%rcx,%rax,8), %xmm0
addsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rcx,%rax,8)
movq %r15, %r13
movq 0x48(%rsp), %r15
movq 0x50(%rsp), %r14
incq %r12
cmpq %r14, %r12
jne 0xb733
movq 0x28(%rsp), %r12
movq 0x8(%rsp), %rbp
movq 0x68(%rsp), %rdx
movq 0x70(%rsp), %rsi
incq %rsi
cmpq %rdx, %rsi
jne 0xb5b6
movq 0x18(%r15), %rsi
testq %rsi, %rsi
je 0xba26
xorl %edx, %edx
movq %rsi, 0x10(%rsp)
movq 0x28(%r15), %r9
leaq (%rdx,%rdx,2), %rcx
shlq $0x4, %rcx
movl 0x20(%r9,%rcx), %r10d
btl $0x1e, %r10d
jb 0xba1a
addq %rcx, %r9
movq 0x10(%rbp), %r11
xorl %ebx, %ebx
movl $0x0, %r14d
testq %r11, %r11
je 0xb9e2
movq 0x28(%r9), %rcx
movl %r10d, %esi
shrl $0x1f, %esi
leaq (%rsi,%rcx,2), %r12
movb (%rbp), %cl
movl $0x1, %r14d
shll %cl, %r14d
movq %r12, %rsi
notq %rsi
movq %r12, %rdi
shlq $0x15, %rdi
addq %rsi, %rdi
movq %rdi, %rsi
shrq $0x18, %rsi
xorq %rdi, %rsi
imulq $0x109, %rsi, %rsi      # imm = 0x109
movq %rsi, %rdi
shrq $0xe, %rdi
xorq %rsi, %rdi
leaq (%rdi,%rdi,4), %rsi
leaq (%rdi,%rsi,4), %rsi
movq %rsi, %rdi
shrq $0x1c, %rdi
xorq %rsi, %rdi
movq %rdi, %rsi
movabsq $-0x7fffffff00000000, %rax # imm = 0x8000000100000000
imulq %rax, %rsi
movabsq $-0xf01bca91, %rax      # imm = 0xFFFFFFFF0FE4356F
xorq %rax, %rsi
shlq $0x35, %rdi
movabsq $0x1e037952000000, %rax # imm = 0x1E037952000000
addq %rax, %rdi
addq %rsi, %rdi
movq %rdi, %rsi
shrq $0x18, %rsi
xorq %rdi, %rsi
imulq $0x109, %rsi, %rsi      # imm = 0x109
movq %rsi, %rdi
shrq $0xe, %rdi
xorq %rsi, %rdi
leaq (%rdi,%rdi,4), %rsi
leaq (%rdi,%rsi,4), %rsi
movq %rsi, %rdi
shrq $0x1c, %rdi
xorl %esi, %edi
imull $0x1e3779b9, %edi, %esi # imm = 0x1E3779B9
negb %cl
shrl %cl, %esi
leal -0x1(%r14), %ecx
movq 0x8(%rbp), %rdi
movl %esi, %ebp
movl %ebp, %r8d
shrl $0x5, %r8d
movl (%rdi,%r8,4), %r8d
btl %ebp, %r8d
jae 0xb9d3
movl %ebp, %r8d
leaq (%r8,%r8,2), %r8
movq (%r11,%r8,8), %rax
xorq %r12, %rax
orq 0x8(%r11,%r8,8), %rax
je 0xb9d0
incl %ebp
andl %ecx, %ebp
cmpl %esi, %ebp
jne 0xb9a0
jmp 0xb9d3
movl %ebp, %r14d
movq 0x28(%rsp), %r12
movq 0x8(%rsp), %rbp
movq 0x10(%rsp), %rsi
testq %r11, %r11
je 0xb9f1
movb (%rbp), %cl
movl $0x1, %ebx
shll %cl, %ebx
xorl %ecx, %ecx
cmpl %ebx, %r14d
jae 0xba0c
movl %r14d, %eax
leaq (%rax,%rax,2), %rax
cvttsd2si 0x10(%r11,%rax,8), %rcx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl $0x80000000, %r10d      # imm = 0x80000000
orl %ecx, %r10d
movl %r10d, 0x20(%r9)
incq %rdx
cmpq %rsi, %rdx
jne 0xb8a3
movq %r13, %rdi
callq 0x2060
testq %rbp, %rbp
je 0xba5a
movq 0x10(%rbp), %rsi
movq 0x18(%rbp), %rbx
movq %rbx, %rdi
callq 0x1b5ca
movq 0x8(%rbp), %rsi
movq %rbx, %rdi
callq 0x1b5ca
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1b5ca
cmpl $0x0, 0x38(%rsp)
je 0xba7e
movq %r12, %rdi
movl 0x34(%rsp), %esi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xba97
movq %r15, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x151bf