// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/graph.c
// Function: asmg_subgraph
uint32_t *asmg_subgraph(asmg_t *g, uint32_t *seeds, uint32_t n, uint32_t step, 
        uint64_t dist, uint32_t *_nv, int modify_graph)
{
    // make a subgraph from given a vertex set and radius
    // if modify_graph
    //     all vertices and arcs in other components will be marked as deleted
    //     return 0
    // else
    //     keep graph unchanged
    //     return the list of vertices in the subgraph
    if (n == 0) {
        if (_nv) *_nv = 0;
        return 0;
    }

    uint32_t r;
    uint64_t i, v, x, rd, nv;
    int8_t *flag;
    kdq_u64_t *q;
    kdq_u64_t *d;
    asmg_arc_t *av;

    if (step == 0)
        step = UINT32_MAX;
    if (dist == 0)
        dist = UINT64_MAX;

    MYCALLOC(flag, asmg_vtx_n(g));
    // flag deleted segments
    for (i = 0; i < g->n_vtx; ++i) {
        if (g->vtx[i].del) {
            flag[i<<1|0] = -1;
            flag[i<<1|1] = -1;
        }
    }

    q = kdq_init(uint64_t, 0);
    d = kdq_init(uint64_t, 0);
    for (i = 0; i < n; ++i) {
        if (seeds[i] < g->n_vtx) {
            kdq_push(uint64_t, q, ((uint64_t)seeds[i]<<1|0)<<32);
            kdq_push(uint64_t, d, 0);
            kdq_push(uint64_t, q, ((uint64_t)seeds[i]<<1|1)<<32);
            kdq_push(uint64_t, d, 0);
        }
    }

    if (modify_graph) {
        for (i = 0; i < g->n_vtx; ++i) // mark all segments to be deleted
            g->vtx[i].del = 1;
        // for (i = 0; i < g->n_arc; ++i) // mark all arcs to be deleted
        //     g->arc[i].del = 1;
    }

    while (kdq_size(q) > 0) {
        x = *kdq_shift(uint64_t, q);
        v = x>>32;
        r = (uint32_t) x;
        rd = *kdq_shift(uint64_t, d);
        if (flag[v] != 0) continue; // already visited or deleted
        flag[v] = 1;
        if (modify_graph) g->vtx[v>>1].del = 0;
        if (r < step && rd < dist) {
            nv = asmg_arc_n(g, v);
            av = asmg_arc_a(g, v);
            for (i = 0; i < nv; ++i) {
                if (av[i].del) continue;
                // if (modify_graph) av[i].del = 0;
                if (flag[av[i].w] == 0) {
                    kdq_push(uint64_t, q, (uint64_t)av[i].w<<32 | (r + 1));
                    kdq_push(uint64_t, d, rd + g->vtx[av[i].w>>1].len - av[i].ls);
                }
                if (flag[av[i].w^1] == 0) {
                    kdq_push(uint64_t, q, (uint64_t)(av[i].w^1)<<32 | (r + 1));
                    kdq_push(uint64_t, d, rd + g->vtx[av[i].w>>1].len - av[i].ls);
                }
            }
        }
    }
    assert(kdq_size(d) == 0);

    // change flag index from vtx<<1 to vtx
    for (i = 0; i < g->n_vtx; ++i)
        flag[i] = (flag[i<<1|0] > 0 || flag[i<<1|1] > 0);

    uint32_t *vs;
    nv = 0;
    vs = 0;
    if (!modify_graph) {
        // make vlist
        kvec_t(uint32_t) vlist;
        kv_init(vlist);
        for (i = 0; i < g->n_vtx; ++i)
            if (flag[i])
                kv_push(uint32_t, vlist, i);
        MYREALLOC(vlist.a, vlist.n);
        vs = vlist.a;
        nv = vlist.n;
    } else {
        // delete dirty arcs
        for (i = 0; i < g->n_arc; ++i) {
            if (!flag[g->arc[i].v>>1] || !flag[g->arc[i].w>>1])
                g->arc[i].del = 1;
        }
        if (_nv) {
            for (i = 0; i < g->n_vtx; ++i)
                nv += flag[i];
        }
    }
    
    if (_nv) *_nv = nv;
    
    kdq_destroy(uint64_t, q);
    kdq_destroy(uint64_t, d);
    free(flag);

    return vs;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x237a8
cmpq $0x0, -0x30(%rbp)
je 0x2379b
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x23e80
cmpl $0x0, -0x20(%rbp)
jne 0x237b5
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
cmpq $0x0, -0x28(%rbp)
jne 0x237c4
movq $-0x1, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
shlq %rdi
movl $0x1, %esi
callq 0x2250
movq %rax, -0x68(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x23845
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x23835
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rcx
shlq %rcx
orq $0x0, %rcx
movb $-0x1, (%rax,%rcx)
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rcx
shlq %rcx
orq $0x1, %rcx
movb $-0x1, (%rax,%rcx)
jmp 0x23837
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x237e4
xorl %eax, %eax
movl %eax, %edi
callq 0x23e90
movq %rax, -0x70(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x23e90
movq %rax, -0x78(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x238fa
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x238e7
movq -0x70(%rbp), %rdi
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %esi
shlq %rsi
orq $0x0, %rsi
shlq $0x20, %rsi
callq 0x23eb0
movq -0x78(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x23eb0
movq -0x70(%rbp), %rdi
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %esi
shlq %rsi
orq $0x1, %rsi
shlq $0x20, %rsi
callq 0x23eb0
movq -0x78(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x23eb0
jmp 0x238e9
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x23867
cmpl $0x0, 0x10(%rbp)
je 0x23947
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x23945
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, 0x20(%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x23908
jmp 0x23947
jmp 0x23949
movq -0x70(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jbe 0x23b8a
movq -0x70(%rbp), %rdi
callq 0x23f50
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
shrq $0x20, %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
movl %eax, -0x34(%rbp)
movq -0x78(%rbp), %rdi
callq 0x23f50
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rax
movq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x2399e
jmp 0x23949
movq -0x68(%rbp), %rax
movq -0x48(%rbp), %rcx
movb $0x1, (%rax,%rcx)
cmpl $0x0, 0x10(%rbp)
je 0x239d5
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rcx
shrq %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x0, %ecx
movl %ecx, 0x20(%rax)
movl -0x34(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x23b85
movq -0x58(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x23b85
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq -0x48(%rbp), %rdx
imulq $0x30, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x23b83
movq -0x80(%rbp), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x23a58
jmp 0x23b72
movq -0x68(%rbp), %rax
movq -0x80(%rbp), %rcx
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x23ae0
movq -0x70(%rbp), %rdi
movq -0x80(%rbp), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
shlq $0x20, %rsi
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
orq %rax, %rsi
callq 0x23eb0
movq -0x78(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x80(%rbp), %rcx
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
shrq %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
addq 0x18(%rax), %rsi
movq -0x80(%rbp), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
subq 0x18(%rax), %rsi
callq 0x23eb0
movq -0x68(%rbp), %rax
movq -0x80(%rbp), %rcx
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
xorq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x23b70
movq -0x70(%rbp), %rdi
movq -0x80(%rbp), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
xorq $0x1, %rsi
shlq $0x20, %rsi
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
orq %rax, %rsi
callq 0x23eb0
movq -0x78(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x80(%rbp), %rcx
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
shrq %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
addq 0x18(%rax), %rsi
movq -0x80(%rbp), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
subq 0x18(%rax), %rsi
callq 0x23eb0
jmp 0x23b72
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x23a2b
jmp 0x23b85
jmp 0x23949
movq -0x78(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x23b97
jmp 0x23bb6
leaq 0xb032(%rip), %rdi      # 0x2ebd0
leaq 0xb03c(%rip), %rsi      # 0x2ebe1
movl $0x4a6, %edx            # imm = 0x4A6
leaq 0xb038(%rip), %rcx      # 0x2ebe9
callq 0x21e0
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x23c30
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rcx
shlq %rcx
orq $0x0, %rcx
movsbl (%rax,%rcx), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0xa1(%rbp)
jg 0x23c0a
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rcx
shlq %rcx
orq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setg %al
movb %al, -0xa1(%rbp)
movb -0xa1(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb %al, %dl
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x23bbe
movq $0x0, -0x60(%rbp)
movq $0x0, -0x88(%rbp)
cmpl $0x0, 0x10(%rbp)
jne 0x23d78
movq $0x0, -0x98(%rbp)
movq $0x0, -0xa0(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x23d3c
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x23d29
jmp 0x23c9b
movq -0xa0(%rbp), %rax
cmpq -0x98(%rbp), %rax
jne 0x23d02
cmpq $0x0, -0x98(%rbp)
je 0x23cc8
movq -0x98(%rbp), %rax
shlq %rax
movq %rax, -0xb0(%rbp)
jmp 0x23cd6
movl $0x2, %eax
movq %rax, -0xb0(%rbp)
jmp 0x23cd6
movq -0xb0(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, -0x90(%rbp)
movq -0x40(%rbp), %rax
movl %eax, %edx
movq -0x90(%rbp), %rax
movq -0xa0(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0xa0(%rbp)
movl %edx, (%rax,%rcx,4)
jmp 0x23d29
jmp 0x23d2b
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x23c76
movq -0x90(%rbp), %rdi
movq -0xa0(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x23e47
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x23e04
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq %rcx
cmpb $0x0, (%rax,%rcx)
je 0x23dcf
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
shrq %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x23df1
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, 0x20(%rax)
jmp 0x23df3
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x23d80
cmpq $0x0, -0x30(%rbp)
je 0x23e45
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x23e43
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbq (%rax,%rcx), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x23e13
jmp 0x23e45
jmp 0x23e47
cmpq $0x0, -0x30(%rbp)
je 0x23e5a
movq -0x60(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x70(%rbp), %rdi
callq 0x24030
movq -0x78(%rbp), %rdi
callq 0x24030
movq -0x68(%rbp), %rdi
callq 0x2060
movq -0x88(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)