// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movl %ecx, %ebx
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r13
movl $0x1, %esi
movl $0x28, %edx
callq 0x2f84
movq %r13, 0x20(%rax)
movq 0x28(%r12), %rcx
cmpq 0x30(%r12), %rcx
movq %rax, (%rsp)
jne 0xa953
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x30(%r12)
movq 0x38(%r12), %rdi
shlq $0x3, %rsi
callq 0x22b0
movq (%rsp), %r9
movq %rax, 0x38(%r12)
movq 0x28(%r12), %rcx
jmp 0xa95b
movq %rax, %r9
movq 0x38(%r12), %rax
movq %rbx, %rdx
shlq $0x20, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x28(%r12)
movq %rdx, (%rax,%rcx,8)
movq 0x28(%r12), %rax
testq %rax, %rax
je 0xacdd
xorl %r8d, %r8d
movl $0x2, %r14d
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq %rbx, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq 0x38(%r12), %rcx
leaq -0x1(%rax), %rdx
movq %rdx, 0x28(%r12)
movq -0x8(%rcx,%rax,8), %r15
movq %r15, %rbp
shrq $0x20, %rbp
testl %r15d, %r15d
jne 0xaa3f
movl (%r12), %eax
leal 0x1(%rax), %ecx
movl %ecx, (%r12)
movq 0x8(%r12), %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(%r12), %rax
orl %edi, 0x4(%rax,%rdx)
movq 0x10(%r12), %rcx
movq 0x20(%r12), %rax
cmpq 0x18(%r12), %rcx
jne 0xaa33
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r14, %rsi
movq %rsi, 0x18(%r12)
shlq $0x2, %rsi
movq %rax, %rdi
movl %r8d, %ebx
callq 0x22b0
movl %ebx, %r8d
movq (%rsp), %r9
movq %rax, 0x20(%r12)
movq 0x10(%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x10(%r12)
movl %ebp, (%rax,%rcx,4)
movq 0x10(%rsp), %rcx
movq 0x58(%rcx), %rax
movq (%rax,%rbp,8), %rax
cmpl %eax, %r15d
jne 0xab29
movq 0x8(%r12), %rax
movq %rbp, %rdx
shlq $0x4, %rdx
movl 0x4(%rax,%rdx), %ecx
andl %r13d, %ecx
movq %rdx, 0x18(%rsp)
cmpl (%rax,%rdx), %ecx
jne 0xac00
movl 0x10(%r12), %r13d
movq 0x20(%r12), %rax
movl %r13d, %r15d
decl %r15d
movslq %r15d, %r14
cmpl %ebp, (%rax,%r14,4)
jne 0xaa83
jmp 0xab06
movq 0x20(%r12), %rax
movslq %r13d, %rcx
movl (%rax,%rcx,4), %ebp
movl (%r9), %ecx
movq 0x10(%r9), %rax
cmpl %r8d, %ecx
jne 0xaae5
movq %r12, %rbx
movl %r8d, %r12d
shrl %r12d
addl %r8d, %r12d
cmpl $0x4, %r8d
movl $0x10, %ecx
cmovbl %ecx, %r12d
movq 0x20(%r9), %rdi
movq %r12, %rdx
shlq $0x4, %rdx
movq %rax, %rsi
callq 0x31ed
movq (%rsp), %r9
movq %rax, 0x10(%r9)
movl (%r9), %ecx
movl %r12d, %r8d
movq %rbx, %r12
leal 0x1(%rcx), %edx
movl %edx, (%r9)
movslq %ecx, %rcx
shlq $0x4, %rcx
movl %ebp, (%rax,%rcx)
movq 0x8(%r12), %rax
shlq $0x4, %rbp
andl $0x7fffffff, 0x4(%rax,%rbp) # imm = 0x7FFFFFFF
decl %r13d
cmpl %r15d, %r13d
jge 0xaa91
movq %r14, 0x10(%r12)
movq 0x8(%rsp), %rbx
movl $0x2, %r14d
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
jmp 0xac05
shrq $0x1b, %rax
andq $-0x20, %rax
addq 0x48(%rcx), %rax
movl %r15d, %ecx
shlq $0x5, %rcx
movl 0x8(%rcx,%rax), %r10d
movq 0x28(%r12), %rcx
movq 0x38(%r12), %rax
cmpq 0x30(%r12), %rcx
jne 0xab8e
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r14, %rsi
movq %rsi, 0x30(%r12)
shlq $0x3, %rsi
movq %rax, %rdi
movl %r8d, %ebx
movq %r10, %r14
callq 0x22b0
movq %r14, %r10
movl $0x2, %r14d
movl %ebx, %r8d
movq (%rsp), %r9
movq %rax, 0x38(%r12)
movq 0x28(%r12), %rcx
movq %r15, %rdx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
andq %rsi, %rdx
incl %r15d
orq %rdx, %r15
leaq 0x1(%rcx), %rdx
movq %rdx, 0x28(%r12)
movq %r15, (%rax,%rcx,8)
movq 0x8(%r12), %rcx
movq %r10, %rsi
shlq $0x4, %rsi
movl (%rcx,%rsi), %edx
cmpl $-0x1, %edx
je 0xac60
addq %rcx, %rsi
cmpl $0x0, 0x4(%rsi)
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %r15
jns 0xac50
shlq $0x4, %rbp
movl 0x4(%rcx,%rbp), %eax
movl %eax, %esi
andl %r13d, %esi
movl %edx, %edi
andl %r13d, %edi
cmpl %edx, %esi
cmovbl %esi, %edi
andl $0x80000000, %eax       # imm = 0x80000000
orl %edi, %eax
movl %eax, 0x4(%rcx,%rbp)
jmp 0xac50
movq 0x8(%rsp), %rbx
movq 0x28(%r12), %rax
testq %rax, %rax
movq 0x10(%rsp), %r15
je 0xacdd
movq 0x8(%r12), %rcx
movq 0x38(%r12), %rdx
movl -0x4(%rdx,%rax,8), %eax
shlq $0x4, %rax
movl 0x4(%rcx,%rax), %edx
movl %edx, %esi
andl %r13d, %esi
movq 0x18(%rsp), %rdi
movl 0x4(%rcx,%rdi), %edi
andl %r13d, %edi
cmpl %edi, %esi
cmovbl %esi, %edi
andl $0x80000000, %edx       # imm = 0x80000000
orl %edi, %edx
movl %edx, 0x4(%rcx,%rax)
movq 0x28(%r12), %rax
testq %rax, %rax
jne 0xa996
jmp 0xacdd
movl %r10d, %edi
xorl $0x1, %edi
shlq $0x4, %rdi
cmpl $0x0, 0x4(%rcx,%rdi)
js 0xabc9
movq 0x28(%r12), %rcx
cmpq 0x30(%r12), %rcx
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %r15
jne 0xacc7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r14, %rsi
movq %rsi, 0x30(%r12)
shlq $0x3, %rsi
movq %rax, %rdi
movl %r8d, %ebp
movq %r10, %r14
callq 0x22b0
movq %r14, %r10
movl $0x2, %r14d
movl %ebp, %r8d
movq (%rsp), %r9
movq %rax, 0x38(%r12)
movq 0x28(%r12), %rcx
shlq $0x20, %r10
leaq 0x1(%rcx), %rdx
movq %rdx, 0x28(%r12)
movq %r10, (%rax,%rcx,8)
jmp 0xac50
movl (%r9), %ecx
cmpl $0x2, %ecx
jb 0xad34
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %edx, %edx
xorl %esi, %esi
movq 0x10(%r9), %rdi
movups (%rdi,%rdx), %xmm0
movaps %xmm0, 0x20(%rsp)
addl %eax, %ecx
shlq $0x4, %rcx
movups (%rdi,%rcx), %xmm0
movups %xmm0, (%rdi,%rdx)
movq 0x10(%r9), %rcx
movl (%r9), %edi
addl %eax, %edi
shlq $0x4, %rdi
movaps 0x20(%rsp), %xmm0
movups %xmm0, (%rcx,%rdi)
incq %rsi
movl (%r9), %ecx
movl %ecx, %edi
sarl %edi
addq $0x10, %rdx
decl %eax
cmpq %rdi, %rsi
jb 0xacee
testl %ecx, %ecx
je 0xadd4
movq 0x8(%r12), %rdx
movq 0x10(%r9), %rsi
movl %ecx, %eax
xorl %edi, %edi
movl (%rsi), %r8d
shlq $0x4, %r8
movl %ebx, 0xc(%rdx,%r8)
movl %edi, 0x8(%rdx,%r8)
incq %rdi
addq $0x10, %rsi
cmpq %rdi, %rax
jne 0xad49
testl %ecx, %ecx
je 0xadd4
movq 0x10(%r9), %rdx
movq 0x48(%r15), %rsi
movq 0x58(%r15), %rdi
addq $0x8, %rsi
xorl %r8d, %r8d
xorl %ecx, %ecx
movq %r8, %r9
shlq $0x4, %r9
movl (%rdx,%r9), %r9d
movq (%rdi,%r9,8), %r9
testl %r9d, %r9d
jle 0xadca
movq %r9, %r10
shrq $0x20, %r10
movq 0x8(%r12), %r11
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
shlq $0x5, %r10
addq %rsi, %r10
movl (%r10), %r14d
shlq $0x4, %r14
xorl %ebp, %ebp
cmpl %ebx, 0xc(%r11,%r14)
sete %bpl
addl %ebp, %ecx
addq $0x20, %r10
decq %r9
jne 0xadad
incq %r8
cmpq %rax, %r8
jne 0xad7f
jmp 0xadd6
xorl %ecx, %ecx
movq (%rsp), %r14
movl %ecx, 0x4(%r14)
movq 0x20(%r14), %rdi
movslq %ecx, %rsi
movl $0x8, %edx
callq 0x2f84
movq %r14, %rdx
movq %rax, 0x18(%r14)
cmpl $0x0, (%r14)
je 0xaec9
xorl %r13d, %r13d
xorl %ebp, %ebp
movl %ebp, %ecx
movq 0x10(%rdx), %rdx
movq %r13, %rsi
shlq $0x4, %rsi
movl (%rdx,%rsi), %edi
movq 0x58(%r15), %r8
movq (%r8,%rdi,8), %rdi
testl %edi, %edi
jle 0xae74
movq 0x48(%r15), %r8
movq %rdi, %r9
shrq $0x20, %r9
movq 0x8(%r12), %r10
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
shlq $0x5, %r9
movl %ecx, %ebp
movl 0x8(%r8,%r9), %r11d
shlq $0x4, %r11
cmpl %ebx, 0xc(%r10,%r11)
jne 0xae6b
addq %r10, %r11
movl 0x8(%r11), %r11d
shlq $0x20, %r11
movq %r9, %r14
sarq $0x5, %r14
orq %r11, %r14
movl %ebp, %r11d
incl %ebp
movq %r14, (%rax,%r11,8)
addq $0x20, %r9
decq %rdi
jne 0xae3d
movl $0x0, 0x4(%rdx,%rsi)
movl %ecx, 0x8(%rdx,%rsi)
movl %ebp, %edi
subl %ecx, %edi
movl %edi, 0xc(%rdx,%rsi)
jbe 0xaeb7
movl %ecx, %r14d
leaq (%rax,%r14,8), %rdi
movl %ebp, %ecx
leaq (%rax,%rcx,8), %rsi
callq 0x47e4
movq (%rsp), %rdx
movq 0x18(%rdx), %rax
movl 0x4(%rax,%r14,8), %ecx
cmpq %r13, %rcx
ja 0xaebb
movl $0x0, 0x8(%rdx)
jmp 0xaebb
movq (%rsp), %rdx
incq %r13
movl (%rdx), %ecx
cmpq %rcx, %r13
jb 0xae05
movq %rdx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq