// File: /workspace/github_c_makefile_star2_O1/c-zhou[P]yahs/yahs.c
// Function: build_graph_from_links
graph_t *build_graph_from_links(inter_link_mat_t *link_mat, asm_dict_t *dict, double min_norm, double la, int8_t *telo_ends)
{
    int32_t i, j, n, c0, c1;
    uint32_t v, w;
    int8_t t;
    double norm, qla;
    inter_link_t *link;
    graph_t *g;
    graph_arc_t *arc;

    g = graph_init();
    g->sdict = dict;

    // build graph
    n = link_mat->n;
    for (i = 0; i < n; ++i) {
        link = &link_mat->links[i];
        if (link->n == 0 || link->n0 == 0)
            continue;
        c0 = link->c0;
        c1 = link->c1;
        t = link->linkt;
        if (!t)
            continue;
        
        qla = qbinom(.99, link->n0, la, 1, 0) / link->n0;
        for (j = 0; j < 4; ++j) {
            if (1 << j & t) {
                norm = link->norms[j];
                if (norm >= min_norm) {
                    if (norm < qla) {
#ifdef DEBUG_QLF
                        fprintf(stderr, "[DEBUG_QLF::%s] #Edge rejected by QL filter: %s %s %u %u %.3f (< %.3f)\n", __func__, dict->s[c0].name, dict->s[c1].name, j, link->n0, norm, qla);
#endif
                        continue;
                    }
                    v = c0<<1 | (j>>1);
                    w = c1<<1 | (j&1);
                    if (telo_ends[v^1] || telo_ends[w])
                        continue;
                    arc = graph_add_arc(g, v, w, -1, 0, norm);
                    graph_add_arc(g, w^1, v^1, arc->link_id, 0, norm);
                }
            }
        }
    }

    graph_arc_sort(g);
    graph_arc_index(g);

    return g;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
movsd %xmm1, 0x30(%rsp)
movsd %xmm0, 0x20(%rsp)
movq %rsi, %r12
movq %rdi, %r14
callq 0x8291
movq %rax, 0x8(%rsp)
movq %r12, 0x8(%rax)
movq %r14, 0x50(%rsp)
movslq (%r14), %rax
movq %rax, 0x48(%rsp)
testq %rax, %rax
jle 0x1e4aa
movl $0x60, %edx
xorl %r15d, %r15d
movq %rbx, 0x18(%rsp)
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rbp
movq %r15, %rbx
shlq $0x7, %rbx
cmpl $0x0, 0x14(%rbp,%rbx)
je 0x1e498
addq %rbp, %rbx
movl 0x18(%rbx), %eax
testl %eax, %eax
je 0x1e498
movsbl 0x1c(%rbx), %r14d
testl %r14d, %r14d
je 0x1e498
movl (%rbx), %r12d
movl 0x4(%rbx), %r13d
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movsd 0x5008(%rip), %xmm0     # 0x23388
movsd 0x30(%rsp), %xmm2
movl $0x1, %edi
xorl %esi, %esi
movq %rdx, 0x28(%rsp)
callq 0x1acda
movl %r13d, %r8d
movq 0x28(%rsp), %rdx
movq 0x18(%rsp), %rcx
movapd %xmm0, %xmm1
movl 0x18(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movl %r12d, %eax
divsd %xmm0, %xmm1
movsd 0x20(%rsp), %xmm2
addl %r12d, %eax
addl %r13d, %r8d
addq %rdx, %rbp
xorl %r13d, %r13d
movl %eax, 0x14(%rsp)
movl %r8d, 0x10(%rsp)
movsd %xmm1, 0x38(%rsp)
btl %r13d, %r14d
jae 0x1e48b
movsd (%rbp,%r13,8), %xmm0
ucomisd %xmm2, %xmm0
jb 0x1e48b
ucomisd %xmm0, %xmm1
ja 0x1e48b
movl %r13d, %esi
shrl %esi
addl %eax, %esi
movq %rsi, %r12
xorq $0x1, %r12
cmpb $0x0, (%rcx,%r12)
jne 0x1e48b
movl %r13d, %ebx
andl $0x1, %ebx
orl %r8d, %ebx
cmpb $0x0, (%rcx,%rbx)
jne 0x1e48b
movq 0x8(%rsp), %rdi
movl %ebx, %edx
movq $-0x1, %rcx
xorl %r8d, %r8d
movsd %xmm0, 0x40(%rsp)
callq 0x8408
xorl $0x1, %ebx
movq 0x18(%rax), %rcx
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
andq %rax, %rcx
movq 0x8(%rsp), %rdi
movl %ebx, %esi
movl %r12d, %edx
xorl %r8d, %r8d
movsd 0x40(%rsp), %xmm0
callq 0x8408
movsd 0x38(%rsp), %xmm1
movl 0x10(%rsp), %r8d
movl 0x14(%rsp), %eax
movq 0x28(%rsp), %rdx
movsd 0x20(%rsp), %xmm2
movq 0x18(%rsp), %rcx
incq %r13
cmpq $0x4, %r13
jne 0x1e3db
incq %r15
subq $-0x80, %rdx
cmpq 0x48(%rsp), %r15
jne 0x1e330
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x853f
movq %rbx, %rdi
callq 0x85bd
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq