// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rdi, %rbx
movabsq $0x4000000000000000, %r14 # imm = 0x4000000000000000
movq 0x8(%rdi), %rax
movl (%rax), %eax
addl %eax, %eax
movl %eax, 0xc(%rsp)
movl %eax, %r15d
je 0x914f
movslq %esi, %rax
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movq 0x8(%rbx), %rsi
movq 0x8(%rsi), %rsi
movl %ecx, %edi
shrl %edi
imulq $0x58, %rdi, %rdi
cmpq %rax, 0x8(%rsi,%rdi)
jae 0x9141
movq 0x28(%rbx), %rsi
movq (%rsi,%rcx,8), %rsi
movl %esi, %edi
testq %rdi, %rdi
je 0x9141
shrq $0x1b, %rsi
andq $-0x20, %rsi
addq 0x20(%rbx), %rsi
shlq $0x5, %rdi
addq %rsi, %rdi
movq 0x18(%rsi), %r9
xorl %r8d, %r8d
testq %r14, %r9
jne 0x9135
orq %r14, %r9
movq %r9, 0x18(%rsi)
movl 0x4(%rsi), %r8d
xorq $0x1, %r8
movq 0x28(%rbx), %r9
movq (%r9,%r8,8), %r11
movq %r11, %r9
movl $0x1, %r8d
andq %rdx, %r9
je 0x9135
movl (%rsi), %r10d
movq 0x20(%rbx), %r13
shrq $0x20, %r11
shlq $0x5, %r9
shlq $0x5, %r11
addq %r13, %r11
addq $0x18, %r11
xorl %r13d, %r13d
movl -0x14(%r11,%r13), %r12d
xorl %r10d, %r12d
cmpl $0x1, %r12d
jne 0x912c
orq %r14, (%r11,%r13)
addq $0x20, %r13
cmpq %r13, %r9
jne 0x911a
addl %r8d, %ebp
addq $0x20, %rsi
cmpq %rdi, %rsi
jb 0x90cc
incq %rcx
cmpq %r15, %rcx
jne 0x908b
jmp 0x9151
xorl %ebp, %ebp
movapd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x10(%rsp)
movsd %xmm2, 0x18(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x8744
cmpl $0x0, 0xc(%rsp)
je 0x9300
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movsd 0x18(%rsp), %xmm6
movsd 0x10(%rsp), %xmm7
movapd 0x20(%rsp), %xmm8
movq 0x28(%rbx), %rdx
movq (%rdx,%rax,8), %rdx
movl %edx, %r8d
shrq $0x1b, %rdx
andq $-0x20, %rdx
addq 0x20(%rbx), %rdx
movq %r8, %rsi
shlq $0x5, %rsi
addq %rdx, %rsi
testq %r8, %r8
je 0x9215
xorl %edi, %edi
xorpd %xmm0, %xmm0
movq %rdx, %r9
xorpd %xmm1, %xmm1
movapd %xmm1, %xmm2
movsd 0x10(%r9), %xmm3
ucomisd %xmm1, %xmm3
jbe 0x91e7
movl $0x1, %edi
movapd %xmm3, %xmm1
movapd %xmm2, %xmm0
jmp 0x9203
jne 0x91ef
jp 0x91ef
incl %edi
jmp 0x91ff
ucomisd %xmm0, %xmm3
jbe 0x91ff
movapd %xmm2, %xmm1
movapd %xmm3, %xmm0
jmp 0x9203
movapd %xmm2, %xmm1
addq $0x20, %r9
cmpq %rsi, %r9
jb 0x91c8
cmpl $0x1, %edi
setne %dil
jmp 0x9220
xorpd %xmm1, %xmm1
movb $0x1, %dil
xorpd %xmm0, %xmm0
testq %r8, %r8
je 0x92f4
movapd %xmm1, %xmm2
mulsd %xmm7, %xmm2
movapd %xmm1, %xmm3
mulsd %xmm6, %xmm3
movsd 0x10(%rdx), %xmm4
ucomisd %xmm8, %xmm4
jb 0x924f
ucomisd %xmm2, %xmm4
jae 0x92e7
ucomisd %xmm0, %xmm3
setb %r8b
movapd %xmm4, %xmm5
cmpneqpd %xmm1, %xmm5
cmpnltpd %xmm8, %xmm4
orpd %xmm5, %xmm4
movd %xmm4, %r9d
orb %dil, %r8b
orb %r9b, %r8b
testb $0x1, %r8b
je 0x92e7
movq 0x18(%rdx), %r9
xorl %r8d, %r8d
testq %r14, %r9
jne 0x92e4
orq %r14, %r9
movq %r9, 0x18(%rdx)
movl 0x4(%rdx), %r8d
xorq $0x1, %r8
movq 0x28(%rbx), %r9
movq (%r9,%r8,8), %r11
movq %r11, %r9
movl $0x1, %r8d
andq %rcx, %r9
je 0x92e4
movl (%rdx), %r10d
movq 0x20(%rbx), %r12
shrq $0x20, %r11
shlq $0x5, %r9
shlq $0x5, %r11
addq %r12, %r11
addq $0x18, %r11
xorl %r12d, %r12d
movl -0x14(%r11,%r12), %r13d
xorl %r10d, %r13d
cmpl $0x1, %r13d
jne 0x92db
orq %r14, (%r11,%r12)
addq $0x20, %r12
cmpq %r12, %r9
jne 0x92c9
addl %r8d, %ebp
addq $0x20, %rdx
cmpq %rsi, %rdx
jb 0x9239
incq %rax
cmpq %r15, %rax
jne 0x9195
movq %rbx, %rdi
movl $0x1, %esi
callq 0x8744
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq