// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %r9, %r14
movq %r8, 0x40(%rsp)
movq %rcx, %r12
movq %rsi, %r8
movq %rdi, %r15
movq 0xa0(%rsp), %rax
movq 0x98(%rsp), %rcx
movl 0x88(%rsp), %esi
xorl %ebp, %ebp
movl %ebp, (%rax)
movl %ebp, (%rcx)
testq %r8, %r8
jle 0x14ae4
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 0x14ad1
testq %rbp, %rbp
je 0x14c70
movq %rbp, %rbx
shlq $0x4, %rbx
movq %r15, %rdi
movq %rbx, %rsi
movq %rdx, 0x10(%rsp)
movq %r8, %r13
callq 0x126e9
movq %r13, %r10
movl 0x88(%rsp), %r8d
movq 0x10(%rsp), %rdi
testq %r13, %r13
jle 0x14b45
xorl %r9d, %r9d
xorl %ecx, %ecx
movslq (%rdi,%r9,4), %rdx
cmpl %r8d, %edx
jl 0x14b3d
movq %rcx, %rsi
shlq $0x4, %rsi
movq %rdx, (%rax,%rsi)
incq %rcx
movq %r9, 0x8(%rax,%rsi)
incq %r9
cmpq %r9, %r10
jne 0x14b21
movq %r15, 0x28(%rsp)
addq %rax, %rbx
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %rbx, %rsi
movq %r10, %rbx
callq 0x5ae1
shlq $0x2, %rbx
movq $0x0, 0x20(%rsp)
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, 0x38(%rsp)
movq %rbx, %rdx
callq 0x21b0
leaq -0x1(%rbp), %r15
movslq 0x80(%rsp), %rax
movq %rax, 0x30(%rsp)
testq %rbp, %rbp
jle 0x14c77
xorl %r9d, %r9d
movq %r15, %rbx
movl $0x0, 0x1c(%rsp)
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rsi
movq %rbx, %r13
shlq $0x4, %r13
movq 0x8(%rsi,%r13), %rax
cmpl $0x0, (%r14,%rax,4)
jne 0x14c55
movq %r9, (%rsp)
addq %rsi, %r13
movl 0x90(%rsp), %edi
movq %r12, %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x14dee
movq 0x8(%r13), %r8
cmpq %rax, %r8
jne 0x14bfd
movq (%rsp), %r9
movq %r9, %rcx
movl 0x88(%rsp), %edi
jmp 0x14c1f
movq (%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 0x14c0b
movl (%r13), %eax
testq %r8, %r8
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rsi
js 0x14c36
subl (%rdx,%r8,4), %eax
cmpl %edi, %eax
jl 0x14c55
movq %rcx, %rax
subq %r9, %rax
jle 0x14c55
xorl %edi, %edi
cmpq 0x30(%rsp), %rax
setge %dil
cmovgeq %rcx, %r9
addl %edi, 0x1c(%rsp)
leaq -0x1(%rbx), %rax
testq %rbx, %rbx
movq %rax, %rbx
jg 0x14bb1
movslq 0x1c(%rsp), %rsi
shlq $0x3, %rsi
jmp 0x14c79
xorl %eax, %eax
jmp 0x14dc0
xorl %esi, %esi
movq 0x28(%rsp), %rdi
callq 0x126e9
movq %rax, (%rsp)
movq %r14, %rdi
xorl %esi, %esi
movq 0x38(%rsp), %rdx
callq 0x21b0
testq %rbp, %rbp
jle 0x14d89
xorl %ebp, %ebp
movq $0x0, 0x20(%rsp)
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rsi
movq %r15, %r13
shlq $0x4, %r13
movq 0x8(%rsi,%r13), %rax
cmpl $0x0, (%r14,%rax,4)
jne 0x14d51
addq %rsi, %r13
movl 0x90(%rsp), %edi
movq %r12, %rcx
movq %r14, %r8
movq %r15, %r9
callq 0x14dee
movq 0x8(%r13), %rcx
movq %rbp, %rbx
cmpq %rax, %rcx
jne 0x14cf8
movl 0x88(%rsp), %edi
jmp 0x14d1b
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 0x14d04
movl (%r13), %eax
testq %rcx, %rcx
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rsi
js 0x14d31
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 0x14d51
cmpq 0x30(%rsp), %rcx
jge 0x14d69
movq %rbp, %rbx
leaq -0x1(%r15), %rax
movq %rbx, %rbp
testq %r15, %r15
movq %rax, %r15
jg 0x14cb4
jmp 0x14d90
shlq $0x20, %rax
orq %rcx, %rax
movq 0x20(%rsp), %rdi
movslq %edi, %rcx
incl %edi
movq %rdi, 0x20(%rsp)
movq (%rsp), %rdi
movq %rax, (%rdi,%rcx,8)
jmp 0x14d54
xorl %ebx, %ebx
movq 0x8(%rsp), %rsi
movq 0x28(%rsp), %rdi
callq 0x1261e
cmpq $0x7fffffff, %rbx       # imm = 0x7FFFFFFF
jge 0x14dcf
movq 0x98(%rsp), %rax
movq 0x20(%rsp), %rcx
movl %ecx, (%rax)
movq 0xa0(%rsp), %rax
movl %ebx, (%rax)
movq (%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1860a(%rip), %rdi     # 0x2d3e0
leaq 0x18613(%rip), %rsi     # 0x2d3f0
leaq 0x18615(%rip), %rcx     # 0x2d3f9
movl $0x49, %edx
callq 0x21a0