// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/syncasm.c
// Function: make_syncmer_graph
scg_t *make_syncmer_graph(sr_db_t *sr_db, syncmer_db_t *scm_db, uint32_t min_k_cov, double min_a_cov_f)
{
    if (scm_db->n == 0) return 0;

    scg_t *scg;
    MYCALLOC(scg, 1);
    scg->scm_db = scm_db;
    
    size_t i, j;
    uint64_t n_scm;
    syncmer_t *scm;
    sr_t *s;
    
    scm = scg_a_scm(scg);
    n_scm = scg_n_scm(scg);
    
    // add utg vtx
    // each single scm is a utg
    asmg_vtx_t *vtx, *vtx1;
    MYCALLOC(vtx, n_scm);
    for (i = 0; i < n_scm; ++i) {
        // filter by kmer coverage
        scm[i].del |= scm[i].cov < min_k_cov;
        vtx1 = &vtx[i];
        MYMALLOC(vtx1->a, 1);
        vtx1->n = 1;
        vtx1->a[0] = i<<1;
        vtx1->cov = scm[i].cov;
        vtx1->del = scm[i].del;
    }

    // add arcs
    kvec_t(asmg_arc_t) arc;
    kv_init(arc);
    uint64_t v0, v1;
    uint32_t r0, r1, v_v;
    uint128_t v_p; // v0, v1 packed
    kh_u128_t *a_cov; // arc cov
    a_cov = kh_u128_init();
    for (i = 0; i < sr_db->n; ++i) {
        s = &sr_db->a[i];
        if (s->n == 0) continue;
        // the last bit of k_mer indicates if it is corrected mer
        v0 = s->k_mer[0] >> 1;
        r0 = s->m_pos[0] & 1;
        v0 = v0 << 1 | r0;

        for (j = 1; j < s->n; ++j) {
            // the last bit of k_mer indicates if it is corrected mer
            v1 = s->k_mer[j] >> 1;
            r1 = s->m_pos[j] & 1;
            v1 = v1 << 1 | r1;

            v0 <= v1? add_a_cov(a_cov, (uint128_t) v0 << 64 | v1, 1) :
                add_a_cov(a_cov, ((uint128_t) v1^1) << 64 | (v0^1), 1);

            v0 = v1;
        }
    }

    khint_t k;
    for (k = (khint_t) 0; k < kh_end(a_cov); ++k) {
        if (kh_exist(a_cov, k)) {
            v_p = kh_key(a_cov, k);
            v_v = kh_val(a_cov, k);
            v0 = (uint64_t) (v_p >> 64);
            v1 = (uint64_t) v_p;
            if (v_v < min_a_cov_f * MIN(scm[v0>>1].cov, scm[v1>>1].cov)
                    || vtx[v0>>1].del || vtx[v1>>1].del)
                continue;
            asmg_arc_t a = {v0, v1, 0, 0, v_v, 0, 0, UINT64_MAX};
            kv_push(asmg_arc_t, arc, a);
            if ((v1^1) != v0 || (v0^1) != v1) {
                // to avoid multi-arcs
                // for arcs like (v+)->(v-)
                asmg_arc_t a_c = {v1^1, v0^1, 0, 0, v_v, 0, 1, UINT64_MAX};
                kv_push(asmg_arc_t, arc, a_c);
            }
        }
    }
    kh_u128_destroy(a_cov);

    asmg_t *utg_asmg;
    MYCALLOC(utg_asmg, 1);
    utg_asmg->vtx = vtx;
    utg_asmg->m_vtx = utg_asmg->n_vtx = n_scm;
    utg_asmg->arc = arc.a;
    utg_asmg->m_arc = utg_asmg->n_arc = arc.n;
    MYREALLOC(utg_asmg->arc, utg_asmg->n_arc);
    // sort arc and build index
    asmg_finalize(utg_asmg, 1);

    scg->utg_asmg = utg_asmg;
    scg_scm_utg_index(scg);

    return scg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movsd %xmm0, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x3e32
movq $0x0, -0x8(%rbp)
jmp 0x4679
movl $0x1, %edi
movl $0x20, %esi
callq 0x2250
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movl $0x28, %esi
callq 0x2250
movq %rax, -0x60(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x3f92
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl -0x1c(%rbp), %eax
setb %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movl 0x10(%rax), %edx
shrl $0x1f, %edx
orl %ecx, %edx
movl 0x10(%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, 0x10(%rax)
movq -0x60(%rbp), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl $0x8, %edi
callq 0x2320
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x68(%rbp), %rax
movq $0x1, (%rax)
movq -0x38(%rbp), %rcx
shlq %rcx
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq -0x68(%rbp), %rax
movl 0x20(%rax), %ecx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl %edx, %ecx
movl %ecx, 0x20(%rax)
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %edx
shrl $0x1f, %edx
movq -0x68(%rbp), %rax
movl 0x20(%rax), %ecx
andl $0x1, %edx
shll $0x1e, %edx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl %edx, %ecx
movl %ecx, 0x20(%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x3e87
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
callq 0x4690
movq %rax, -0xb8(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x415e
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x58, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x3ff2
jmp 0x414d
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rax
movq (%rax), %rax
shrq %rax
movq %rax, -0x88(%rbp)
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movl (%rax), %eax
andl $0x1, %eax
movl %eax, -0x94(%rbp)
movq -0x88(%rbp), %rax
shlq %rax
movl -0x94(%rbp), %ecx
orq %rcx, %rax
movq %rax, -0x88(%rbp)
movq $0x1, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x58(%rbp), %rcx
movl 0x38(%rcx), %ecx
cmpq %rcx, %rax
jae 0x414b
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
movq %rax, -0x90(%rbp)
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x1, %eax
movl %eax, -0x98(%rbp)
movq -0x90(%rbp), %rax
shlq %rax
movl -0x98(%rbp), %ecx
orq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x90(%rbp), %rax
ja 0x40e9
movq -0xb8(%rbp), %rdi
movq -0x88(%rbp), %rcx
movq -0x90(%rbp), %rax
movq %rcx, -0xc8(%rbp)
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rdx
movl $0x1, %ecx
callq 0x46a0
jmp 0x412c
movq -0xb8(%rbp), %rdi
movq -0x90(%rbp), %rcx
xorq $0x1, %rcx
movq -0x88(%rbp), %rax
xorq $0x1, %rax
movq %rcx, -0xd8(%rbp)
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movl $0x1, %ecx
callq 0x46a0
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x403c
jmp 0x414d
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x3fbe
movl $0x0, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
movl %eax, -0x154(%rbp)
movq -0xb8(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x419a
movq -0xb8(%rbp), %rax
movl (%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x158(%rbp)
jmp 0x41a4
xorl %eax, %eax
movl %eax, -0x158(%rbp)
jmp 0x41a4
movl -0x154(%rbp), %eax
movl -0x158(%rbp), %ecx
cmpl %ecx, %eax
jae 0x45ab
movq -0xb8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0xe4(%rbp), %ecx
shrl $0x5, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0xe4(%rbp), %ecx
andl $0x1f, %ecx
shrl %cl, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4595
movq -0xb8(%rbp), %rax
movq 0x10(%rax), %rcx
movl -0xe4(%rbp), %eax
leaq (%rax,%rax,2), %rdx
movq (%rcx,%rdx,8), %rax
movq 0x8(%rcx,%rdx,8), %rcx
movq %rcx, -0xa8(%rbp)
movq %rax, -0xb0(%rbp)
movq -0xb8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xe4(%rbp), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x10(%rax,%rcx,8), %eax
movl %eax, -0x9c(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x9c(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x168(%rbp)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x160(%rbp)
movq -0x50(%rbp), %rax
movq -0x88(%rbp), %rcx
shrq %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x50(%rbp), %rcx
movq -0x90(%rbp), %rdx
shrq %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jge 0x42d3
movq -0x50(%rbp), %rax
movq -0x88(%rbp), %rcx
shrq %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x16c(%rbp)
jmp 0x42f6
movq -0x50(%rbp), %rax
movq -0x90(%rbp), %rcx
shrq %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x16c(%rbp)
movsd -0x168(%rbp), %xmm1
movsd -0x160(%rbp), %xmm0
movl -0x16c(%rbp), %eax
cvtsi2sd %eax, %xmm2
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
ja 0x4360
movq -0x60(%rbp), %rax
movq -0x88(%rbp), %rcx
shrq %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x4360
movq -0x60(%rbp), %rax
movq -0x90(%rbp), %rcx
shrq %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4365
jmp 0x4597
movq -0x88(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x110(%rbp)
movq $0x0, -0x108(%rbp)
movq $0x0, -0x100(%rbp)
movl -0x9c(%rbp), %ecx
movl -0xf8(%rbp), %eax
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl $0xc0000000, %eax       # imm = 0xC0000000
orl %ecx, %eax
movl %eax, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x0, %eax
movl %eax, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl $0x0, %eax
movl %eax, -0xf8(%rbp)
movq $-0x1, -0xf0(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x78(%rbp), %rax
jne 0x4435
cmpq $0x0, -0x78(%rbp)
je 0x440a
movq -0x78(%rbp), %rax
shlq %rax
movq %rax, -0x178(%rbp)
jmp 0x4418
movl $0x2, %eax
movq %rax, -0x178(%rbp)
jmp 0x4418
movq -0x178(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
imulq $0x30, -0x78(%rbp), %rsi
callq 0x2360
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movq -0x80(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x80(%rbp)
imulq $0x30, %rax, %rax
addq %rax, %rdi
leaq -0x118(%rbp), %rsi
movl $0x30, %edx
callq 0x22c0
movq -0x90(%rbp), %rax
xorq $0x1, %rax
cmpq -0x88(%rbp), %rax
jne 0x448c
movq -0x88(%rbp), %rax
xorq $0x1, %rax
cmpq -0x90(%rbp), %rax
je 0x4593
movq -0x90(%rbp), %rax
xorq $0x1, %rax
movq %rax, -0x148(%rbp)
movq -0x88(%rbp), %rax
xorq $0x1, %rax
movq %rax, -0x140(%rbp)
movq $0x0, -0x138(%rbp)
movq $0x0, -0x130(%rbp)
movl -0x9c(%rbp), %ecx
movl -0x128(%rbp), %eax
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl $0xc0000000, %eax       # imm = 0xC0000000
orl %ecx, %eax
movl %eax, -0x128(%rbp)
movl -0x128(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x0, %eax
movl %eax, -0x128(%rbp)
movl -0x128(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl $0x80000000, %eax       # imm = 0x80000000
movl %eax, -0x128(%rbp)
movq $-0x1, -0x120(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x78(%rbp), %rax
jne 0x4566
cmpq $0x0, -0x78(%rbp)
je 0x453b
movq -0x78(%rbp), %rax
shlq %rax
movq %rax, -0x180(%rbp)
jmp 0x4549
movl $0x2, %eax
movq %rax, -0x180(%rbp)
jmp 0x4549
movq -0x180(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
imulq $0x30, -0x78(%rbp), %rsi
callq 0x2360
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movq -0x80(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x80(%rbp)
imulq $0x30, %rax, %rax
addq %rax, %rdi
leaq -0x148(%rbp), %rsi
movl $0x30, %edx
callq 0x22c0
jmp 0x4593
jmp 0x4595
jmp 0x4597
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x4168
movq -0xb8(%rbp), %rdi
callq 0x4740
movl $0x1, %edi
movl $0x40, %esi
callq 0x2250
movq %rax, -0x150(%rbp)
movq -0x60(%rbp), %rcx
movq -0x150(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x48(%rbp), %rcx
movq -0x150(%rbp), %rax
movq %rcx, (%rax)
movq -0x150(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x70(%rbp), %rcx
movq -0x150(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x80(%rbp), %rcx
movq -0x150(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x150(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x150(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x150(%rbp), %rax
imulq $0x30, 0x18(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x150(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x150(%rbp), %rdi
movl $0x1, %esi
callq 0x20160
movq -0x150(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rdi
callq 0x4760
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
nopw %cs:(%rax,%rax)