// File: /workspace/github_c_makefile_star2_O3/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), %eax
addl %eax, %eax
je 0xa228
movabsq $0x4000000000000000, %r12 # imm = 0x4000000000000000
movl %eax, %ecx
xorl %edx, %edx
movl $0x0, 0x4(%rsp)
movq 0x28(%rdi), %r9
movq (%r9,%rdx,8), %rbx
cmpl $0x2, %ebx
jne 0xa21a
movl %edx, %eax
xorq $0x1, %rax
movq (%r9,%rax,8), %r8
cmpl $0x2, %r8d
jne 0xa21a
movq 0x20(%rdi), %r10
shrq $0x1b, %r8
andq $-0x20, %r8
movl 0x4(%r10,%r8), %r14d
movq (%r9,%r14,8), %rsi
movq %rsi, %r15
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %r15
je 0xa21a
movq %r12, %r11
leaq (%r10,%r8), %rax
movq %rax, 0x8(%rsp)
movl 0x24(%r10,%r8), %r12d
shrq $0x1b, %rbx
andq $-0x20, %rbx
leaq (%r10,%rbx), %rax
movq %rax, 0x10(%rsp)
movl 0x4(%r10,%rbx), %ebp
movl 0x24(%r10,%rbx), %r13d
shrq $0x20, %rsi
shlq $0x5, %rsi
leaq (%r10,%rsi), %rbx
addq $0x4, %rbx
movq %r15, %rsi
shlq $0x5, %rsi
xorl %r8d, %r8d
cmpl %ebp, (%rbx,%r8)
je 0x9fbe
addq $0x20, %r8
cmpq %r8, %rsi
jne 0x9fad
jmp 0x9ff5
movq (%r9,%r12,8), %rax
movq %rax, %rsi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rsi
je 0x9ff5
shrq $0x20, %rax
shlq $0x5, %rax
leaq (%r10,%rax), %r8
addq $0x4, %r8
shlq $0x5, %rsi
xorl %eax, %eax
cmpl %r13d, (%r8,%rax)
je 0xa044
addq $0x20, %rax
cmpq %rax, %rsi
jne 0x9fe6
cmpl %r13d, (%rbx)
je 0xa005
addq $0x20, %rbx
decq %r15
jne 0x9ff5
jmp 0xa03c
movq (%r9,%r12,8), %rax
movq %rax, %rsi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rsi
je 0xa03c
shrq $0x20, %rax
shlq $0x5, %rax
leaq (%r10,%rax), %r8
addq $0x4, %r8
shlq $0x5, %rsi
xorl %eax, %eax
cmpl %ebp, (%r8,%rax)
je 0xa044
addq $0x20, %rax
cmpq %rax, %rsi
jne 0xa02d
movq %r11, %r12
jmp 0xa21a
movq 0x8(%rsp), %r13
movq 0x18(%r13), %rax
xorl %r10d, %r10d
movl $0x0, %r9d
movq %r11, %r12
testq %r11, %rax
movq 0x10(%rsp), %r15
jne 0xa0c1
orq %r12, %rax
movq %rax, 0x18(%r13)
xorq $0x1, %r14
movq 0x28(%rdi), %rax
movq (%rax,%r14,8), %r8
movq %r8, %rbx
movl $0x1, %r9d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rbx
je 0xa0c1
movl (%r13), %esi
movq 0x20(%rdi), %rax
shrq $0x20, %r8
shlq $0x5, %rbx
shlq $0x5, %r8
leaq (%rax,%r8), %r14
addq $0x18, %r14
xorl %r8d, %r8d
movl -0x14(%r14,%r8), %eax
xorl %esi, %eax
cmpl $0x1, %eax
jne 0xa0b8
orq %r12, (%r14,%r8)
addq $0x20, %r8
cmpq %r8, %rbx
jne 0xa0a8
movq 0x38(%r13), %rax
testq %r12, %rax
jne 0xa12c
orq %r12, %rax
movq %rax, 0x38(%r13)
movl 0x24(%r13), %eax
xorq $0x1, %rax
movq 0x28(%rdi), %rsi
movq (%rsi,%rax,8), %r8
movq %r8, %rbx
movl $0x1, %r10d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rbx
je 0xa12c
movl 0x20(%r13), %esi
movq 0x20(%rdi), %rax
shrq $0x20, %r8
shlq $0x5, %rbx
shlq $0x5, %r8
leaq (%rax,%r8), %r11
addq $0x18, %r11
xorl %r8d, %r8d
movl -0x14(%r11,%r8), %eax
xorl %esi, %eax
cmpl $0x1, %eax
jne 0xa123
orq %r12, (%r11,%r8)
addq $0x20, %r8
cmpq %r8, %rbx
jne 0xa113
movq 0x18(%r15), %rax
xorl %r11d, %r11d
movl $0x0, %ebp
testq %r12, %rax
jne 0xa19d
orq %r12, %rax
movq %rax, 0x18(%r15)
movl 0x4(%r15), %eax
xorq $0x1, %rax
movq 0x28(%rdi), %rsi
movq (%rsi,%rax,8), %r8
movq %r8, %rbx
movl $0x1, %ebp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rbx
je 0xa19d
movl (%r15), %esi
movq 0x20(%rdi), %rax
shrq $0x20, %r8
shlq $0x5, %rbx
shlq $0x5, %r8
leaq (%rax,%r8), %r14
addq $0x18, %r14
xorl %r8d, %r8d
movl -0x14(%r14,%r8), %eax
xorl %esi, %eax
cmpl $0x1, %eax
jne 0xa194
orq %r12, (%r14,%r8)
addq $0x20, %r8
cmpq %r8, %rbx
jne 0xa184
movq 0x38(%r15), %rax
testq %r12, %rax
jne 0xa207
orq %r12, %rax
movq %rax, 0x38(%r15)
movl 0x24(%r15), %eax
xorq $0x1, %rax
movq 0x28(%rdi), %rsi
movq (%rsi,%rax,8), %r8
movq %r8, %rbx
movl $0x1, %r11d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rbx
je 0xa207
movl 0x20(%r15), %esi
movq 0x20(%rdi), %rax
shrq $0x20, %r8
shlq $0x5, %rbx
shlq $0x5, %r8
addq %rax, %r8
addq $0x18, %r8
xorl %r14d, %r14d
movl -0x14(%r8,%r14), %eax
xorl %esi, %eax
cmpl $0x1, %eax
jne 0xa1fe
orq %r12, (%r8,%r14)
addq $0x20, %r14
cmpq %r14, %rbx
jne 0xa1ee
addl 0x4(%rsp), %r9d
addl %r10d, %r9d
addl %ebp, %r9d
addl %r11d, %r9d
movl %r9d, 0x4(%rsp)
incq %rdx
cmpq %rcx, %rdx
jne 0x9f1c
jmp 0xa230
movl $0x0, 0x4(%rsp)
movl $0x1, %esi
callq 0x8b9c
movl 0x4(%rsp), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq