// File: /workspace/github_c_makefile_star2_O1/c-zhou[P]oatk/graph.c
// Function: asmg_uext_arc_group
uint32_t *asmg_uext_arc_group(asmg_t *g, uint32_t *n_group)
{
    uint64_t i, j, k, v, n_vtx, n_arc;
    uint32_t *arc_group, group, na;
    uint8_t *visited;
    int32_t vt;
    u64_v_t a = {0, 0, 0};

    n_vtx = g->n_vtx;
    n_arc = asmg_max_link_id(g) + 1; // number unique arcs
    
    MYMALLOC(arc_group, n_arc);
    MYBONE(arc_group, n_arc);
    MYCALLOC(visited, n_vtx);

    group = 0;
    for (i = 0; i < n_vtx; ++i) {
        if (visited[i] || g->vtx[i].del)
            continue;
        na = 0;
        for (k = 0; k < 2; ++k) {
            v = i << 1 | k;
            vt = asmg_uext(g, v, n_vtx*2+1, 0, 0, &a, 0);
            for (j = 1; j < a.n; ++j) {
                arc_group[asmg_arc1(g, a.a[j-1], a.a[j])->link_id] = group;
                visited[a.a[j]>>1] = 1;
                ++na;
            }
            if (vt == ASMG_VT_MULTI_NEI) {
                arc_group[asmg_arc_a1(g, a.a[a.n-1])->link_id] = group;
                ++na;
            }
        }
        if (na > 0) ++group;
        visited[i] = 1;
    }
    
    for (i = 0; i < g->n_arc; ++i) {
        if (g->arc[i].del || 
                arc_group[g->arc[i].link_id] != (uint32_t) -1)
            continue;
        arc_group[g->arc[i].link_id] = group++;
    }

    if (n_group) *n_group = group;

    free(a.a);
    free(visited);

    return arc_group;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%rdi), %rbp
movq 0x18(%rdi), %rax
testq %rax, %rax
je 0x158c1
movq 0x28(%r15), %rcx
addq $0x28, %rcx
xorl %edx, %edx
movq %rdx, %rsi
movq (%rcx), %rdx
cmpq %rdx, %rsi
cmovaq %rsi, %rdx
addq $0x30, %rcx
decq %rax
jne 0x158a1
leaq 0x4(,%rdx,4), %rbx
jmp 0x158c6
movl $0x4, %ebx
movq %rbx, %rdi
callq 0x2320
movq %rax, %r14
movq %rax, %rdi
movl $0xff, %esi
movq %rbx, %rdx
callq 0x21e0
movl $0x1, %esi
movq %rbp, %rdi
callq 0x2250
movq %rax, %r12
testq %rbp, %rbp
je 0x15a44
leal 0x1(,%rbp,2), %eax
movl %eax, 0x4(%rsp)
xorl %edx, %edx
xorl %r13d, %r13d
movq %rbp, 0x30(%rsp)
cmpb $0x0, (%r12,%rdx)
jne 0x15a36
movq 0x10(%r15), %rax
leaq (%rdx,%rdx,4), %rcx
testb $0x40, 0x23(%rax,%rcx,8)
jne 0x15a36
movq %rdx, 0x38(%rsp)
leaq (%rdx,%rdx), %rax
movq %rax, 0x40(%rsp)
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x40(%rsp), %rax
leaq (%rbx,%rax), %rsi
movq %r15, %rdi
movl 0x4(%rsp), %edx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
xorl %r9d, %r9d
callq 0x15ab0
movq 0x10(%rsp), %rcx
cmpq $0x2, %rcx
jb 0x159c6
movq 0x20(%rsp), %rdx
movq 0x28(%r15), %rsi
movq 0x30(%r15), %rdi
addq $0x28, %rsi
movl $0x1, %r8d
movq -0x8(%rdx,%r8,8), %r10
movq (%rdx,%r8,8), %r9
movq (%rdi,%r10,8), %r10
leaq (%r10,%r10,2), %r10
shlq $0x4, %r10
addq %rsi, %r10
cmpq %r9, -0x20(%r10)
jne 0x159a5
testb $0x40, -0x5(%r10)
je 0x159ab
addq $0x30, %r10
jmp 0x15998
movq (%r10), %r10
movl %r13d, (%r14,%r10,4)
shrq %r9
movb $0x1, (%r12,%r9)
incq %r8
cmpq %rcx, %r8
jne 0x15980
addl %ecx, %ebp
decl %ebp
cmpl $0x3, %eax
jne 0x15a10
movq 0x20(%rsp), %rax
movq -0x8(%rax,%rcx,8), %rax
movq 0x28(%r15), %rcx
movq 0x30(%r15), %rdx
movq (%rdx,%rax,8), %rax
leaq (%rax,%rax,2), %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rax
testb $0x40, 0x23(%rcx,%rdx)
jne 0x159f9
movq %rax, %rcx
jmp 0x15a06
leaq 0x30(%rax), %rcx
testb $0x40, 0x53(%rax)
movq %rcx, %rax
jne 0x159f9
movq 0x28(%rcx), %rax
movl %r13d, (%r14,%rax,4)
incl %ebp
leaq 0x1(%rbx), %rax
testq %rbx, %rbx
movq %rax, %rbx
je 0x1593f
cmpl $0x1, %ebp
sbbl $-0x1, %r13d
movq 0x38(%rsp), %rdx
movb $0x1, (%r12,%rdx)
movq 0x30(%rsp), %rbp
incq %rdx
cmpq %rbp, %rdx
jne 0x1590f
jmp 0x15a47
xorl %r13d, %r13d
movq 0x18(%r15), %rax
testq %rax, %rax
je 0x15a7f
movq 0x28(%r15), %rcx
addq $0x28, %rcx
movq 0x8(%rsp), %rsi
testb $0x40, -0x5(%rcx)
jne 0x15a74
movq (%rcx), %rdx
cmpl $-0x1, (%r14,%rdx,4)
jne 0x15a74
movl %r13d, (%r14,%rdx,4)
incl %r13d
addq $0x30, %rcx
decq %rax
jne 0x15a5d
jmp 0x15a84
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
je 0x15a8c
movl %r13d, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x2060
movq %r12, %rdi
callq 0x2060
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq