// File: /workspace/github_c_makefile_star2_O2/lh3[P]minigraph/gfa-bbl.c
// Function: gfa_scc1
gfa_sub_t *gfa_scc1(void *km0, const gfa_t *g, gfa_scbuf_t *b, uint32_t v0)
{
	gfa_sub_t *sub;
	uint32_t k, off, m_v = 0;

	KCALLOC(km0, sub, 1);
	sub->km = km0;

	kv_push(uint64_t, b->ds, (uint64_t)v0<<32);
	while (b->ds.n > 0) {
		uint64_t x = kv_pop(b->ds);
		uint32_t i = (uint32_t)x, v = x>>32, nv;
		if (i == 0) { // i is the number of outgoing edges already visited
			b->a[v].low = b->a[v].index = b->index++;
			b->a[v].stack = 1;
			kv_push(uint32_t, b->ts, v);
		}
		nv = gfa_arc_n(g, v);
		if (i == nv) { // done with v
			if (b->a[v].low == b->a[v].index) {
				int32_t i, j = b->ts.n - 1;
				while (b->ts.a[j] != v) --j;
				for (i = b->ts.n - 1; i >= j; --i) {
					uint32_t w = b->ts.a[i];
					gfa_subv_t *p;
					//fprintf(stderr, "V\t%c%s\t%d\t%c%s\t%d\t%d\n", "><"[v&1], g->seg[v>>1].name, i, "><"[w&1], g->seg[w>>1].name, b->a[w^1].stack, b->a[w].index);
					if (sub->n_v == m_v) KEXPAND(sub->km, sub->v, m_v);
					p = &sub->v[sub->n_v++];
					p->v = w;
					b->a[w].stack = 0;
				}
				b->ts.n = j;
			}
			if (b->ds.n > 0) { // if the DFS stack is not empty, update the top element
				uint32_t w = v;
				v = b->ds.a[b->ds.n - 1] >> 32;
				b->a[v].low = b->a[v].low < b->a[w].low? b->a[v].low : b->a[w].low;
			}
		} else { // process v's neighbor av[i].w
			gfa_arc_t *av = gfa_arc_a(g, v);
			uint32_t w = av[i].w;
			kv_push(uint64_t, b->ds, (uint64_t)v<<32 | (i+1)); // update the old top of the stack
			if (b->a[w].index == (uint32_t)-1 && b->a[w^1].stack == 0)
				kv_push(uint64_t, b->ds, (uint64_t)w<<32);
			else if (b->a[w].stack)
				b->a[v].low = b->a[v].low < b->a[w].index? b->a[v].low : b->a[w].index;
		}
	}

	// reverse the vertex array
	for (k = 0; k < sub->n_v>>1; ++k) {
		gfa_subv_t x;
		x = sub->v[k], sub->v[k] = sub->v[sub->n_v - k - 1], sub->v[sub->n_v - k - 1] = x;
	}

	// fill other fields in sub
	for (k = 0; k < sub->n_v; ++k)
		b->a[sub->v[k].v].start = v0, b->a[sub->v[k].v].i = k;
	for (k = 0, off = 0; k < sub->n_v; ++k) { // precompute the length of gfa_sub_t::a[]
		uint32_t v = sub->v[k].v;
		int32_t i, nv = gfa_arc_n(g, v);
		gfa_arc_t *av = gfa_arc_a(g, v);
		for (i = 0; i < nv; ++i)
			if (b->a[av[i].w].start == v0)
				++off;
	}
	sub->n_a = off;
	KCALLOC(sub->km, sub->a, sub->n_a);
	for (k = 0, off = 0; k < sub->n_v; ++k) {
		uint32_t o0, v = sub->v[k].v;
		int32_t i, nv = gfa_arc_n(g, v);
		gfa_arc_t *av = gfa_arc_a(g, v);
		for (i = 0, o0 = off; i < nv; ++i)
			if (b->a[av[i].w].start == v0)
				sub->a[off++] = (uint64_t)b->a[av[i].w].i << 32 | (&av[i] - g->arc);
		sub->v[k].d = 0;
		sub->v[k].off = o0;
		sub->v[k].n = off - o0;
		if (o0 < off) {
			radix_sort_gfa64(&sub->a[o0], &sub->a[off]);
			if (sub->a[o0]>>32 <= k) sub->is_dag = 0;
		}
	}
	return sub;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %ebx
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r13
pushq $0x1
popq %rsi
pushq $0x28
popq %rdx
callq 0x24f0
movq %rax, %r15
movq %r13, 0x20(%rax)
movq 0x28(%r14), %rcx
pushq $0x2
popq %rax
cmpq 0x30(%r14), %rcx
jne 0x88eb
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %rax, %rsi
movq %rsi, 0x30(%r14)
movq 0x38(%r14), %rdi
shlq $0x3, %rsi
callq 0x22b0
movq %rax, 0x38(%r14)
movq 0x28(%r14), %rcx
jmp 0x88ef
movq 0x38(%r14), %rax
movq %r15, 0x10(%rsp)
movq %rbx, %rdx
shlq $0x20, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x28(%r14)
movq %rdx, (%rax,%rcx,8)
movl $0x0, 0xc(%rsp)
movq 0x28(%r14), %rax
testq %rax, %rax
je 0x8c0a
movq 0x38(%r14), %rcx
leaq -0x1(%rax), %rdx
movq %rdx, 0x28(%r14)
movq -0x8(%rcx,%rax,8), %r13
movq %r13, %rbp
shrq $0x20, %rbp
testl %r13d, %r13d
jne 0x89ad
movl (%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, (%r14)
movq 0x8(%r14), %rcx
movq %rbp, %rdx
shlq $0x4, %rdx
movl %eax, (%rcx,%rdx)
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl 0x4(%rcx,%rdx), %esi
movl $0x80000000, %edi       # imm = 0x80000000
andl %edi, %esi
orl %eax, %esi
movl %esi, 0x4(%rcx,%rdx)
movq 0x8(%r14), %rax
orl %edi, 0x4(%rax,%rdx)
movq 0x10(%r14), %rcx
movq 0x20(%r14), %rax
cmpq 0x18(%r14), %rcx
jne 0x89a2
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x18(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x22b0
movq %rax, 0x20(%r14)
movq 0x10(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x10(%r14)
movl %ebp, (%rax,%rcx,4)
movq 0x58(%r12), %rax
movq (%rax,%rbp,8), %rax
cmpl %eax, %r13d
je 0x8ad1
shrq $0x1b, %rax
andq $-0x20, %rax
addq 0x48(%r12), %rax
movl %r13d, %ecx
shlq $0x5, %rcx
movl 0x8(%rcx,%rax), %r15d
movq 0x28(%r14), %rcx
movq 0x38(%r14), %rax
cmpq 0x30(%r14), %rcx
jne 0x8a0c
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x30(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x22b0
movq %rax, 0x38(%r14)
movq 0x28(%r14), %rcx
movq %r13, %rdx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
andq %rsi, %rdx
incl %r13d
orq %rdx, %r13
leaq 0x1(%rcx), %rdx
movq %rdx, 0x28(%r14)
movq %r13, (%rax,%rcx,8)
movq 0x8(%r14), %rcx
movq %r15, %rsi
shlq $0x4, %rsi
movl (%rcx,%rsi), %edx
cmpl $-0x1, %edx
je 0x8a7b
addq %rcx, %rsi
cmpl $0x0, 0x4(%rsi)
jns 0x890f
shlq $0x4, %rbp
movl 0x4(%rcx,%rbp), %eax
movl %eax, %esi
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %esi
movl %edx, %edi
andl %r8d, %edi
cmpl %edx, %esi
cmovbl %esi, %edi
andl $0x80000000, %eax       # imm = 0x80000000
orl %edi, %eax
movl %eax, 0x4(%rcx,%rbp)
jmp 0x890f
movl %r15d, %edi
xorl $0x1, %edi
shlq $0x4, %rdi
cmpl $0x0, 0x4(%rcx,%rdi)
js 0x8a41
movq 0x28(%r14), %rcx
cmpq 0x30(%r14), %rcx
jne 0x8abc
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x30(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x22b0
movq %rax, 0x38(%r14)
movq 0x28(%r14), %rcx
shlq $0x20, %r15
leaq 0x1(%rcx), %rdx
movq %rdx, 0x28(%r14)
movq %r15, (%rax,%rcx,8)
jmp 0x890f
movq 0x8(%r14), %rax
movq %rbp, %rdi
shlq $0x4, %rdi
movl 0x4(%rax,%rdi), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
cmpl (%rax,%rdi), %ecx
jne 0x8bc1
movq %rdi, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movl 0x10(%r14), %edi
movq 0x20(%r14), %rax
movl %edi, %r15d
movl 0xc(%rsp), %edx
decl %r15d
movslq %r15d, %r8
cmpl %ebp, (%rax,%r8,4)
jne 0x8b09
decl %edi
movq %r8, 0x28(%rsp)
cmpl %r15d, %edi
jl 0x8baf
movq 0x20(%r14), %rax
movslq %edi, %rcx
movl (%rax,%rcx,4), %ebp
movq 0x10(%rsp), %r12
movl (%r12), %ecx
movq 0x10(%r12), %rax
cmpl %edx, %ecx
jne 0x8b83
movl %edx, %r13d
shrl %r13d
addl %edx, %r13d
cmpl $0x4, %edx
pushq $0x10
popq %rcx
cmovbl %ecx, %r13d
movl %edi, 0xc(%rsp)
movq 0x20(%r12), %rdi
movq %r13, %rdx
shlq $0x4, %rdx
movq %rax, %rsi
callq 0x2774
movq 0x28(%rsp), %r8
movl 0xc(%rsp), %edi
movq %rax, 0x10(%r12)
movl (%r12), %ecx
movl %r13d, %esi
jmp 0x8b85
movl %edx, %esi
leal 0x1(%rcx), %edx
movl %edx, (%r12)
movslq %ecx, %rcx
shlq $0x4, %rcx
movl %ebp, (%rax,%rcx)
movq 0x8(%r14), %rax
shlq $0x4, %rbp
andl $0x7fffffff, 0x4(%rax,%rbp) # imm = 0x7FFFFFFF
decl %edi
movl %esi, %edx
jmp 0x8b1c
movl %edx, 0xc(%rsp)
movq %r8, 0x10(%r14)
movq 0x20(%rsp), %r12
movq 0x18(%rsp), %rdi
movq 0x28(%r14), %rax
testq %rax, %rax
je 0x890f
movq 0x8(%r14), %rcx
movq 0x38(%r14), %rdx
movl -0x4(%rdx,%rax,8), %eax
shlq $0x4, %rax
movl 0x4(%rcx,%rax), %edx
movl %edx, %esi
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %esi
movl 0x4(%rcx,%rdi), %edi
andl %r8d, %edi
cmpl %edi, %esi
cmovbl %esi, %edi
andl $0x80000000, %edx       # imm = 0x80000000
orl %edi, %edx
movl %edx, 0x4(%rcx,%rax)
jmp 0x890f
pushq $-0x1
popq %rcx
xorl %edx, %edx
xorl %esi, %esi
movq 0x10(%rsp), %r15
movl (%r15), %eax
movl %eax, %edi
sarl %edi
cmpq %rdi, %rsi
jae 0x8c5e
movq 0x10(%r15), %rdi
movups (%rdi,%rdx), %xmm0
movaps %xmm0, 0x30(%rsp)
addl %ecx, %eax
shlq $0x4, %rax
movups (%rdi,%rax), %xmm0
movups %xmm0, (%rdi,%rdx)
movq 0x10(%r15), %rax
movl (%r15), %edi
addl %ecx, %edi
shlq $0x4, %rdi
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rax,%rdi)
incq %rsi
decl %ecx
addq $0x10, %rdx
jmp 0x8c16
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x8c87
movq 0x8(%r14), %rsi
movq 0x10(%r15), %rdi
movl (%rdi,%rcx), %edi
shlq $0x4, %rdi
movl %ebx, 0xc(%rsi,%rdi)
movl %edx, 0x8(%rsi,%rdi)
incq %rdx
addq $0x10, %rcx
jmp 0x8c62
xorl %edx, %edx
xorl %ecx, %ecx
cmpq %rax, %rdx
je 0x8cf9
movq 0x10(%r15), %rsi
movq %rdx, %rdi
shlq $0x4, %rdi
movl (%rsi,%rdi), %esi
movq 0x48(%r12), %rdi
movq 0x58(%r12), %r8
movq (%r8,%rsi,8), %r8
testl %r8d, %r8d
movl $0x0, %esi
cmovgl %r8d, %esi
shlq $0x5, %rsi
shrq $0x1b, %r8
andq $-0x20, %r8
addq %r8, %rdi
addq $0x8, %rdi
xorl %r8d, %r8d
cmpq %r8, %rsi
je 0x8cf4
movq 0x8(%r14), %r9
movl (%rdi,%r8), %r10d
shlq $0x4, %r10
xorl %r11d, %r11d
cmpl %ebx, 0xc(%r9,%r10)
sete %r11b
addl %r11d, %ecx
addq $0x20, %r8
jmp 0x8cce
incq %rdx
jmp 0x8c8b
movl %ecx, 0x4(%r15)
movq 0x20(%r15), %rdi
movslq %ecx, %rsi
pushq $0x8
popq %rdx
callq 0x24f0
movq %rax, 0x18(%r15)
xorl %r13d, %r13d
xorl %ecx, %ecx
movl (%r15), %edx
cmpq %rdx, %r13
jae 0x8dda
movq 0x10(%r15), %rdx
movq %r13, %rsi
shlq $0x4, %rsi
movl (%rdx,%rsi), %edi
movq 0x58(%r12), %r8
movq (%r8,%rdi,8), %rdi
testl %edi, %edi
movl $0x0, %r8d
cmovgl %edi, %r8d
movq 0x48(%r12), %r9
shrq $0x1b, %rdi
andq $-0x20, %rdi
movl %ecx, %ebp
movl %ebp, %r10d
subq $0x1, %r8
jb 0x8d91
movq 0x8(%r14), %r11
movl 0x8(%r9,%rdi), %r15d
shlq $0x4, %r15
cmpl %ebx, 0xc(%r11,%r15)
jne 0x8d8b
addq %r15, %r11
movl 0x8(%r11), %r11d
shlq $0x20, %r11
movq %rdi, %r15
sarq $0x5, %r15
orq %r11, %r15
incl %ebp
movq %r15, (%rax,%r10,8)
addq $0x20, %rdi
jmp 0x8d53
andl $0x0, 0x4(%rdx,%rsi)
movl %ecx, 0x8(%rdx,%rsi)
movl %ebp, %edi
subl %ecx, %edi
movl %edi, 0xc(%rdx,%rsi)
jbe 0x8dcb
movl %ecx, %r15d
leaq (%rax,%r15,8), %rdi
leaq (%rax,%r10,8), %rsi
callq 0x3d53
movq 0x10(%rsp), %rdx
movq 0x18(%rdx), %rax
movl 0x4(%rax,%r15,8), %ecx
cmpq %r13, %rcx
ja 0x8dcb
andl $0x0, 0x8(%rdx)
incq %r13
movl %ebp, %ecx
movq 0x10(%rsp), %r15
jmp 0x8d15
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq