// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/graph.c
// Function: asmg_topo_ext
static uint64_t asmg_topo_ext(asmg_t *g, uint64_t v0, uint64_t max_dist, int32_t thru_flag, asmg_tbuf_t *b)
{
    if (g->vtx[v0>>1].del) return 0;

    uint64_t i, v, w, l, nv, d, c, a, n_pending, max_d;
    asmg_tinfo_t *t;
    asmg_arc_t *av;

    // n_pending: number of visited vertices that are not sorted
    // max_d: max asmg_tinfo_t::d of visited vertices
    n_pending = max_d = 0;
    b->S.n = b->b.n = b->e.n = 0;
    b->n_short_tip = b->n_sink = b->dist = 0;
    b->self_cycle = 0;
    b->v_sink = UINT64_MAX;
    t = &b->a[v0];
    t->d = t->c = t->r = t->s = 0;
    t->p = UINT64_MAX;

    kv_push(uint64_t, b->S, v0);

    while (b->S.n > 0 && max_d <= max_dist) {
        v = kv_pop(b->S);
        nv = asmg_arc_n(g, v);
        av = asmg_arc_a(g, v);
        d = b->a[v].d;
        c = b->a[v].c;
        if (b->S.n == 0 && n_pending == 0) { // a sink vertex
            b->dist = d;
            b->v_sink = v;
            if (v != v0) { // exclude the input vertex
                ++b->n_sink;
                if (!(thru_flag & ASMG_TE_THRU_BUBBLE))
                    break;
            }
        }

        if (asmg_arc_n1(g, v) == 0) { // a tip
            if (d + g->vtx[v>>1].len < max_dist) {
                // a tip shorter than max_dist
                if (b->S.n || n_pending)
                    // don't count a tip if it is the end of a bubble chain
                    ++b->n_short_tip;
                if (thru_flag & ASMG_TE_THRU_SHORT_TIP) continue;
                else break;
            } else break; // if we come here, we have a tip beyond max_dist; we stop
        }

        for (i = 0; i < nv; ++i) { // loop through v's neighbors
            if (av[i].del)
                continue;
            w = av[i].w;
            l = g->vtx[v>>1].len - av[i].ls;
            a = g->vtx[v>>1].cov * l;
            t = &b->a[w];
            if (w>>1 == v0>>1) {
                // cycle or bidirected cycle involving the input vertex
                b->self_cycle |= w == v0? 1 : 2;
                break;
            }
            kv_push(uint64_t, b->e, g->idx_p[v] + i); // TODO save the edge
            if (t->s == 0) { // this vertex has never been visited
                kv_push(uint64_t, b->b, w); // save it for asmg_tbuf_reset()
                t->p = v, t->s = 1, t->d = d + l, t->c = c + a;
                t->r = asmg_arc_n1(g, w^1);
                ++n_pending;
            } else { // visited before
                if (c + a > t->c || (c + a == t->c && d + l > t->d)) t->p = v;
                if (c + a > t->c) t->c = c + a;
                if (d + l < t->d) t->d = d + l; // update dist
            }
            max_d = max_d > t->d? max_d : t->d;
            assert(t->r > 0);
            assert(n_pending > 0);
            if (--(t->r) == 0) {
                kv_push(uint64_t, b->S, w);
                --n_pending;
            }
        }
        if (i < nv) break;
    }
    return b->n_sink;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
shrq %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x24c0f
movq $0x0, -0x8(%rbp)
jmp 0x25477
movq $0x0, -0x80(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x30(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x30(%rbp), %rax
movb $0x0, 0x70(%rax)
movq -0x30(%rbp), %rax
movq $-0x1, 0x68(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq 0x18(%rax), %rcx
orq $0x0, %rcx
movq %rcx, 0x18(%rax)
movq -0x88(%rbp), %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
andq 0x18(%rax), %rcx
orq $0x0, %rcx
movq %rcx, 0x18(%rax)
movq -0x88(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x88(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x88(%rbp), %rax
movq $-0x1, (%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x24d6c
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x24d2b
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x98(%rbp)
jmp 0x24d39
movl $0x2, %eax
movq %rax, -0x98(%rbp)
jmp 0x24d39
movq -0x98(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rsi
movq 0x8(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x8(%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x24d91
movq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, 0x8(%rcx)
movb %al, -0x99(%rbp)
jbe 0x24db5
movq -0x80(%rbp), %rax
cmpq -0x20(%rbp), %rax
setbe %al
movb %al, -0x99(%rbp)
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x24dc4
jmp 0x2546b
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $-0x1, %rsi
movq %rsi, 0x8(%rdx)
movq -0x8(%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq -0x40(%rbp), %rdx
imulq $0x30, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x24eab
cmpq $0x0, -0x78(%rbp)
jne 0x24eab
movq -0x60(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x24ea9
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x58(%rax)
movl -0x24(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x24ea7
jmp 0x2546b
jmp 0x24ea9
jmp 0x24eab
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x21690
cmpq $0x0, %rax
jne 0x24f1e
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x40(%rbp), %rdx
shrq %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
addq 0x18(%rcx), %rax
cmpq -0x20(%rbp), %rax
jae 0x24f19
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x24ef4
cmpq $0x0, -0x78(%rbp)
je 0x24f04
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x50(%rax)
movl -0x24(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x24f14
jmp 0x24d91
jmp 0x2546b
jmp 0x2546b
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0x2545a
movq -0x90(%rbp), %rax
imulq $0x30, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x24f56
jmp 0x25449
movq -0x90(%rbp), %rax
imulq $0x30, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
shrq %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq -0x90(%rbp), %rcx
imulq $0x30, -0x38(%rbp), %rdx
addq %rdx, %rcx
subq 0x18(%rcx), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
shrq %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
imulq -0x50(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x48(%rbp), %rax
shrq %rax
movq -0x18(%rbp), %rcx
shrq %rcx
cmpq %rcx, %rax
jne 0x2501d
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rsi
movl $0x2, %edx
movl $0x1, %eax
cmpq %rsi, %rcx
cmovel %eax, %edx
movq -0x30(%rbp), %rax
movzbl 0x70(%rax), %ecx
orl %edx, %ecx
movb %cl, 0x70(%rax)
jmp 0x2545a
jmp 0x2501f
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jne 0x25091
movq -0x30(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x25050
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
shlq %rax
movq %rax, -0xa8(%rbp)
jmp 0x2505e
movl $0x2, %eax
movq %rax, -0xa8(%rbp)
jmp 0x2505e
movq -0xa8(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x30(%rbp), %rsi
movq 0x38(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x38(%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x88(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
jne 0x2521e
jmp 0x250de
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jne 0x25150
movq -0x30(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x2510f
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
shlq %rax
movq %rax, -0xb0(%rbp)
jmp 0x2511d
movl $0x2, %eax
movq %rax, -0xb0(%rbp)
jmp 0x2511d
movq -0xb0(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x30(%rbp), %rsi
movq 0x20(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x20(%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rcx
movq -0x88(%rbp), %rax
movq %rcx, (%rax)
movq -0x88(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq 0x18(%rax), %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x60(%rbp), %rcx
addq -0x50(%rbp), %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x68(%rbp), %rcx
addq -0x70(%rbp), %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
xorq $0x1, %rsi
callq 0x21690
movq %rax, %rdx
movq -0x88(%rbp), %rax
movq 0x18(%rax), %rcx
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
andq %rsi, %rdx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x252bd
movq -0x68(%rbp), %rax
addq -0x70(%rbp), %rax
movq -0x88(%rbp), %rcx
cmpq 0x10(%rcx), %rax
ja 0x2525d
movq -0x68(%rbp), %rax
addq -0x70(%rbp), %rax
movq -0x88(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2526b
movq -0x60(%rbp), %rax
addq -0x50(%rbp), %rax
movq -0x88(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x2526b
movq -0x40(%rbp), %rcx
movq -0x88(%rbp), %rax
movq %rcx, (%rax)
movq -0x68(%rbp), %rax
addq -0x70(%rbp), %rax
movq -0x88(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jbe 0x25293
movq -0x68(%rbp), %rcx
addq -0x70(%rbp), %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
addq -0x50(%rbp), %rax
movq -0x88(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x252bb
movq -0x60(%rbp), %rcx
addq -0x50(%rbp), %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x252bd
movq -0x80(%rbp), %rax
movq -0x88(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x252db
movq -0x80(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x252ed
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x88(%rbp), %rcx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
andq 0x18(%rcx), %rax
cmpq $0x0, %rax
jbe 0x25315
jmp 0x25334
leaq 0x9989(%rip), %rdi      # 0x2eca5
leaq 0x98be(%rip), %rsi      # 0x2ebe1
movl $0x236, %edx            # imm = 0x236
leaq 0x997f(%rip), %rcx      # 0x2ecae
callq 0x21e0
cmpq $0x0, -0x78(%rbp)
jbe 0x2533d
jmp 0x2535c
leaq 0x99b7(%rip), %rdi      # 0x2ecfb
leaq 0x9896(%rip), %rsi      # 0x2ebe1
movl $0x237, %edx            # imm = 0x237
leaq 0x9957(%rip), %rcx      # 0x2ecae
callq 0x21e0
movq -0x88(%rbp), %rcx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
andq 0x18(%rcx), %rax
addq $-0x1, %rax
movq 0x18(%rcx), %rdx
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
andq %rsi, %rax
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
andq %rsi, %rdx
orq %rax, %rdx
movq %rdx, 0x18(%rcx)
cmpq $0x0, %rax
jne 0x25447
jmp 0x253a6
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x25418
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x253d7
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xc0(%rbp)
jmp 0x253e5
movl $0x2, %eax
movq %rax, -0xc0(%rbp)
jmp 0x253e5
movq -0xc0(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rsi
movq 0x8(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x8(%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x78(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x25449
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x24f26
movq -0x38(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0x25466
jmp 0x2546b
jmp 0x24d91
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)