// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %r9, %rbx
movq %r8, 0x40(%rsp)
movq %rcx, %r15
movq 0xa8(%rsp), %rax
movq 0xa0(%rsp), %rcx
andl $0x0, (%rax)
andl $0x0, (%rcx)
movl 0x88(%rsp), %r13d
xorl %r12d, %r12d
testq %rsi, %rsi
movl $0x0, %r14d
cmovgq %rsi, %r14
xorl %eax, %eax
cmpq %rax, %r14
je 0x131c7
xorl %ecx, %ecx
cmpl %r13d, (%rdx,%rax,4)
setge %cl
addq %rcx, %r12
incq %rax
jmp 0x131b1
testq %r12, %r12
je 0x13482
movq %rsi, 0x28(%rsp)
movq %r12, %rsi
shlq $0x4, %rsi
movq %rdi, 0x30(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
callq 0x266c
movq 0x18(%rsp), %rdi
movq %rax, %rbp
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x13223
movslq (%rdi,%rcx,4), %rdx
cmpl %r13d, %edx
jl 0x1321e
movq %rax, %rsi
shlq $0x4, %rsi
movq %rdx, (%rbp,%rsi)
incq %rax
movq %rcx, 0x8(%rbp,%rsi)
incq %rcx
jmp 0x131fc
movq 0x10(%rsp), %rsi
addq %rbp, %rsi
movq %rbp, %rdi
callq 0xcb7f
movq 0x28(%rsp), %rdx
shlq $0x2, %rdx
movq $0x0, 0x8(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movq %rdx, 0x28(%rsp)
callq 0x2180
decq %r12
movslq 0x80(%rsp), %rax
movq %rax, 0x38(%rsp)
xorl %esi, %esi
movq %r12, %r14
testq %r14, %r14
js 0x13325
movq %r14, %rax
shlq $0x4, %rax
movq 0x8(%rbp,%rax), %rcx
cmpl $0x0, (%rbx,%rcx,4)
jne 0x1331d
movq %rsi, 0x10(%rsp)
leaq (%rax,%rbp), %rcx
movq %rcx, 0x20(%rsp)
leaq (%rax,%rbp), %r13
addq $0x8, %r13
movl 0x90(%rsp), %edi
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %r14, %r9
callq 0x134b0
xorl %ecx, %ecx
movq (%r13), %rdx
cmpq %rax, %rdx
je 0x132d6
movl $0x1, (%rbx,%rdx,4)
leaq (%r15,%rdx,8), %r13
incq %rcx
jmp 0x132bd
movq 0x20(%rsp), %rdx
movl (%rdx), %edx
testq %rax, %rax
js 0x132ea
movq 0x18(%rsp), %rsi
subl (%rsi,%rax,4), %edx
movl 0x88(%rsp), %eax
movq 0x10(%rsp), %rsi
cmpl %eax, %edx
jl 0x1331d
leaq (%rsi,%rcx), %rax
cmpq %rsi, %rax
jle 0x1331d
xorl %edx, %edx
cmpq 0x38(%rsp), %rcx
setge %dl
cmovgeq %rax, %rsi
movq 0x8(%rsp), %rax
addl %edx, %eax
movq %rax, 0x8(%rsp)
decq %r14
jmp 0x13269
movq 0x8(%rsp), %rax
addl 0x98(%rsp), %eax
movslq %eax, %rsi
shlq $0x3, %rsi
movq 0x30(%rsp), %rdi
callq 0x266c
movq %rax, 0x8(%rsp)
movq $0x0, 0x20(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movq 0x28(%rsp), %rdx
callq 0x2180
xorl %r14d, %r14d
movq 0x18(%rsp), %rdx
testq %r12, %r12
js 0x1344b
movq %r12, %rax
shlq $0x4, %rax
movq 0x8(%rbp,%rax), %rcx
cmpl $0x0, (%rbx,%rcx,4)
jne 0x1341c
leaq (%rax,%rbp), %rcx
movq %rcx, 0x10(%rsp)
leaq (%rax,%rbp), %r13
addq $0x8, %r13
movl 0x90(%rsp), %edi
movq %rbp, %rsi
movq %r15, %rcx
movq %rbx, %r8
movq %r12, %r9
callq 0x134b0
movq 0x40(%rsp), %rcx
leaq (%rcx,%r14,4), %rdx
xorl %ecx, %ecx
movq (%r13), %rsi
cmpq %rax, %rsi
je 0x133d6
movl %esi, (%rdx,%rcx,4)
movl $0x1, (%rbx,%rsi,4)
leaq (%r15,%rsi,8), %r13
incq %rcx
jmp 0x133ba
movq 0x10(%rsp), %rdx
movl (%rdx), %r8d
testq %rax, %rax
js 0x133ee
movq 0x18(%rsp), %rdx
subl (%rdx,%rax,4), %r8d
jmp 0x133f3
movq 0x18(%rsp), %rdx
movl 0x88(%rsp), %esi
leaq (%r14,%rcx), %rax
cmpl %esi, %r8d
setge %sil
cmpq %r14, %rax
setg %dil
andb %sil, %dil
cmpb $0x1, %dil
jne 0x1341c
cmpq 0x38(%rsp), %rcx
jge 0x1342a
movq %r14, %rax
decq %r12
movq %rax, %r14
jmp 0x13367
shlq $0x20, %r8
orq %rcx, %r8
movq 0x20(%rsp), %rsi
movslq %esi, %rcx
incl %esi
movq %rsi, 0x20(%rsp)
movq 0x8(%rsp), %rsi
movq %r8, (%rsi,%rcx,8)
jmp 0x1341f
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x2577
cmpq $0x7fffffff, %r14       # imm = 0x7FFFFFFF
jge 0x13493
movq 0xa0(%rsp), %rax
movq 0x20(%rsp), %rcx
movl %ecx, (%rax)
movq 0xa8(%rsp), %rax
movl %r14d, (%rax)
movq 0x8(%rsp), %rax
jmp 0x13484
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10dc6(%rip), %rdi     # 0x24260
leaq 0x10dcf(%rip), %rsi     # 0x24270
leaq 0x10dd1(%rip), %rcx     # 0x24279
pushq $0x4a
popq %rdx
callq 0x2160