// File: /workspace/github_c_makefile_star2_O3/lh3[P]minimap2/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 *n_u_, int32_t *n_v_)
{
	mm128_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;
	z = Kmalloc(km, mm128_t, 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;
		}
	}
	u = Kmalloc(km, uint64_t, n_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 0x90(%rsp), %rsi
movq 0x88(%rsp), %rcx
xorl %eax, %eax
movl %eax, (%rsi)
movl %eax, (%rcx)
testq %r8, %r8
jle 0x14d96
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 0x14af1
testq %rbp, %rbp
je 0x14d94
movq %rbp, %r12
shlq $0x4, %r12
movq %rdi, 0x20(%rsp)
movq %r12, %rsi
movq %rdx, (%rsp)
movq %r8, %r13
callq 0x1264d
movq %r13, %r10
movl 0x78(%rsp), %r8d
movq (%rsp), %rdi
testq %r13, %r13
jle 0x14b62
xorl %r9d, %r9d
xorl %ecx, %ecx
movslq (%rdi,%r9,4), %rdx
cmpl %r8d, %edx
jl 0x14b5a
movq %rcx, %rsi
shlq $0x4, %rsi
movq %rdx, (%rax,%rsi)
incq %rcx
movq %r9, 0x8(%rax,%rsi)
incq %r9
cmpq %r9, %r10
jne 0x14b3e
addq %rax, %r12
movq %rax, %rdi
movq %r12, %rsi
movq %rax, 0x10(%rsp)
movq %r10, %r12
callq 0x5a49
shlq $0x2, %r12
movq $0x0, 0x8(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, 0x30(%rsp)
movq %r12, %rdx
callq 0x21b0
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 0x14c52
addq %rsi, %r13
movl 0x80(%rsp), %edi
movq %r15, %rcx
movq %rbx, %r8
movq %r12, %r9
callq 0x14dc4
movq 0x8(%r13), %rdx
movq 0x8(%rsp), %r9
movq %r9, %rcx
cmpq %rax, %rdx
je 0x14c0d
movq %r9, %rcx
incq %rcx
movl $0x1, (%rbx,%rdx,4)
movq (%r15,%rdx,8), %rdx
cmpq %rax, %rdx
jne 0x14bfa
movl (%r13), %r8d
testq %rax, %rax
movl 0x78(%rsp), %edi
js 0x14c24
movq (%rsp), %rdx
subl (%rdx,%rax,4), %r8d
jmp 0x14c28
movq (%rsp), %rdx
movq 0x10(%rsp), %rsi
cmpl %edi, %r8d
jl 0x14c52
movq %rcx, %rax
subq %r9, %rax
jle 0x14c52
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 0x14bb8
movslq 0x18(%rsp), %rsi
shlq $0x3, %rsi
movq 0x20(%rsp), %rdi
callq 0x1264d
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %esi, %esi
movq 0x30(%rsp), %rdx
callq 0x21b0
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 0x14d51
addq %rsi, %r13
movl 0x80(%rsp), %edi
movq %r15, %rcx
movq %rbx, %r8
movq %rbp, %r9
callq 0x14dc4
movq 0x8(%r13), %rdx
movq %r12, %rcx
cmpq %rax, %rdx
je 0x14cf2
movq %r12, %rcx
movl %edx, (%r14,%rcx,4)
incq %rcx
movl $0x1, (%rbx,%rdx,4)
movq (%r15,%rdx,8), %rdx
cmpq %rax, %rdx
jne 0x14cdb
movl (%r13), %r8d
testq %rax, %rax
js 0x14d05
movq (%rsp), %rdx
subl (%rdx,%rax,4), %r8d
jmp 0x14d09
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 0x14d51
cmpq 0x28(%rsp), %rax
jl 0x14d51
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 0x14c9e
movq 0x20(%rsp), %rdi
callq 0x12587
cmpq $0x7fffffff, %r12       # imm = 0x7FFFFFFF
jge 0x14da5
movq 0x88(%rsp), %rax
movl 0x8(%rsp), %ecx
movl %ecx, (%rax)
movq 0x90(%rsp), %rax
movl %r12d, (%rax)
movq 0x18(%rsp), %rax
jmp 0x14d96
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19654(%rip), %rdi     # 0x2e400
leaq 0x1965d(%rip), %rsi     # 0x2e410
leaq 0x1965f(%rip), %rcx     # 0x2e419
movl $0x49, %edx
callq 0x21a0