// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]oatk/syncasm.c
// Function: scg_arc_coverage
void scg_arc_coverage(scg_t *scg, sr_db_t *sr_db)
{
    // add arcs
    uint64_t i, j, n;
    uint64_t v0, v1;
    uint32_t r0, r1;
    khint_t k;
    kh_u128_t *a_cov; // arc cov
    asmg_t *g;
    asmg_arc_t *a;
    asmg_vtx_t *v;
    sr_t *s;

    g = scg->utg_asmg;
    a_cov = kh_u128_init();
    for (i = 0, n = g->n_arc; i < n; ++i) {
        a = &g->arc[i];
        if (a->del) continue;
        v = &g->vtx[a->v>>1];
        v0 = a->v&1? v->a[0]^1 : v->a[v->n-1];
        v = &g->vtx[a->w>>1];
        v1 = a->w&1? v->a[v->n-1]^1 : v->a[0];
        add_a_cov(a_cov, (uint128_t) v0 << 64 | v1, 0);
    }
    for (i = 0, n = sr_db->n; i < n; ++i) {
        s = &sr_db->a[i];
        if (s->n == 0) continue;
        v0 = s->k_mer[0] >> 1;
        r0 = s->m_pos[0] & 1;
        v0 = v0 << 1 | r0;

        for (j = 1; j < s->n; ++j) {
            v1 = s->k_mer[j] >> 1;
            r1 = s->m_pos[j] & 1;
            v1 = v1 << 1 | r1;

            k = kh_u128_get(a_cov, (uint128_t) v0 << 64 | v1);
            if (k < kh_end(a_cov)) {
                kh_val(a_cov, k) += 1;
                if ((v1^1) != v0 || (v0^1) != v1) {
                    k = kh_u128_get(a_cov, (uint128_t) (v1^1) << 64 | (v0^1));
                    kh_val(a_cov, k) += 1;
                }
            }

            v0 = v1;
        }
    }
    for (i = 0, n = g->n_arc; i < n; ++i) {
        a = &g->arc[i];
        if (a->del) continue;
        v = &g->vtx[a->v>>1];
        v0 = a->v&1? v->a[0]^1 : v->a[v->n-1];
        v = &g->vtx[a->w>>1];
        v1 = a->w&1? v->a[v->n-1]^1 : v->a[0];
        k = kh_u128_get(a_cov, (uint128_t) v0 << 64 | v1);
        a->cov = kh_val(a_cov, k);
    }
    kh_u128_destroy(a_cov);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, 0x10(%rsp)
movq 0x8(%rdi), %rbx
callq 0x3cde
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %r14
xorl %r15d, %r15d
subq $0x1, %r14
jb 0x402e
movq 0x28(%rbx), %rcx
testb $0x40, 0x23(%rcx,%r15)
jne 0x4025
movq 0x10(%rbx), %rax
movq (%rcx,%r15), %rdi
movq %rdi, %rdx
shrq %rdx
imulq $0x28, %rdx, %rdx
movq 0x8(%rax,%rdx), %rsi
testb $0x1, %dil
jne 0x3fe4
addq %rax, %rdx
movq (%rdx), %rdx
movq -0x8(%rsi,%rdx,8), %rdx
jmp 0x3feb
movq (%rsi), %rdx
xorq $0x1, %rdx
movq 0x8(%rcx,%r15), %rdi
movq %rdi, %rcx
shrq %rcx
imulq $0x28, %rcx, %rsi
movq 0x8(%rax,%rsi), %rcx
testb $0x1, %dil
jne 0x400a
movq (%rcx), %rsi
jmp 0x4019
addq %rsi, %rax
movq (%rax), %rax
movq -0x8(%rcx,%rax,8), %rsi
xorq $0x1, %rsi
movq 0x8(%rsp), %rdi
xorl %ecx, %ecx
callq 0x3cf3
addq $0x30, %r15
jmp 0x3fa4
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
xorl %ecx, %ecx
movq %rbx, 0x18(%rsp)
cmpq 0x20(%rsp), %rcx
je 0x4127
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x28(%rsp)
imulq $0x58, %rcx, %rcx
movl 0x38(%rax,%rcx), %edx
movq %rdx, 0x30(%rsp)
testq %rdx, %rdx
je 0x4115
addq %rcx, %rax
movq 0x40(%rax), %r13
movq 0x50(%rax), %r14
movq (%r14), %rax
andq $-0x2, %rax
movl (%r13), %r15d
andl $0x1, %r15d
orq %rax, %r15
pushq $0x1
popq %rbx
cmpq %rbx, 0x30(%rsp)
je 0x4115
movq %r15, %r12
movq (%r14,%rbx,8), %rax
andq $-0x2, %rax
movl (%r13,%rbx,4), %r15d
andl $0x1, %r15d
orq %rax, %r15
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x41fd
movq 0x10(%rbp), %rbp
testq %rbp, %rbp
je 0x410d
movq 0x8(%rsp), %rcx
movb (%rcx), %cl
movl %eax, %edx
shrl %cl, %edx
testl %edx, %edx
jne 0x410d
movl %eax, %eax
imulq $0x18, %rax, %rax
incq 0x10(%rbp,%rax)
movq %r15, %rdx
xorq $0x1, %rdx
cmpq %r12, %rdx
je 0x410d
xorq $0x1, %r12
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x41fd
movl %eax, %eax
imulq $0x18, %rax, %rax
incq 0x10(%rbp,%rax)
incq %rbx
jmp 0x4091
movq 0x28(%rsp), %rcx
incq %rcx
movq 0x18(%rsp), %rbx
jmp 0x4042
movq 0x18(%rbx), %r14
pushq $0x20
popq %r15
movq 0x8(%rsp), %rbp
subq $0x1, %r14
jb 0x41e5
movq 0x28(%rbx), %r12
movl (%r12,%r15), %r13d
btl $0x1e, %r13d
jb 0x41dc
movq 0x10(%rbx), %rax
movq -0x20(%r12,%r15), %rsi
movq %rsi, %rcx
shrq %rcx
imulq $0x28, %rcx, %rcx
movq 0x8(%rax,%rcx), %rdx
testb $0x1, %sil
jne 0x417c
addq %rax, %rcx
movq (%rcx), %rcx
movq -0x8(%rdx,%rcx,8), %rdx
jmp 0x4183
movq (%rdx), %rdx
xorq $0x1, %rdx
movq -0x18(%r12,%r15), %rdi
movq %rdi, %rcx
shrq %rcx
imulq $0x28, %rcx, %rsi
movq 0x8(%rax,%rsi), %rcx
testb $0x1, %dil
jne 0x41a2
movq (%rcx), %rsi
jmp 0x41b1
addq %rsi, %rax
movq (%rax), %rax
movq -0x8(%rcx,%rax,8), %rsi
xorq $0x1, %rsi
movq %rbp, %rdi
callq 0x41fd
movq 0x10(%rbp), %rcx
movl %eax, %eax
imulq $0x18, %rax, %rax
movl 0x10(%rcx,%rax), %eax
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl %ecx, %eax
andl $0x80000000, %r13d      # imm = 0x80000000
orl %eax, %r13d
movl %r13d, (%r12,%r15)
addq $0x30, %r15
jmp 0x4134
movq 0x8(%rsp), %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3d41