// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]yahs/graph.c
// Function: trim_graph_simple_filter
int trim_graph_simple_filter(graph_t *g, double min_wt, double min_diff_h, double min_diff_l, int min_len)
{
    uint32_t v, nv, na, n_del, n_ma;
    double mwt, smwt;
    graph_arc_t *av, *a;
    nv = graph_n_vtx(g);
    nv <<= 1;
    n_del = 0;

    for (v = 0; v < nv; ++v) {
        if (g->sdict->s[v>>1].len >= min_len)
            continue;
        na = graph_arc_n(g, v);
        av = graph_arc_a(g, v);
        for (a = av; a < av + na; ++a)
            n_del += graph_arc_del_existed(g, a);
    }
    graph_clean(g, 1);

    for (v = 0; v < nv; ++v) {
        na = graph_arc_n(g, v);
        av = graph_arc_a(g, v);
        
        mwt = smwt = 0;
        n_ma = 0;
        for (a = av; a < av + na; ++a) {
            if (a->wt > mwt) {
                smwt = mwt;
                mwt = a->wt;
                n_ma = 1;
            } else if (a->wt == mwt) {
                ++n_ma;
            } else if (a->wt > smwt) {
                smwt = a->wt;
            }
        }

        for (a = av; a < av + na; ++a) {
            if ((a->wt >= min_wt && a->wt >= mwt * min_diff_h) || 
                    (a->wt < min_wt && a->wt == mwt && mwt * min_diff_l >= smwt && n_ma == 1))
                continue;
            n_del += graph_arc_del_existed(g, a);
        }
    }

    graph_clean(g, 1);

#ifdef DEBUG_GRAPH_PRUNE
    fprintf(stderr, "[DEBUG_GRAPH_PRUNE::%s] #del simple filter: %u\n", __func__, n_del);
#endif

    return n_del;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movsd %xmm2, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
movapd %xmm0, 0x20(%rsp)
movq %rdi, %rbx
movq 0x8(%rdi), %rax
movl (%rax), %eax
addl %eax, %eax
movq %rax, (%rsp)
movslq %esi, %r15
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpq (%rsp), %r12
je 0x6a90
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rax
movl %r12d, %ecx
shrl %ecx
imulq $0x58, %rcx, %rcx
cmpq %r15, 0x8(%rax,%rcx)
jae 0x6a8b
movq 0x28(%rbx), %rax
movq (%rax,%r12,8), %r14
movl %r14d, %r13d
shrq $0x1b, %r14
andq $-0x20, %r14
addq 0x20(%rbx), %r14
shlq $0x5, %r13
addq %r14, %r13
cmpq %r13, %r14
jae 0x6a8b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6be8
addl %eax, %ebp
addq $0x20, %r14
jmp 0x6a73
incq %r12
jmp 0x6a37
pushq $0x1
popq %r13
movq %rbx, %rdi
movl %r13d, %esi
callq 0x6248
xorl %ecx, %ecx
cmpq (%rsp), %rcx
je 0x6bcc
movq 0x28(%rbx), %rax
movq %rcx, 0x18(%rsp)
movq (%rax,%rcx,8), %r15
movl %r15d, %r12d
shrq $0x1b, %r15
andq $-0x20, %r15
addq 0x20(%rbx), %r15
shlq $0x5, %r12
addq %r15, %r12
xorpd %xmm3, %xmm3
xorl %r14d, %r14d
xorpd %xmm2, %xmm2
movq %r15, %rax
cmpq %r12, %rax
jae 0x6b20
movsd 0x10(%rax), %xmm1
ucomisd %xmm3, %xmm1
jbe 0x6af9
movl %r13d, %r14d
movapd %xmm1, %xmm0
movapd %xmm3, %xmm2
jmp 0x6b16
jne 0x6b02
jp 0x6b02
incl %r14d
jmp 0x6b12
ucomisd %xmm2, %xmm1
jbe 0x6b12
movapd %xmm3, %xmm0
movapd %xmm1, %xmm2
jmp 0x6b16
movapd %xmm3, %xmm0
addq $0x20, %rax
movapd %xmm0, %xmm3
jmp 0x6adc
movapd %xmm3, %xmm4
mulsd 0x8(%rsp), %xmm4
movapd %xmm3, %xmm5
mulsd 0x10(%rsp), %xmm5
movapd %xmm2, 0x60(%rsp)
movapd %xmm3, 0x50(%rsp)
movapd %xmm4, 0x40(%rsp)
movapd %xmm5, 0x30(%rsp)
cmpq %r12, %r15
jae 0x6bbf
movsd 0x10(%r15), %xmm0
ucomisd 0x20(%rsp), %xmm0
jb 0x6b65
ucomisd %xmm4, %xmm0
jae 0x6bb9
cmpl $0x1, %r14d
setne %al
ucomisd %xmm2, %xmm5
setb %cl
movapd %xmm0, %xmm1
cmpneqpd %xmm3, %xmm1
cmpnltpd 0x20(%rsp), %xmm0
orpd %xmm1, %xmm0
movd %xmm0, %edx
orb %al, %cl
orb %dl, %cl
testb $0x1, %cl
je 0x6bb9
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6be8
movapd 0x30(%rsp), %xmm5
movapd 0x40(%rsp), %xmm4
movapd 0x50(%rsp), %xmm3
movapd 0x60(%rsp), %xmm2
addl %eax, %ebp
addq $0x20, %r15
jmp 0x6b4c
movq 0x18(%rsp), %rcx
incq %rcx
jmp 0x6aa1
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x6248
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq