// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]yahs/link.c
// Function: calc_link_directs
void calc_link_directs(inter_link_mat_t *link_mat, double min_norm, asm_dict_t *dict, int8_t *directs)
{
    uint32_t i, j, k, n, b, b0, b1, r, n_ma;
    int8_t t;
    inter_link_t *inter_link;
    double area[4]; // area under the cumsum of linkb
    double ma, sma;
    uint32_t max_b = UINT32_MAX;

    r = link_mat->r;
    for (i = 0; i < link_mat->n; ++i) {
        inter_link = &link_mat->links[i];
        n = inter_link->n;
        if (n == 0)
            continue;
        b0 = inter_link->b0;
        b1 = inter_link->b1;
        for (j = 0; j < n; ++j) {
            b = j / b1 + j % b1;
            if (b <= b0 && b <= b1 && b <= max_b && b < r)
                for (k = 0; k < 4; ++k)
                    if (inter_link->link[k][j] > .0)
                        inter_link->linkb[k][b] += inter_link->link[k][j];
        }
    }

    for (i = 0; i < link_mat->n; ++i) {
        inter_link = &link_mat->links[i];
        if (inter_link->n == 0)
            continue;
        r = inter_link->r;
        memset(area, 0, sizeof(area));
        for (j = 0; j < r; ++j)
            for (k = 0; k < 4; ++k)
                area[k] += inter_link->linkb[k][j]; //* (r - j);
        // select the one with maximum cumsum area as linkt
        t = 0;
        ma = sma = 0;
        n_ma = 0;
        for (k = 0; k < 4; ++k) {
            if (area[k] > ma) {
                sma = ma;
                ma = area[k];
                n_ma = 1;
                t = k;
            } else if (area[k] == ma) {
                ++n_ma;
            } else if (area[k] > sma) {
                sma = area[k];
            }
        }
        if (n_ma == 1 && ma * .9 > sma) {
            inter_link->linkt = 1 << t;
        } else {
            t = 0;
            for (k = 0; k < 4; ++k)
                if (inter_link->norms[k] >= min_norm)
                    t |= (1 << k);
            inter_link->linkt = t;
        }

#ifdef DEBUG_ORIEN
        fprintf(stderr, "[DEBUG_ORIEN::%s] %d %.0f %.0f %d %d [%.3f %.3f %.3f %.3f] [%.0f  %.0f  %.0f  %.0f] %s %s\n", __func__, inter_link->linkt, ma, sma, inter_link->b0, inter_link->b1, inter_link->norms[0], inter_link->norms[1], inter_link->norms[2], inter_link->norms[3], area[0], area[1], area[2], area[3], dict->s[inter_link->c0].name, dict->s[inter_link->c1].name);
#endif
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0xffffffff, -0x84(%rbp) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x11a46
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x11951
jmp 0x11a38
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x50(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x11a36
movl -0x28(%rbp), %eax
xorl %edx, %edx
divl -0x3c(%rbp)
movl %eax, -0x88(%rbp)
movl -0x28(%rbp), %eax
xorl %edx, %edx
divl -0x3c(%rbp)
movl -0x88(%rbp), %eax
addl %edx, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
ja 0x11a26
movl -0x34(%rbp), %eax
cmpl -0x3c(%rbp), %eax
ja 0x11a26
movl -0x34(%rbp), %eax
cmpl -0x84(%rbp), %eax
ja 0x11a26
movl -0x34(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0x11a26
movl $0x0, -0x2c(%rbp)
cmpl $0x4, -0x2c(%rbp)
jae 0x11a24
movq -0x50(%rbp), %rax
movl -0x2c(%rbp), %ecx
movq 0x20(%rax,%rcx,8), %rax
movl -0x28(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x11a17
movq -0x50(%rbp), %rax
movl -0x2c(%rbp), %ecx
movq 0x20(%rax,%rcx,8), %rax
movl -0x28(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm0
movq -0x50(%rbp), %rax
movl -0x2c(%rbp), %ecx
movq 0x40(%rax,%rcx,8), %rax
movl -0x34(%rbp), %ecx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x11a19
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x119c7
jmp 0x11a26
jmp 0x11a28
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1196c
jmp 0x11a38
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x11917
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x11c35
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jne 0x11a81
jmp 0x11c27
movq -0x50(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x40(%rbp)
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x21f0
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0x11af2
movl $0x0, -0x2c(%rbp)
cmpl $0x4, -0x2c(%rbp)
jae 0x11ae5
movq -0x50(%rbp), %rax
movl -0x2c(%rbp), %ecx
movq 0x40(%rax,%rcx,8), %rax
movl -0x28(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm0
movl -0x2c(%rbp), %eax
addsd -0x70(%rbp,%rax,8), %xmm0
movsd %xmm0, -0x70(%rbp,%rax,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x11ab1
jmp 0x11ae7
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x11aa2
movb $0x0, -0x45(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x78(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x4, -0x2c(%rbp)
jae 0x11ba4
movl -0x2c(%rbp), %eax
movsd -0x70(%rbp,%rax,8), %xmm0
ucomisd -0x78(%rbp), %xmm0
jbe 0x11b55
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movl -0x2c(%rbp), %eax
movsd -0x70(%rbp,%rax,8), %xmm0
movsd %xmm0, -0x78(%rbp)
movl $0x1, -0x44(%rbp)
movl -0x2c(%rbp), %eax
movb %al, -0x45(%rbp)
jmp 0x11b94
movl -0x2c(%rbp), %eax
movsd -0x70(%rbp,%rax,8), %xmm0
ucomisd -0x78(%rbp), %xmm0
jne 0x11b72
jp 0x11b72
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x11b92
movl -0x2c(%rbp), %eax
movsd -0x70(%rbp,%rax,8), %xmm0
ucomisd -0x80(%rbp), %xmm0
jbe 0x11b90
movl -0x2c(%rbp), %eax
movsd -0x70(%rbp,%rax,8), %xmm0
movsd %xmm0, -0x80(%rbp)
jmp 0x11b92
jmp 0x11b94
jmp 0x11b96
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x11b14
cmpl $0x1, -0x44(%rbp)
jne 0x11bd4
movsd 0x1fa76(%rip), %xmm0    # 0x31628
mulsd -0x78(%rbp), %xmm0
ucomisd -0x80(%rbp), %xmm0
jbe 0x11bd4
movsbl -0x45(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movb %al, %cl
movq -0x50(%rbp), %rax
movb %cl, 0x1c(%rax)
jmp 0x11c25
movb $0x0, -0x45(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x4, -0x2c(%rbp)
jae 0x11c1b
movq -0x50(%rbp), %rax
movl -0x2c(%rbp), %ecx
movsd 0x60(%rax,%rcx,8), %xmm0
ucomisd -0x10(%rbp), %xmm0
jb 0x11c0e
movl -0x2c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movsbl -0x45(%rbp), %eax
orl %ecx, %eax
movb %al, -0x45(%rbp)
jmp 0x11c10
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x11bdf
movb -0x45(%rbp), %cl
movq -0x50(%rbp), %rax
movb %cl, 0x1c(%rax)
jmp 0x11c27
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x11a4d
addq $0x90, %rsp
popq %rbp
retq
nop