// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %r8, 0x40(%rsp)
movq %rcx, %r12
movq %rsi, %r8
movq %rdi, %r15
movq 0xa8(%rsp), %rax
movq 0xa0(%rsp), %rcx
movl 0x88(%rsp), %esi
xorl %ebp, %ebp
movl %ebp, (%rax)
movl %ebp, (%rcx)
testq %r8, %r8
jle 0x15d14
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 0x15d01
testq %rbp, %rbp
je 0x15fc4
movq %rbp, %rbx
shlq $0x4, %rbx
movq %r15, %rdi
movq %rbx, %rsi
movq %rdx, 0x18(%rsp)
movq %r8, %r13
callq 0x31c1
movq %r13, %r10
movl 0x88(%rsp), %r8d
movq 0x18(%rsp), %rdi
testq %r13, %r13
jle 0x15d75
xorl %r9d, %r9d
xorl %ecx, %ecx
movslq (%rdi,%r9,4), %rdx
cmpl %r8d, %edx
jl 0x15d6d
movq %rcx, %rsi
shlq $0x4, %rsi
movq %rdx, (%rax,%rsi)
incq %rcx
movq %r9, 0x8(%rax,%rsi)
incq %r9
cmpq %r9, %r10
jne 0x15d51
movq %r15, 0x28(%rsp)
addq %rax, %rbx
movq %rax, %rdi
movq %rbx, %rsi
movq %rax, 0x10(%rsp)
movq %r10, %rbx
callq 0xeec3
shlq $0x2, %rbx
movq $0x0, 0x20(%rsp)
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, 0x38(%rsp)
movq %rbx, %rdx
callq 0x2180
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq -0x1(%rbp), %r15
movslq 0x80(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0x0, 0x4(%rsp)
testq %rbp, %rbp
jle 0x15ea0
xorl %r9d, %r9d
movq %r15, %rbx
movl $0x0, 0x4(%rsp)
movq %rbx, %r13
shlq $0x4, %r13
movq 0x8(%rsi,%r13), %rax
cmpl $0x0, (%r14,%rax,4)
jne 0x15e90
movq %r9, 0x8(%rsp)
addq %rsi, %r13
movl 0x90(%rsp), %edi
movq %r12, %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x1602e
movq 0x8(%r13), %r8
cmpq %rax, %r8
jne 0x15e37
movq 0x8(%rsp), %r9
movq %r9, %rcx
movl 0x88(%rsp), %edi
jmp 0x15e5a
movq 0x8(%rsp), %r9
movq %r9, %rcx
movl 0x88(%rsp), %edi
incq %rcx
movl $0x1, (%r14,%r8,4)
movq (%r12,%r8,8), %r8
cmpq %rax, %r8
jne 0x15e46
movl (%r13), %eax
testq %r8, %r8
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rsi
js 0x15e71
subl (%rdx,%r8,4), %eax
cmpl %edi, %eax
jl 0x15e90
movq %rcx, %rax
subq %r9, %rax
jle 0x15e90
xorl %edi, %edi
cmpq 0x30(%rsp), %rax
setge %dil
cmovgeq %rcx, %r9
addl %edi, 0x4(%rsp)
leaq -0x1(%rbx), %rax
testq %rbx, %rbx
movq %rax, %rbx
jg 0x15de9
movl 0x4(%rsp), %eax
addl 0x98(%rsp), %eax
movslq %eax, %rsi
shlq $0x3, %rsi
movq 0x28(%rsp), %rdi
callq 0x31c1
movq %rax, 0x8(%rsp)
movq %r14, %rdi
xorl %esi, %esi
movq 0x38(%rsp), %rdx
callq 0x2180
testq %rbp, %rbp
jle 0x15fc8
xorl %ebp, %ebp
movq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq %r15, %r13
shlq $0x4, %r13
movq 0x8(%rsi,%r13), %rax
cmpl $0x0, (%r14,%rax,4)
jne 0x15f8b
addq %rsi, %r13
movl 0x90(%rsp), %edi
movq %r12, %rcx
movq %r14, %r8
movq %r15, %r9
callq 0x1602e
movq 0x8(%r13), %rcx
movq %rbp, %rbx
cmpq %rax, %rcx
jne 0x15f32
movl 0x88(%rsp), %edi
jmp 0x15f55
movq 0x40(%rsp), %rdx
movl 0x88(%rsp), %edi
movl %ecx, (%rdx,%rbx,4)
incq %rbx
movl $0x1, (%r14,%rcx,4)
movq (%r12,%rcx,8), %rcx
cmpq %rax, %rcx
jne 0x15f3e
movl (%r13), %eax
testq %rcx, %rcx
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rsi
js 0x15f6b
subl (%rdx,%rcx,4), %eax
cmpl %edi, %eax
setge %dil
movq %rbx, %rcx
subq %rbp, %rcx
setg %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0x15f8b
cmpq 0x30(%rsp), %rcx
jge 0x15fa3
movq %rbp, %rbx
leaq -0x1(%r15), %rax
movq %rbx, %rbp
testq %r15, %r15
movq %rax, %r15
jg 0x15eee
jmp 0x15fcf
shlq $0x20, %rax
orq %rcx, %rax
movq 0x20(%rsp), %rdi
movslq %edi, %rcx
incl %edi
movq %rdi, 0x20(%rsp)
movq 0x8(%rsp), %rdi
movq %rax, (%rdi,%rcx,8)
jmp 0x15f8e
xorl %eax, %eax
jmp 0x16000
xorl %ebx, %ebx
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdi
callq 0x30f6
cmpq $0x7fffffff, %rbx       # imm = 0x7FFFFFFF
jge 0x1600f
movq 0xa0(%rsp), %rax
movq 0x20(%rsp), %rcx
movl %ecx, (%rax)
movq 0xa8(%rsp), %rax
movl %ebx, (%rax)
movq 0x8(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x131ea(%rip), %rdi     # 0x29200
leaq 0x131f3(%rip), %rsi     # 0x29210
leaq 0x131f5(%rip), %rcx     # 0x29219
movl $0x4a, %edx
callq 0x2160