// File: /workspace/github_c_makefile_star2_O3/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
movq 0x8(%rdi), %rax
movl (%rax), %ecx
addl %ecx, %ecx
je 0x9c55
movabsq $0x4000000000000000, %r14 # imm = 0x4000000000000000
movslq %esi, %rax
movl %ecx, 0xc(%rsp)
movl %ecx, %r15d
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 0x9aa1
movq 0x28(%rbx), %rsi
movq (%rsi,%rcx,8), %rsi
movl %esi, %edi
testq %rdi, %rdi
je 0x9aa1
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 0x9a95
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 0x9a95
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 0x9a8c
orq %r14, (%r11,%r13)
addq $0x20, %r13
cmpq %r13, %r9
jne 0x9a7a
addl %r8d, %ebp
addq $0x20, %rsi
cmpq %rdi, %rsi
jb 0x9a2c
incq %rcx
cmpq %r15, %rcx
jne 0x99eb
movapd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x10(%rsp)
movsd %xmm2, 0x18(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x8b9c
cmpl $0x0, 0xc(%rsp)
je 0x9c64
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
testq %r8, %r8
je 0x9c47
shrq $0x1b, %rdx
andq $-0x20, %rdx
addq 0x20(%rbx), %rdx
movq %r8, %rsi
shlq $0x5, %rsi
addq %rdx, %rsi
xorl %edi, %edi
xorpd %xmm0, %xmm0
movq %rdx, %r9
xorpd %xmm1, %xmm1
movapd %xmm1, %xmm2
movsd 0x10(%r9), %xmm3
ucomisd %xmm1, %xmm3
jbe 0x9b47
movl $0x1, %edi
movapd %xmm3, %xmm1
movapd %xmm2, %xmm0
jmp 0x9b63
jne 0x9b4f
jp 0x9b4f
incl %edi
jmp 0x9b5f
ucomisd %xmm0, %xmm3
jbe 0x9b5f
movapd %xmm2, %xmm1
movapd %xmm3, %xmm0
jmp 0x9b63
movapd %xmm2, %xmm1
addq $0x20, %r9
cmpq %rsi, %r9
jb 0x9b28
testq %r8, %r8
je 0x9c47
movapd %xmm1, %xmm2
mulsd %xmm7, %xmm2
movapd %xmm1, %xmm3
mulsd %xmm6, %xmm3
movsd 0x10(%rdx), %xmm4
ucomisd %xmm8, %xmm4
jb 0x9b9b
ucomisd %xmm2, %xmm4
jae 0x9c3a
ucomisd %xmm0, %xmm3
setb %r8b
cmpl $0x1, %edi
setne %r9b
movapd %xmm4, %xmm5
cmpneqpd %xmm1, %xmm5
cmpnltpd %xmm8, %xmm4
orpd %xmm5, %xmm4
movd %xmm4, %r10d
orb %r8b, %r9b
orb %r10b, %r9b
testb $0x1, %r9b
je 0x9c3a
movq 0x18(%rdx), %r9
xorl %r8d, %r8d
testq %r14, %r9
jne 0x9c37
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 0x9c37
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 0x9c2e
orq %r14, (%r11,%r12)
addq $0x20, %r12
cmpq %r12, %r9
jne 0x9c1c
addl %r8d, %ebp
addq $0x20, %rdx
cmpq %rsi, %rdx
jb 0x9b85
incq %rax
cmpq %r15, %rax
jne 0x9af1
jmp 0x9c64
movq %rbx, %rdi
movl $0x1, %esi
callq 0x8b9c
xorl %ebp, %ebp
movq %rbx, %rdi
movl $0x1, %esi
callq 0x8b9c
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq