// File: /workspace/github_c_makefile_star2_O1/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, %r12
movq %rsi, 0x10(%rsp)
movq %rdi, %r13
movl $0x1, %esi
movl $0x28, %edx
callq 0x3054
movq %rax, %r15
movq %r13, 0x20(%rax)
movq 0x30(%r12), %rax
cmpq %rax, 0x28(%r12)
jne 0xa55a
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x30(%r12)
movq 0x38(%r12), %rdi
shlq $0x3, %rsi
callq 0x22b0
movq %rax, 0x38(%r12)
movq %rbx, %rax
shlq $0x20, %rax
movq 0x28(%r12), %rcx
movq 0x38(%r12), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x28(%r12)
movq %rax, (%rdx,%rcx,8)
movq 0x28(%r12), %rax
testq %rax, %rax
movq 0x10(%rsp), %r14
je 0xa8df
xorl %r9d, %r9d
movl $0x2, %r13d
movq %rbx, 0x18(%rsp)
movq %r15, 0x8(%rsp)
movq %r12, 0x28(%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 0xa64a
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 0x18(%r12), %rax
cmpq %rax, 0x10(%r12)
jne 0xa634
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r13, %rsi
movq %rsi, 0x18(%r12)
movq 0x20(%r12), %rdi
shlq $0x2, %rsi
movl %r9d, %ebx
callq 0x22b0
movl %ebx, %r9d
movq %rax, 0x20(%r12)
movq 0x10(%r12), %rax
movq 0x20(%r12), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%r12)
movl %ebp, (%rcx,%rax,4)
movq 0x58(%r14), %rax
movq (%rax,%rbp,8), %rax
cmpl %eax, %r15d
jne 0xa783
movq 0x8(%r12), %rax
movq %rbp, %rsi
shlq $0x4, %rsi
movl 0x4(%rax,%rsi), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
cmpl (%rax,%rsi), %ecx
movq %rsi, 0x20(%rsp)
jne 0xa728
movl 0x10(%r12), %r13d
movq 0x20(%r12), %rax
movl %r13d, %r15d
decl %r15d
movslq %r15d, %r14
cmpl %ebp, (%rax,%r14,4)
jne 0xa68d
decl %r13d
cmpl %r15d, %r13d
jl 0xa718
movq 0x8(%rsp), %rbx
movq 0x20(%r12), %rax
movslq %r13d, %rcx
movl (%rax,%rcx,4), %ebp
cmpl %r9d, (%rbx)
jne 0xa6ec
movl %r9d, %r12d
shrl %r12d
addl %r9d, %r12d
cmpl $0x4, %r9d
movl $0x10, %eax
cmovbl %eax, %r12d
movq 0x10(%rbx), %rsi
movq 0x20(%rbx), %rdi
movq %r12, %rdx
shlq $0x4, %rdx
callq 0x32c4
movq %rax, 0x10(%rbx)
movl %r12d, %r9d
movq 0x28(%rsp), %r12
movq 0x10(%rbx), %rax
movslq (%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%rbx)
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 0xa6a6
movq %r14, 0x10(%r12)
movq 0x10(%rsp), %r14
movl $0x2, %r13d
movq 0x28(%r12), %rax
testq %rax, %rax
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %r15
je 0xa8d1
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
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %esi
movq 0x20(%rsp), %rdi
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 0xa8d1
shrq $0x1b, %rax
andq $-0x20, %rax
addq 0x48(%r14), %rax
movl %r15d, %ecx
shlq $0x5, %rcx
movl 0x8(%rcx,%rax), %r8d
movq 0x30(%r12), %rax
cmpq %rax, 0x28(%r12)
jne 0xa7dc
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r13, %rsi
movq %rsi, 0x30(%r12)
movq 0x38(%r12), %rdi
shlq $0x3, %rsi
movl %r9d, %ebx
movq %r8, %r13
callq 0x22b0
movq %r13, %r8
movl $0x2, %r13d
movl %ebx, %r9d
movq %rax, 0x38(%r12)
movq %r15, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
incl %r15d
orq %rax, %r15
movq 0x28(%r12), %rax
movq 0x38(%r12), %rdi
leaq 0x1(%rax), %rcx
movq %rcx, 0x28(%r12)
movq %r15, (%rdi,%rax,8)
movq 0x8(%r12), %rax
movq %r8, %rdx
shlq $0x4, %rdx
movl (%rax,%rdx), %ecx
cmpl $-0x1, %ecx
je 0xa85f
addq %rax, %rdx
cmpl $0x0, 0x4(%rdx)
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %r15
jns 0xa8d1
shlq $0x4, %rbp
movl 0x4(%rax,%rbp), %edx
movl %edx, %esi
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %esi
movl %ecx, %edi
andl %r8d, %edi
cmpl %ecx, %esi
cmovbl %esi, %edi
andl $0x80000000, %edx       # imm = 0x80000000
orl %edi, %edx
movl %edx, 0x4(%rax,%rbp)
jmp 0xa8d1
movl %r8d, %esi
xorl $0x1, %esi
shlq $0x4, %rsi
cmpl $0x0, 0x4(%rax,%rsi)
js 0xa81d
movq 0x30(%r12), %rax
cmpq %rax, 0x28(%r12)
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %r15
jne 0xa8b6
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r13, %rsi
movq %rsi, 0x30(%r12)
shlq $0x3, %rsi
movl %r9d, %ebp
movq %r8, %r13
callq 0x22b0
movq %r13, %r8
movl $0x2, %r13d
movl %ebp, %r9d
movq %rax, 0x38(%r12)
shlq $0x20, %r8
movq 0x28(%r12), %rax
movq 0x38(%r12), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x28(%r12)
movq %r8, (%rcx,%rax,8)
movq 0x28(%r12), %rax
testq %rax, %rax
jne 0xa5a3
movl (%r15), %eax
cmpl $0x2, %eax
jb 0xa936
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %edx, %edx
xorl %esi, %esi
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
movl (%r15), %eax
movl %eax, %edi
sarl %edi
addq $0x10, %rdx
decl %ecx
cmpq %rdi, %rsi
jb 0xa8f0
testl %eax, %eax
je 0xa9d0
movq 0x8(%r12), %rcx
movq 0x10(%r15), %rdx
movl %eax, %eax
xorl %esi, %esi
movl (%rdx), %edi
shlq $0x4, %rdi
movl %ebx, 0xc(%rcx,%rdi)
movl %esi, 0x8(%rcx,%rdi)
incq %rsi
addq $0x10, %rdx
cmpq %rsi, %rax
jne 0xa94b
movq 0x10(%r15), %rcx
movq 0x48(%r14), %rdx
movq 0x58(%r14), %rsi
addq $0x8, %rdx
xorl %edi, %edi
xorl %r8d, %r8d
movq %rdi, %r9
shlq $0x4, %r9
movl (%rcx,%r9), %r9d
movq (%rsi,%r9,8), %r9
testl %r9d, %r9d
jle 0xa9c6
movq %r9, %r10
shrq $0x20, %r10
movq 0x8(%r12), %r11
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
shlq $0x5, %r10
addq %rdx, %r10
movl (%r10), %r14d
shlq $0x4, %r14
xorl %ebp, %ebp
cmpl %ebx, 0xc(%r11,%r14)
sete %bpl
addl %ebp, %r8d
addq $0x20, %r10
decq %r9
jne 0xa9a8
incq %rdi
cmpq %rax, %rdi
jne 0xa97a
jmp 0xa9d3
xorl %r8d, %r8d
movl %r8d, 0x4(%r15)
movq 0x20(%r15), %rdi
movslq %r8d, %rsi
movl $0x8, %edx
callq 0x3054
movq %rax, 0x18(%r15)
cmpl $0x0, (%r15)
je 0xaac9
xorl %r13d, %r13d
xorl %ebp, %ebp
movl %ebp, %eax
movq 0x10(%r15), %rcx
movq %r13, %rdx
shlq $0x4, %rdx
movl (%rcx,%rdx), %esi
movq 0x10(%rsp), %rdi
movq 0x58(%rdi), %rdi
movq (%rdi,%rsi,8), %rsi
testl %esi, %esi
jle 0xaa78
movq 0x10(%rsp), %rdi
movq 0x48(%rdi), %rdi
movq %rsi, %r8
shrq $0x20, %r8
movq 0x8(%r12), %r9
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
shlq $0x5, %r8
movl %eax, %ebp
movl 0x8(%rdi,%r8), %r10d
shlq $0x4, %r10
cmpl %ebx, 0xc(%r9,%r10)
jne 0xaa6f
addq %r9, %r10
movl 0x8(%r10), %r10d
shlq $0x20, %r10
movq %r8, %r11
sarq $0x5, %r11
orq %r10, %r11
movq 0x18(%r15), %r10
movl %ebp, %r14d
incl %ebp
movq %r11, (%r10,%r14,8)
addq $0x20, %r8
decq %rsi
jne 0xaa3d
movl $0x0, 0x4(%rcx,%rdx)
movl %eax, 0x8(%rcx,%rdx)
movl %ebp, %esi
subl %eax, %esi
movl %esi, 0xc(%rcx,%rdx)
jbe 0xaaba
movq 0x18(%r15), %rcx
movl %eax, %r14d
leaq (%rcx,%r14,8), %rdi
movl %ebp, %eax
leaq (%rcx,%rax,8), %rsi
callq 0x48ff
movq 0x18(%r15), %rax
movl 0x4(%rax,%r14,8), %eax
cmpq %r13, %rax
ja 0xaaba
movl $0x0, 0x8(%r15)
incq %r13
movl (%r15), %eax
cmpq %rax, %r13
jb 0xa9fb
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq