// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %r8, 0x40(%rsp)
movq %rcx, %r15
movq 0xa0(%rsp), %rax
movq 0x98(%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 0x12c8b
xorl %ecx, %ecx
cmpl %r13d, (%rdx,%rax,4)
setge %cl
addq %rcx, %r12
incq %rax
jmp 0x12c75
testq %r12, %r12
je 0x12f3c
movq %rsi, 0x28(%rsp)
movq %r12, %rsi
shlq $0x4, %rsi
movq %rdi, 0x30(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
callq 0x10afc
movq 0x18(%rsp), %rdi
movq %rax, %rbp
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x12ce7
movslq (%rdi,%rcx,4), %rdx
cmpl %r13d, %edx
jl 0x12ce2
movq %rax, %rsi
shlq $0x4, %rsi
movq %rdx, (%rbp,%rsi)
incq %rax
movq %rcx, 0x8(%rbp,%rsi)
incq %rcx
jmp 0x12cc0
movq 0x10(%rsp), %rsi
addq %rbp, %rsi
movq %rbp, %rdi
callq 0x47dc
movq 0x28(%rsp), %rdx
shlq $0x2, %rdx
movq $0x0, 0x8(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movq %rdx, 0x28(%rsp)
callq 0x21b0
decq %r12
movslq 0x80(%rsp), %rax
movq %rax, 0x38(%rsp)
xorl %esi, %esi
movq %r12, %r14
testq %r14, %r14
js 0x12de9
movq %r14, %rax
shlq $0x4, %rax
movq 0x8(%rbp,%rax), %rcx
cmpl $0x0, (%rbx,%rcx,4)
jne 0x12de1
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 0x12f6a
xorl %ecx, %ecx
movq (%r13), %rdx
cmpq %rax, %rdx
je 0x12d9a
movl $0x1, (%rbx,%rdx,4)
leaq (%r15,%rdx,8), %r13
incq %rcx
jmp 0x12d81
movq 0x20(%rsp), %rdx
movl (%rdx), %edx
testq %rax, %rax
js 0x12dae
movq 0x18(%rsp), %rsi
subl (%rsi,%rax,4), %edx
movl 0x88(%rsp), %eax
movq 0x10(%rsp), %rsi
cmpl %eax, %edx
jl 0x12de1
leaq (%rsi,%rcx), %rax
cmpq %rsi, %rax
jle 0x12de1
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 0x12d2d
movslq 0x8(%rsp), %rsi
shlq $0x3, %rsi
movq 0x30(%rsp), %rdi
callq 0x10afc
movq %rax, 0x8(%rsp)
movq $0x0, 0x20(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movq 0x28(%rsp), %rdx
callq 0x21b0
xorl %r14d, %r14d
movq 0x18(%rsp), %rdx
testq %r12, %r12
js 0x12f05
movq %r12, %rax
shlq $0x4, %rax
movq 0x8(%rbp,%rax), %rcx
cmpl $0x0, (%rbx,%rcx,4)
jne 0x12ed6
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 0x12f6a
movq 0x40(%rsp), %rcx
leaq (%rcx,%r14,4), %rdx
xorl %ecx, %ecx
movq (%r13), %rsi
cmpq %rax, %rsi
je 0x12e90
movl %esi, (%rdx,%rcx,4)
movl $0x1, (%rbx,%rsi,4)
leaq (%r15,%rsi,8), %r13
incq %rcx
jmp 0x12e74
movq 0x10(%rsp), %rdx
movl (%rdx), %r8d
testq %rax, %rax
js 0x12ea8
movq 0x18(%rsp), %rdx
subl (%rdx,%rax,4), %r8d
jmp 0x12ead
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 0x12ed6
cmpq 0x38(%rsp), %rcx
jge 0x12ee4
movq %r14, %rax
decq %r12
movq %rax, %r14
jmp 0x12e21
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 0x12ed9
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x10a07
cmpq $0x7fffffff, %r14       # imm = 0x7FFFFFFF
jge 0x12f4d
movq 0x98(%rsp), %rax
movq 0x20(%rsp), %rcx
movl %ecx, (%rax)
movq 0xa0(%rsp), %rax
movl %r14d, (%rax)
movq 0x8(%rsp), %rax
jmp 0x12f3e
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x164ac(%rip), %rdi     # 0x29400
leaq 0x164b5(%rip), %rsi     # 0x29410
leaq 0x164b7(%rip), %rcx     # 0x29419
pushq $0x49
popq %rdx
callq 0x21a0