// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq (%rdi), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rdi), %rbp
testq %rbp, %rbp
je 0x16387
movq 0x28(%r15), %rax
addq $0x28, %rax
xorl %ecx, %ecx
movq %rbp, %rdx
movq %rcx, %rsi
movq (%rax), %rcx
cmpq %rcx, %rsi
cmovaq %rsi, %rcx
addq $0x30, %rax
decq %rdx
jne 0x16367
leaq 0x4(,%rcx,4), %rbx
jmp 0x1638c
movl $0x4, %ebx
movq %rbx, %rdi
callq 0x2310
movq %rax, %r14
movq %rax, %rdi
movl $0xff, %esi
movq %rbx, %rdx
callq 0x21e0
movl $0x1, %esi
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x2250
movq %rax, %r12
testq %rbx, %rbx
je 0x1650f
leal 0x1(,%rbx,2), %eax
movl %eax, 0xc(%rsp)
xorl %edx, %edx
xorl %r13d, %r13d
cmpb $0x0, (%r12,%rdx)
jne 0x164fd
movq 0x10(%r15), %rax
leaq (%rdx,%rdx,4), %rcx
testb $0x40, 0x23(%rax,%rcx,8)
jne 0x164fd
movq %rdx, 0x38(%rsp)
leaq (%rdx,%rdx), %rax
movq %rax, 0x40(%rsp)
movb $0x1, %bl
xorl %ebp, %ebp
xorl %esi, %esi
orq 0x40(%rsp), %rsi
movq %r15, %rdi
movl 0xc(%rsp), %edx
xorl %ecx, %ecx
leaq 0x20(%rsp), %r8
xorl %r9d, %r9d
callq 0x16577
movq 0x20(%rsp), %rcx
cmpq $0x2, %rcx
jb 0x1648a
movq 0x30(%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 0x16469
testb $0x40, -0x5(%r10)
je 0x1646f
addq $0x30, %r10
jmp 0x1645c
movq (%r10), %r10
movl %r13d, (%r14,%r10,4)
shrq %r9
movb $0x1, (%r12,%r9)
incq %r8
cmpq %rcx, %r8
jne 0x16444
addl %ecx, %ebp
decl %ebp
cmpl $0x3, %eax
jne 0x164d4
movq 0x30(%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 0x164bd
movq %rax, %rcx
jmp 0x164ca
leaq 0x30(%rax), %rcx
testb $0x40, 0x53(%rax)
movq %rcx, %rax
jne 0x164bd
movq 0x28(%rcx), %rax
movl %r13d, (%r14,%rax,4)
incl %ebp
movl $0x1, %esi
testb $0x1, %bl
movl $0x0, %ebx
jne 0x16407
cmpl $0x1, %ebp
sbbl $-0x1, %r13d
movq 0x38(%rsp), %rdx
movb $0x1, (%r12,%rdx)
movq 0x18(%rsp), %rbx
incq %rdx
cmpq %rbx, %rdx
jne 0x163d5
movq 0x18(%r15), %rbp
jmp 0x16512
xorl %r13d, %r13d
testq %rbp, %rbp
je 0x16546
movq 0x28(%r15), %rax
addq $0x28, %rax
movq 0x10(%rsp), %rdx
testb $0x40, -0x5(%rax)
jne 0x1653b
movq (%rax), %rcx
cmpl $-0x1, (%r14,%rcx,4)
jne 0x1653b
movl %r13d, (%r14,%rcx,4)
incl %r13d
addq $0x30, %rax
decq %rbp
jne 0x16524
jmp 0x1654b
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
je 0x16553
movl %r13d, (%rdx)
movq 0x30(%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