// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
callq 0x8080
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x2bcac
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpl $0x0, 0x14(%rax)
je 0x2bb2a
movq -0x60(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x2bb2f
jmp 0x2bc9e
movq -0x60(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x60(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x60(%rbp), %rax
movb 0x1c(%rax), %al
movb %al, -0x45(%rbp)
cmpb $0x0, -0x45(%rbp)
jne 0x2bb57
jmp 0x2bc9e
movq -0x60(%rbp), %rax
movl 0x18(%rax), %eax
cvtsi2sd %rax, %xmm1
movsd -0x20(%rbp), %xmm2
movsd 0x7248(%rip), %xmm0     # 0x32db8
movl $0x1, %edi
xorl %esi, %esi
callq 0x249b0
movq -0x60(%rbp), %rax
movl 0x18(%rax), %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x4, -0x30(%rbp)
jge 0x2bc9c
movl -0x30(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movsbl -0x45(%rbp), %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x2bc8c
movq -0x60(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsd 0x60(%rax,%rcx,8), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
ucomisd -0x18(%rbp), %xmm0
jb 0x2bc8a
movsd -0x50(%rbp), %xmm1
movsd -0x58(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2bbf3
jmp 0x2bc8e
movl -0x38(%rbp), %eax
shll %eax
movl -0x30(%rbp), %ecx
sarl %ecx
orl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
shll %eax
movl -0x30(%rbp), %ecx
andl $0x1, %ecx
orl %ecx, %eax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rax
movl -0x40(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x2bc37
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x2bc39
jmp 0x2bc8e
movq -0x68(%rbp), %rdi
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
movsd -0x50(%rbp), %xmm0
movq $-0x1, %rcx
xorl %r8d, %r8d
callq 0x8330
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movl -0x44(%rbp), %esi
xorl $0x1, %esi
movl -0x40(%rbp), %edx
xorl $0x1, %edx
movq -0x70(%rbp), %rax
movabsq $0x1fffffffffffffff, %rcx # imm = 0x1FFFFFFFFFFFFFFF
andq 0x18(%rax), %rcx
movsd -0x50(%rbp), %xmm0
xorl %r8d, %r8d
callq 0x8330
jmp 0x2bc8c
jmp 0x2bc8e
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2bb98
jmp 0x2bc9e
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2baf3
movq -0x68(%rbp), %rdi
callq 0x85a0
movq -0x68(%rbp), %rdi
callq 0x86b0
movq -0x68(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)