// File: /workspace/github_c_makefile_star2_O1/c-zhou[P]yahs/graph.c
// Function: trim_graph_repeats
int trim_graph_repeats(graph_t *g)
{
    // TODO a more sophisticated implemetation for complex repeats
    uint32_t v, v1, v2, w1, w2, nv, n_del;
    graph_arc_t *av, *aw;
    nv = graph_n_vtx(g);
    nv <<= 1;
    n_del = 0;

    for (v = 0; v < nv; ++v) {
        if (graph_arc_n(g, v) != 2 || graph_arc_n(g, v^1) != 2)
            continue;
        av = graph_arc_a(g, v^1);
        v1 = av->w;
        v2 = (av + 1)->w;
        aw = graph_arc_a(g, v);
        w1 = aw->w;
        w2 = (aw + 1)->w;

        if ((graph_arc(g, v1, w1) && graph_arc(g, v2, w2)) ||
                (graph_arc(g, v1, w2) && graph_arc(g, v2, w1))) {
            n_del += graph_arc_del_existed(g, av);
            n_del += graph_arc_del_existed(g, av + 1);
            n_del += graph_arc_del_existed(g, aw);
            n_del += graph_arc_del_existed(g, aw + 1);
        }
    }

    graph_clean(g, 1);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x8(%rdi), %rax
movl (%rax), %ecx
addl %ecx, %ecx
je 0x98c2
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movl %ecx, %ecx
xorl %edx, %edx
movl $0x0, 0x4(%rsp)
movq 0x28(%rdi), %r11
movq (%r11,%rdx,8), %rbx
cmpl $0x2, %ebx
jne 0x98b4
movl %edx, %esi
xorq $0x1, %rsi
movq (%r11,%rsi,8), %r8
cmpl $0x2, %r8d
jne 0x98b4
movq 0x20(%rdi), %r10
shrq $0x1b, %r8
andq $-0x20, %r8
movl 0x4(%r10,%r8), %r14d
movq (%r11,%r14,8), %rsi
testl %esi, %esi
je 0x98b4
leaq (%r10,%r8), %r9
movq %r9, 0x8(%rsp)
movl 0x24(%r10,%r8), %r15d
shrq $0x1b, %rbx
andq $-0x20, %rbx
leaq (%r10,%rbx), %r8
movq %r8, 0x10(%rsp)
movl 0x4(%r10,%rbx), %ebp
movl 0x24(%r10,%rbx), %r13d
movq %rsi, %r12
shrq $0x1b, %r12
andq $-0x20, %r12
addq %r10, %r12
movl %esi, %ebx
movq %rbx, %r9
movq %r12, %r8
cmpl %ebp, 0x4(%r8)
je 0x9643
addq $0x20, %r8
decq %r9
jne 0x9631
xorl %r8d, %r8d
testq %r8, %r8
je 0x9679
movq (%r11,%r15,8), %r9
testl %r9d, %r9d
je 0x9679
movq %r9, %r8
shrq $0x1b, %r8
andq $-0x20, %r8
addq %r10, %r8
movl %r9d, %r9d
cmpl %r13d, 0x4(%r8)
je 0x9674
addq $0x20, %r8
decq %r9
jne 0x9662
xorl %r8d, %r8d
testq %r8, %r8
jne 0x96d4
testl %esi, %esi
je 0x98b4
cmpl %r13d, 0x4(%r12)
je 0x9694
addq $0x20, %r12
decq %rbx
jne 0x9681
xorl %r12d, %r12d
testq %r12, %r12
je 0x98b4
movq (%r11,%r15,8), %rsi
testl %esi, %esi
je 0x98b4
movq %rsi, %r8
shrq $0x1b, %r8
andq $-0x20, %r8
addq %r8, %r10
movl %esi, %esi
cmpl %ebp, 0x4(%r10)
je 0x96cb
addq $0x20, %r10
decq %rsi
jne 0x96b9
xorl %r10d, %r10d
testq %r10, %r10
je 0x98b4
movq 0x8(%rsp), %r15
movq 0x18(%r15), %rsi
xorl %r11d, %r11d
movl $0x0, %r10d
testq %rax, %rsi
movq 0x10(%rsp), %r12
jne 0x974e
orq %rax, %rsi
movq %rsi, 0x18(%r15)
xorq $0x1, %r14
movq 0x28(%rdi), %rsi
movq (%rsi,%r14,8), %r9
movq %r9, %rsi
movl $0x1, %r10d
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rsi
je 0x974e
movl (%r15), %r8d
movq 0x20(%rdi), %rbx
shrq $0x20, %r9
shlq $0x5, %rsi
shlq $0x5, %r9
addq %r9, %rbx
addq $0x18, %rbx
xorl %r9d, %r9d
movl -0x14(%rbx,%r9), %ebp
xorl %r8d, %ebp
cmpl $0x1, %ebp
jne 0x9745
orq %rax, (%rbx,%r9)
addq $0x20, %r9
cmpq %r9, %rsi
jne 0x9734
movq 0x38(%r15), %rsi
testq %rax, %rsi
jne 0x97b9
orq %rax, %rsi
movq %rsi, 0x38(%r15)
movl 0x24(%r15), %esi
xorq $0x1, %rsi
movq 0x28(%rdi), %r8
movq (%r8,%rsi,8), %r9
movq %r9, %rsi
movl $0x1, %r11d
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rsi
je 0x97b9
movl 0x20(%r15), %r8d
movq 0x20(%rdi), %rbx
shrq $0x20, %r9
shlq $0x5, %rsi
shlq $0x5, %r9
addq %rbx, %r9
addq $0x18, %r9
xorl %ebx, %ebx
movl -0x14(%r9,%rbx), %ebp
xorl %r8d, %ebp
cmpl $0x1, %ebp
jne 0x97b0
orq %rax, (%r9,%rbx)
addq $0x20, %rbx
cmpq %rbx, %rsi
jne 0x979f
movq 0x18(%r12), %rsi
xorl %r9d, %r9d
movl $0x0, %ebp
testq %rax, %rsi
jne 0x9830
orq %rax, %rsi
movq %rsi, 0x18(%r12)
movl 0x4(%r12), %esi
xorq $0x1, %rsi
movq 0x28(%rdi), %r8
movq (%r8,%rsi,8), %rbx
movq %rbx, %rsi
movl $0x1, %ebp
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rsi
je 0x9830
movl (%r12), %r8d
movq 0x20(%rdi), %r14
shrq $0x20, %rbx
shlq $0x5, %rsi
shlq $0x5, %rbx
addq %r14, %rbx
addq $0x18, %rbx
xorl %r14d, %r14d
movl -0x14(%rbx,%r14), %r15d
xorl %r8d, %r15d
cmpl $0x1, %r15d
jne 0x9827
orq %rax, (%rbx,%r14)
addq $0x20, %r14
cmpq %r14, %rsi
jne 0x9815
movq 0x38(%r12), %rsi
testq %rax, %rsi
jne 0x98a1
orq %rax, %rsi
movq %rsi, 0x38(%r12)
movl 0x24(%r12), %esi
xorq $0x1, %rsi
movq 0x28(%rdi), %r8
movq (%r8,%rsi,8), %rbx
movq %rbx, %rsi
movl $0x1, %r9d
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rsi
je 0x98a1
movl 0x20(%r12), %r8d
movq 0x20(%rdi), %r14
shrq $0x20, %rbx
shlq $0x5, %rsi
shlq $0x5, %rbx
addq %r14, %rbx
addq $0x18, %rbx
xorl %r14d, %r14d
movl -0x14(%rbx,%r14), %r15d
xorl %r8d, %r15d
cmpl $0x1, %r15d
jne 0x9898
orq %rax, (%rbx,%r14)
addq $0x20, %r14
cmpq %r14, %rsi
jne 0x9886
addl 0x4(%rsp), %r10d
addl %r11d, %r10d
addl %ebp, %r10d
addl %r9d, %r10d
movl %r10d, 0x4(%rsp)
incq %rdx
cmpq %rcx, %rdx
jne 0x95b0
jmp 0x98ca
movl $0x0, 0x4(%rsp)
movl $0x1, %esi
callq 0x8744
movl 0x4(%rsp), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq