// File: /workspace/github_c_makefile_star2_O3/lh3[P]minigraph/lchain.c
// Function: mg_chain_backtrack
uint64_t *mg_chain_backtrack(void *km, int64_t n, const int32_t *f, const int64_t *p, int32_t *v, int32_t *t, int32_t min_cnt, int32_t min_sc, int32_t max_drop,
							 int32_t extra_u, int32_t *n_u_, int32_t *n_v_)
{
	mg128_t *z;
	uint64_t *u;
	int64_t i, k, n_z, n_v;
	int32_t n_u;

	*n_u_ = *n_v_ = 0;
	for (i = 0, n_z = 0; i < n; ++i) // precompute n_z
		if (f[i] >= min_sc) ++n_z;
	if (n_z == 0) return 0;
	KMALLOC(km, z, n_z);
	for (i = 0, k = 0; i < n; ++i) // populate z[]
		if (f[i] >= min_sc) z[k].x = f[i], z[k++].y = i;
	radix_sort_128x(z, z + n_z);

	memset(t, 0, n * 4);
	for (k = n_z - 1, n_v = n_u = 0; k >= 0; --k) { // precompute n_u
		if (t[z[k].y] == 0) {
			int64_t n_v0 = n_v, end_i;
			int32_t sc;
			end_i = mg_chain_bk_end(max_drop, z, f, p, t, k);
			for (i = z[k].y; i != end_i; i = p[i])
				++n_v, t[i] = 1;
			sc = i < 0? z[k].x : (int32_t)z[k].x - f[i];
			if (sc >= min_sc && n_v > n_v0 && n_v - n_v0 >= min_cnt)
				++n_u;
			else n_v = n_v0;
		}
	}
	KMALLOC(km, u, n_u + extra_u);
	memset(t, 0, n * 4);
	for (k = n_z - 1, n_v = n_u = 0; k >= 0; --k) { // populate u[]
		if (t[z[k].y] == 0) {
			int64_t n_v0 = n_v, end_i;
			int32_t sc;
			end_i = mg_chain_bk_end(max_drop, z, f, p, t, k);
			for (i = z[k].y; i != end_i; i = p[i])
				v[n_v++] = i, t[i] = 1;
			sc = i < 0? z[k].x : (int32_t)z[k].x - f[i];
			if (sc >= min_sc && n_v > n_v0 && n_v - n_v0 >= min_cnt)
				u[n_u++] = (uint64_t)sc << 32 | (n_v - n_v0);
			else n_v = n_v0;
		}
	}
	kfree(km, z);
	assert(n_v < INT32_MAX);
	*n_u_ = n_u, *n_v_ = n_v;
	return u;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r14
movq %rcx, %r15
movq %rsi, %r8
movq 0x98(%rsp), %rsi
movq 0x90(%rsp), %rcx
xorl %eax, %eax
movl %eax, (%rsi)
movl %eax, (%rcx)
testq %r8, %r8
jle 0x1623f
movq %r9, %rbx
movl 0x78(%rsp), %esi
xorl %eax, %eax
xorl %ebp, %ebp
xorl %ecx, %ecx
cmpl %esi, (%rdx,%rax,4)
setge %cl
addq %rcx, %rbp
incq %rax
cmpq %rax, %r8
jne 0x15f91
testq %rbp, %rbp
je 0x1623d
movq %rbp, %r12
shlq $0x4, %r12
movq %rdi, 0x20(%rsp)
movq %r12, %rsi
movq %rdx, (%rsp)
movq %r8, %r13
callq 0x30e5
movq %r13, %r10
movl 0x78(%rsp), %r8d
movq (%rsp), %rdi
testq %r13, %r13
jle 0x16002
xorl %r9d, %r9d
xorl %ecx, %ecx
movslq (%rdi,%r9,4), %rdx
cmpl %r8d, %edx
jl 0x15ffa
movq %rcx, %rsi
shlq $0x4, %rsi
movq %rdx, (%rax,%rsi)
incq %rcx
movq %r9, 0x8(%rax,%rsi)
incq %r9
cmpq %r9, %r10
jne 0x15fde
addq %rax, %r12
movq %rax, %rdi
movq %r12, %rsi
movq %rax, 0x10(%rsp)
movq %r10, %r12
callq 0xf27f
shlq $0x2, %r12
movq $0x0, 0x8(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, 0x30(%rsp)
movq %r12, %rdx
callq 0x2180
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
decq %rbp
movslq 0x70(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %rbp, %r12
movl $0x0, 0x18(%rsp)
movq %r12, %r13
shlq $0x4, %r13
movq 0x8(%rsi,%r13), %rax
cmpl $0x0, (%rbx,%rax,4)
jne 0x160f2
addq %rsi, %r13
movl 0x80(%rsp), %edi
movq %r15, %rcx
movq %rbx, %r8
movq %r12, %r9
callq 0x1626d
movq 0x8(%r13), %rdx
movq 0x8(%rsp), %r9
movq %r9, %rcx
cmpq %rax, %rdx
je 0x160ad
movq %r9, %rcx
incq %rcx
movl $0x1, (%rbx,%rdx,4)
movq (%r15,%rdx,8), %rdx
cmpq %rax, %rdx
jne 0x1609a
movl (%r13), %r8d
testq %rax, %rax
movl 0x78(%rsp), %edi
js 0x160c4
movq (%rsp), %rdx
subl (%rdx,%rax,4), %r8d
jmp 0x160c8
movq (%rsp), %rdx
movq 0x10(%rsp), %rsi
cmpl %edi, %r8d
jl 0x160f2
movq %rcx, %rax
subq %r9, %rax
jle 0x160f2
xorl %edi, %edi
cmpq 0x28(%rsp), %rax
setge %dil
cmovgeq %rcx, %r9
movq %r9, 0x8(%rsp)
addl %edi, 0x18(%rsp)
leaq -0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
jg 0x16058
movl 0x18(%rsp), %eax
addl 0x88(%rsp), %eax
movslq %eax, %rsi
shlq $0x3, %rsi
movq 0x20(%rsp), %rdi
callq 0x30e5
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %esi, %esi
movq 0x30(%rsp), %rdx
callq 0x2180
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
movl $0x0, 0x8(%rsp)
movq %rbp, %r13
shlq $0x4, %r13
movq 0x8(%rsi,%r13), %rax
cmpl $0x0, (%rbx,%rax,4)
jne 0x161fa
addq %rsi, %r13
movl 0x80(%rsp), %edi
movq %r15, %rcx
movq %rbx, %r8
movq %rbp, %r9
callq 0x1626d
movq 0x8(%r13), %rdx
movq %r12, %rcx
cmpq %rax, %rdx
je 0x1619b
movq %r12, %rcx
movl %edx, (%r14,%rcx,4)
incq %rcx
movl $0x1, (%rbx,%rdx,4)
movq (%r15,%rdx,8), %rdx
cmpq %rax, %rdx
jne 0x16184
movl (%r13), %r8d
testq %rax, %rax
js 0x161ae
movq (%rsp), %rdx
subl (%rdx,%rax,4), %r8d
jmp 0x161b2
movq (%rsp), %rdx
movq 0x10(%rsp), %rsi
cmpl 0x78(%rsp), %r8d
setge %r9b
movq %rcx, %rax
subq %r12, %rax
setg %dil
andb %r9b, %dil
cmpb $0x1, %dil
jne 0x161fa
cmpq 0x28(%rsp), %rax
jl 0x161fa
shlq $0x20, %r8
orq %rax, %r8
movl 0x8(%rsp), %edi
movslq %edi, %rax
incl %edi
movl %edi, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movq %r8, (%rdi,%rax,8)
movq %rcx, %r12
leaq -0x1(%rbp), %rax
testq %rbp, %rbp
movq %rax, %rbp
jg 0x16147
movq 0x20(%rsp), %rdi
callq 0x301f
cmpq $0x7fffffff, %r12       # imm = 0x7FFFFFFF
jge 0x1624e
movq 0x90(%rsp), %rax
movl 0x8(%rsp), %ecx
movl %ecx, (%rax)
movq 0x98(%rsp), %rax
movl %r12d, (%rax)
movq 0x18(%rsp), %rax
jmp 0x1623f
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12ffb(%rip), %rdi     # 0x29250
leaq 0x13004(%rip), %rsi     # 0x29260
leaq 0x13006(%rip), %rcx     # 0x29269
movl $0x4a, %edx
callq 0x2160