// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]oatk/syncasm.c
// Function: scg_refine_arc_coverage
void scg_refine_arc_coverage(scg_t *g, int verbose)
{
    // update arc coverage on graph
    // the arc coverage on the input graph is the number of syncmer pair links in the read set
    // need to check if there are other pair links on the graph
    // if yes, calculate weighted arc coverage by utg coverge
    
    uint64_t i, j, n, m, p, v, w, c, nl, ld, *a;
    asmg_t *utg_g;
    asmg_arc_t *arc;
    u64_v_t *link_pairs, *pair;
    khint_t k;
    kh_u128_t *h_arc;
    int absent;

    utg_g = g->utg_asmg;
    h_arc = kh_u128_init();
    nl = asmg_max_link_id(utg_g) + 1; // number of links
    MYCALLOC(link_pairs, nl);
    // add arcs
    for (i = 0, n = utg_g->n_arc; i < n; ++i) {
        arc = &utg_g->arc[i];
        if (arc->del || arc->comp) continue;
        v = asmg_arc_head_e(utg_g, arc);
        w = asmg_arc_tail_e(utg_g, arc);
        if (v > w) {
            v ^= 1;
            w ^= 1;
            SWAP(v, w);
        }
        ld = arc->link_id;
        // add arc
        k = kh_u128_put(h_arc, (uint128_t) v << 64 | w, &absent);
        // only update if absent
        // for (v,w) with multiple link ids
        // all pack in the first link
        if (absent)
            kh_val(h_arc, k) = ld;
        else
            ld = kh_val(h_arc, k);
        kv_push(uint64_t, link_pairs[ld], arc->link_id);
        kv_push(uint64_t, link_pairs[ld], ((uint64_t) 
                    utg_g->vtx[arc->v >> 1].cov + 
                    utg_g->vtx[arc->w >> 1].cov) / 2);
    }
    // check utgs
    for (i = 0, n = utg_g->n_vtx; i < n; ++i) {
        a = utg_g->vtx[i].a;
        for (j = 1, m = utg_g->vtx[i].n; j < m; ++j) {
            v = a[j - 1];
            w = a[j];
            if (v > w) {
                v ^= 1;
                w ^= 1;
                SWAP(v, w);
            }
            k = kh_u128_get(h_arc, (uint128_t) v << 64 | w);
            if (k == kh_end(h_arc)) continue;
            ld = kh_val(h_arc, k);
            kv_push(uint64_t, link_pairs[ld], UINT64_MAX);
            kv_push(uint64_t, link_pairs[ld], utg_g->vtx[i].cov);
        } 
    }
    // update arc covs on graph
    for (i = 0, n = utg_g->n_arc; i < n; ++i) {
        arc = &utg_g->arc[i];
        if (arc->del || arc->comp) continue;
        v = asmg_arc_head_e(utg_g, arc);
        w = asmg_arc_tail_e(utg_g, arc);
        if (v > w) {
            v ^= 1;
            w ^= 1;
            SWAP(v, w);
        }
        k = kh_u128_get(h_arc, (uint128_t) v << 64 | w);
        ld = kh_val(h_arc, k);
        pair = &link_pairs[ld];
        if (pair->n == 2) {
            assert(pair->a[0] == ld);
            continue; // no need to update
        }
        // find the pair and total cov
        c = 0;
        p = UINT64_MAX;
        for (j = 1, m = pair->n; j < m; j += 2) {
            if (pair->a[j - 1] == arc->link_id)
                p = j;
            c += pair->a[j];
        }
        if (c == 0) continue;
        assert(p < m);
        c = lround((double) arc->cov / c * pair->a[p]);
        // c = MIN(c, utg_g->vtx[arc->v >> 1].cov);
        // c = MIN(c, utg_g->vtx[arc->w >> 1].cov);
        if (verbose > 2)
            fprintf(stderr, "[M::%s] arc u%lu%c -> u%lu%c coverage updated: %u -> %lu\n", 
                    __func__, arc->v>>1, "+-"[arc->v&1], arc->w>>1, "+-"[arc->w&1], arc->cov, c);
        arc->cov = c;

        // for reverse complementary arcs
        arc = asmg_comp_arc1(utg_g, arc);
        if (arc) arc->cov = c;
    }

    // fix arc coverage
    // bounded by the minimum utg cov
    asmg_arc_fix_cov(utg_g);
    
    for (i = 0; i < nl; ++i)
        free(link_pairs[i].a);
    free(link_pairs);
    kh_u128_destroy(h_arc);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, 0x28(%rsp)
movq 0x8(%rdi), %r14
movl $0x1, %esi
movl $0x20, %edx
xorl %edi, %edi
callq 0x1d660
movq %rax, %rbx
movq $0x0, 0x18(%rax)
movq %r14, %rdi
callq 0x15bd6
incq %rax
movl $0x18, %esi
movq %rax, 0x30(%rsp)
movq %rax, %rdi
callq 0x2250
movq %rax, 0x18(%rsp)
movq %r14, 0x8(%rsp)
movq 0x18(%r14), %r14
testq %r14, %r14
movq %rbx, 0x10(%rsp)
je 0xc62c
movl $0x28, %r15d
movq 0x8(%rsp), %rax
movq 0x28(%rax), %r12
cmpl $0x3fffffff, -0x8(%r12,%r15) # imm = 0x3FFFFFFF
ja 0xc61f
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
movq -0x28(%r12,%r15), %rsi
movq %rsi, %rax
shrq %rax
leaq (%rax,%rax,4), %rdx
movq 0x8(%rcx,%rdx,8), %rax
testb $0x1, %sil
jne 0xc4c2
leaq (%rcx,%rdx,8), %rdx
movq (%rdx), %rdx
movq -0x8(%rax,%rdx,8), %rax
jmp 0xc4c9
movq (%rax), %rax
xorq $0x1, %rax
movq -0x20(%r12,%r15), %rdi
movq %rdi, %rdx
shrq %rdx
leaq (%rdx,%rdx,4), %rsi
movq 0x8(%rcx,%rsi,8), %rdx
testb $0x1, %dil
jne 0xc4e8
movq (%rdx), %rcx
jmp 0xc4f8
leaq (%rcx,%rsi,8), %rcx
movq (%rcx), %rcx
movq -0x8(%rdx,%rcx,8), %rcx
xorq $0x1, %rcx
movq %rax, %rsi
xorq $0x1, %rsi
movq %rcx, %rdx
xorq $0x1, %rdx
cmpq %rcx, %rax
cmovbeq %rcx, %rsi
cmovbeq %rax, %rdx
movq (%r12,%r15), %rbx
movq 0x10(%rsp), %r13
movq %r13, %rdi
leaq 0x2c(%rsp), %rcx
callq 0xcd0b
cmpl $0x0, 0x2c(%rsp)
movq 0x10(%r13), %rcx
movl %eax, %eax
leaq (%rax,%rax,2), %rax
leaq 0x10(%rcx,%rax,8), %rax
je 0xc542
movq %rbx, (%rax)
jmp 0xc545
movq (%rax), %rbx
leaq (%rbx,%rbx,2), %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,8), %r8
movq (%rcx,%rax,8), %rbp
movq 0x8(%rcx,%rax,8), %r13
cmpq %r13, %rbp
jne 0xc595
leaq (,%rbp,2), %r13
testq %rbp, %rbp
movl $0x2, %eax
cmoveq %rax, %r13
movq %r13, 0x8(%r8)
movq 0x10(%r8), %rdi
leaq (,%r13,8), %rsi
movq %r8, %rbx
callq 0x2350
movq %rbx, %r8
movq %rax, 0x10(%rbx)
jmp 0xc599
movq 0x10(%r8), %rax
movq 0x10(%rsp), %rbx
movq (%r12,%r15), %rcx
leaq 0x1(%rbp), %rdx
movq %rcx, (%rax,%rbp,8)
cmpq %r13, %rdx
jne 0xc5dd
leaq (,%r13,2), %rsi
testq %r13, %r13
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r8)
shlq $0x3, %rsi
movq %rax, %rdi
movq %r8, %r13
callq 0x2350
movq %r13, %r8
movq %rax, 0x10(%r13)
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq -0x28(%r12,%r15), %rdx
movq -0x20(%r12,%r15), %rsi
shrq %rdx
leaq (%rdx,%rdx,4), %rdx
movl 0x20(%rcx,%rdx,8), %edx
movl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
andl %edi, %edx
shrq %rsi
leaq (%rsi,%rsi,4), %rsi
movl 0x20(%rcx,%rsi,8), %ecx
andl %edi, %ecx
addl %edx, %ecx
shrl %ecx
leaq 0x2(%rbp), %rdx
movq %rdx, (%r8)
movq %rcx, 0x8(%rax,%rbp,8)
addq $0x30, %r15
decq %r14
jne 0xc479
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0xc8b8
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdx
xorl %eax, %eax
movq %rax, 0x40(%rsp)
leaq (%rax,%rax,4), %rax
movq (%rdx,%rax,8), %r14
cmpq $0x2, %r14
jb 0xc8a5
movq %rax, 0x20(%rsp)
movq 0x8(%rdx,%rax,8), %rbp
movl $0x1, %r15d
movq -0x8(%rbp,%r15,8), %rcx
movq (%rbp,%r15,8), %rsi
movq %rcx, %rax
xorq $0x1, %rax
movq %rsi, %rdi
xorq $0x1, %rdi
cmpq %rsi, %rcx
cmovbeq %rsi, %rax
cmovbeq %rcx, %rdi
movq 0x10(%rbx), %rsi
testq %rsi, %rsi
je 0xc894
movb (%rbx), %cl
movl $0x1, %r8d
shll %cl, %r8d
movq %rax, %r9
notq %r9
movq %rax, %r10
shlq $0x15, %r10
addq %r9, %r10
movq %r10, %r9
shrq $0x18, %r9
xorq %r10, %r9
imulq $0x109, %r9, %r9        # imm = 0x109
movq %r9, %r10
shrq $0xe, %r10
xorq %r9, %r10
leaq (%r10,%r10,4), %r9
leaq (%r10,%r9,4), %r10
movq %r10, %r9
shrq $0x1c, %r9
xorq %r10, %r9
movq %rdi, %r10
notq %r10
movq %rdi, %r11
shlq $0x15, %r11
addq %r10, %r11
movq %r11, %r10
shrq $0x18, %r10
xorq %r11, %r10
imulq $0x109, %r10, %r10      # imm = 0x109
movq %r10, %r11
shrq $0xe, %r11
xorq %r10, %r11
leaq (%r11,%r11,4), %r10
leaq (%r11,%r10,4), %r10
movq %r10, %r11
shrq $0x1c, %r11
xorl %r10d, %r11d
movl $0x80000001, %r10d      # imm = 0x80000001
imull %r11d, %r10d
movabsq $-0x7fffffff00000000, %r11 # imm = 0x8000000100000000
imulq %r11, %r9
orq %r9, %r10
movq %r10, %r9
notq %r9
shlq $0x15, %r10
addq %r9, %r10
movq %r10, %r9
shrq $0x18, %r9
xorq %r10, %r9
imulq $0x109, %r9, %r9        # imm = 0x109
movq %r9, %r10
shrq $0xe, %r10
xorq %r9, %r10
leaq (%r10,%r10,4), %r9
leaq (%r10,%r9,4), %r9
movq %r9, %r10
shrq $0x1c, %r10
xorl %r9d, %r10d
imull $0x1e3779b9, %r10d, %r9d # imm = 0x1E3779B9
negb %cl
shrl %cl, %r9d
leal -0x1(%r8), %ecx
movq 0x8(%rbx), %r11
movl %r9d, %r10d
movl %r10d, %ebx
shrl $0x5, %ebx
movl (%r11,%rbx,4), %ebx
btl %r10d, %ebx
jae 0xc894
movl %r10d, %ebx
leaq (%rbx,%rbx,2), %r12
movq 0x8(%rsi,%r12,8), %r13
xorq %rdi, %r13
movq (%rsi,%r12,8), %r12
xorq %rax, %r12
orq %r13, %r12
je 0xc7d4
incl %r10d
andl %ecx, %r10d
cmpl %r9d, %r10d
jne 0xc795
jmp 0xc894
cmpl %r8d, %r10d
je 0xc894
leaq (%rbx,%rbx,2), %rax
movq 0x10(%rsi,%rax,8), %rax
leaq (%rax,%rax,2), %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
movq (%rcx,%rax,8), %r13
movq 0x8(%rcx,%rax,8), %rbx
cmpq %rbx, %r13
jne 0xc833
leaq (,%r13,2), %rbx
testq %r13, %r13
movl $0x2, %eax
cmoveq %rax, %rbx
movq %rbx, 0x8(%r12)
movq 0x10(%r12), %rdi
leaq (,%rbx,8), %rsi
callq 0x2350
movq %rax, 0x10(%r12)
jmp 0xc838
movq 0x10(%r12), %rax
leaq 0x1(%r13), %rcx
movq $-0x1, (%rax,%r13,8)
cmpq %rbx, %rcx
jne 0xc86f
leaq (%rbx,%rbx), %rsi
testq %rbx, %rbx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r12)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2350
movq %rax, 0x10(%r12)
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rdx
movq 0x20(%rsp), %rcx
movl 0x20(%rdx,%rcx,8), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
leaq 0x2(%r13), %rsi
movq %rsi, (%r12)
movq %rcx, 0x8(%rax,%r13,8)
incq %r15
cmpq %r14, %r15
movq 0x10(%rsp), %rbx
jne 0xc674
movq 0x40(%rsp), %rax
incq %rax
cmpq 0x38(%rsp), %rax
jne 0xc64d
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rbx
testq %rbx, %rbx
je 0xcc47
xorl %r12d, %r12d
movq %rbx, 0x20(%rsp)
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rdx
leaq (%r12,%r12,2), %rsi
shlq $0x4, %rsi
movl 0x20(%rdx,%rsi), %eax
cmpl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
ja 0xcc23
leaq (%rdx,%rsi), %r13
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rdi
movq (%r13), %r9
movq %r9, %rcx
shrq %rcx
leaq (%rcx,%rcx,4), %r8
movq 0x8(%rdi,%r8,8), %rcx
testb $0x1, %r9b
jne 0xc926
leaq (%rdi,%r8,8), %r8
movq (%r8), %r8
movq -0x8(%rcx,%r8,8), %rcx
jmp 0xc92d
movq (%rcx), %rcx
xorq $0x1, %rcx
movq 0x10(%rsp), %r15
movq 0x8(%r13), %r10
movq %r10, %r8
shrq %r8
leaq (%r8,%r8,4), %r9
movq 0x8(%rdi,%r9,8), %r8
testb $0x1, %r10b
jne 0xc950
movq (%r8), %rdi
jmp 0xc960
leaq (%rdi,%r9,8), %rdi
movq (%rdi), %rdi
movq -0x8(%r8,%rdi,8), %rdi
xorq $0x1, %rdi
movq %rcx, %r8
xorq $0x1, %r8
movq %rdi, %r9
xorq $0x1, %r9
cmpq %rdi, %rcx
cmovbeq %rdi, %r8
cmovbeq %rcx, %r9
movq 0x10(%r15), %rdi
testq %rdi, %rdi
je 0xcaad
movb (%r15), %cl
movl $0x1, %r10d
shll %cl, %r10d
movq %r8, %r11
notq %r11
movq %r8, %rbx
shlq $0x15, %rbx
addq %r11, %rbx
movq %rbx, %r11
shrq $0x18, %r11
xorq %rbx, %r11
imulq $0x109, %r11, %r11      # imm = 0x109
movq %r11, %rbx
shrq $0xe, %rbx
xorq %r11, %rbx
leaq (%rbx,%rbx,4), %r11
leaq (%rbx,%r11,4), %rbx
movq %rbx, %r11
shrq $0x1c, %r11
xorq %rbx, %r11
movq %r9, %rbx
notq %rbx
movq %r9, %r14
shlq $0x15, %r14
addq %rbx, %r14
movq %r14, %rbx
shrq $0x18, %rbx
xorq %r14, %rbx
imulq $0x109, %rbx, %rbx      # imm = 0x109
movq %rbx, %r14
shrq $0xe, %r14
xorq %rbx, %r14
leaq (%r14,%r14,4), %rbx
leaq (%r14,%rbx,4), %rbx
movq %rbx, %r14
shrq $0x1c, %r14
xorl %ebx, %r14d
movl $0x80000001, %ebx       # imm = 0x80000001
imull %r14d, %ebx
movabsq $-0x7fffffff00000000, %r14 # imm = 0x8000000100000000
imulq %r14, %r11
orq %r11, %rbx
movq %rbx, %r11
notq %r11
shlq $0x15, %rbx
addq %r11, %rbx
movq %rbx, %r11
shrq $0x18, %r11
xorq %rbx, %r11
imulq $0x109, %r11, %r11      # imm = 0x109
movq %r11, %rbx
shrq $0xe, %rbx
xorq %r11, %rbx
leaq (%rbx,%rbx,4), %r11
leaq (%rbx,%r11,4), %r11
movq %r11, %rbx
shrq $0x1c, %rbx
xorl %r11d, %ebx
imull $0x1e3779b9, %ebx, %r11d # imm = 0x1E3779B9
negb %cl
shrl %cl, %r11d
leal -0x1(%r10), %ecx
movq 0x8(%r15), %r14
movl %r11d, %ebx
movl %ebx, %r15d
shrl $0x5, %r15d
movl (%r14,%r15,4), %ebp
btl %ebx, %ebp
jae 0xcab4
movl %ebx, %r15d
leaq (%r15,%r15,2), %r15
movq 0x8(%rdi,%r15,8), %rbp
xorq %r9, %rbp
movq (%rdi,%r15,8), %r15
xorq %r8, %r15
orq %rbp, %r15
je 0xcab1
incl %ebx
andl %ecx, %ebx
cmpl %r11d, %ebx
jne 0xca77
jmp 0xcab4
xorl %ecx, %ecx
jmp 0xcabc
movl %ebx, %r10d
movl %r10d, %ecx
movq 0x20(%rsp), %rbx
leaq 0x8(%r13), %r14
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rdi,%rcx,8), %r8
leaq (%r8,%r8,2), %rdi
movq 0x18(%rsp), %r9
leaq (%r9,%rdi,8), %rcx
movq (%r9,%rdi,8), %rdi
cmpq $0x2, %rdi
jne 0xcaf2
movq 0x10(%rcx), %rax
cmpq %r8, (%rax)
je 0xcc23
jmp 0xcccd
jb 0xcc23
leaq (%rdx,%rsi), %r15
addq $0x20, %r15
movq 0x10(%rcx), %r8
movq 0x28(%r13), %r9
movq $-0x1, %rdx
movl $0x1, %r10d
xorl %esi, %esi
cmpq %r9, -0x8(%r8,%r10,8)
cmoveq %r10, %rdx
addq (%r8,%r10,8), %rsi
addq $0x2, %r10
cmpq %rdi, %r10
jb 0xcb17
testq %rsi, %rsi
je 0xcc23
cmpq %rdi, %rdx
jae 0xccec
cvtsi2sd %eax, %xmm1
movq %rsi, %xmm0
movq 0x12cb0(%rip), %xmm3    # 0x1f800
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x12cb4(%rip), %xmm4    # 0x1f810
subpd %xmm4, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
divsd %xmm2, %xmm1
movq 0x10(%rcx), %rax
movq (%rax,%rdx,8), %xmm2
punpckldq %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1]
subpd %xmm4, %xmm2
movapd %xmm2, %xmm0
unpckhpd %xmm2, %xmm0            # xmm0 = xmm0[1],xmm2[1]
addsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
callq 0x2110
movq %rax, %rbp
cmpl $0x3, 0x28(%rsp)
jge 0xcc31
andl $0x3fffffff, %ebp       # imm = 0x3FFFFFFF
movl 0x20(%r13), %eax
movl $0xc0000000, %ecx       # imm = 0xC0000000
andl %ecx, %eax
orl %ebp, %eax
movl %eax, 0x20(%r13)
movq 0x8(%r13), %rdx
xorq $0x1, %rdx
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax,%rdx,8), %rax
testq %rax, %rax
je 0xcc23
movq (%r13), %rcx
movq 0x8(%rsp), %rdi
movq 0x28(%rdi), %rsi
movq 0x30(%rdi), %rdi
movq (%rdi,%rdx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
addq %rsi, %rdx
addq $0x20, %rdx
movq -0x18(%rdx), %rsi
xorq %rcx, %rsi
cmpq $0x1, %rsi
jne 0xcc0e
movl (%rdx), %esi
btl $0x1e, %esi
jae 0xcc19
addq $0x30, %rdx
decq %rax
jne 0xcbf9
jmp 0xcc23
andl $0x80000000, %esi       # imm = 0x80000000
orl %ebp, %esi
movl %esi, (%rdx)
incq %r12
cmpq %rbx, %r12
jne 0xc8d2
jmp 0xcc47
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x2872
jmp 0xcba4
movq 0x8(%rsp), %rdi
callq 0x15c8e
movq 0x30(%rsp), %r14
testq %r14, %r14
je 0xcc75
movq 0x18(%rsp), %rbx
addq $0x10, %rbx
movq (%rbx), %rdi
callq 0x2060
addq $0x18, %rbx
decq %r14
jne 0xcc64
movq 0x18(%rsp), %rdi
callq 0x2060
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0xccbe
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %r14
movq %r14, %rdi
callq 0x1d6fb
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0x1d6fb
movq %r14, %rdi
movq %rbx, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1d6fb
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12f7c(%rip), %rdi     # 0x1fc50
leaq 0x12d70(%rip), %rsi     # 0x1fa4b
leaq 0x12f7f(%rip), %rcx     # 0x1fc61
movl $0x8b3, %edx            # imm = 0x8B3
callq 0x21d0
leaq 0x12f99(%rip), %rdi     # 0x1fc8c
leaq 0x12d51(%rip), %rsi     # 0x1fa4b
leaq 0x12f60(%rip), %rcx     # 0x1fc61
movl $0x8bf, %edx            # imm = 0x8BF
callq 0x21d0