// File: /workspace/github_c_makefile_star2_O0/lh3[P]minigraph/miniwfa.c
// Function: mg_chain
static uint64_t *mg_chain(void *km, int32_t l1, const char *s1, int32_t l2, const char *s2, int32_t k, int32_t max_occ, int32_t *n_lis_)
{
	int32_t i, n_a, n_b, m_b, i0, n_lis, *lis;
	uint64_t *a, *b;

	*n_lis_ = 0;
	if (l1 < k || l2 < k) return 0;
	assert(k >= 2 && k <= 15);

	// collect k-mers
	KMALLOC(km, a, l1 + l2);
	n_a = mg_fc_kmer(l1, s1, 0, k, a);
	n_a += mg_fc_kmer(l2, s2, 1, k, &a[n_a]);
	radix_sort_gfa64(a, a + n_a);

	// collect k-mer matches
	n_b = m_b = 0, b = 0;
	for (i0 = 0, i = 1; i <= n_a; ++i) {
		if (i == n_a || a[i0]>>33 != a[i]>>33) {
			if (i - i0 >= 2) {
				int32_t j, s, t;
				for (j = i0; j < i && (a[j]>>32&1) == 0; ++j) {}
				if (j > i0 && j < i && j - i0 <= max_occ && i - j <= max_occ) {
					for (s = i0; s < j; ++s)
						for (t = j; t < i; ++t) {
							if (n_b == m_b) KEXPAND(km, b, m_b);
							b[n_b++] = a[s]<<32 | (uint32_t)a[t];
						}
				}
			}
			i0 = i;
		}
	}
	kfree(km, a);

	// find co-linear chain with LIS
	radix_sort_gfa64(b, b + n_b);
	for (i = 0; i < n_b; ++i)
		b[i] = b[i]>>32 | b[i]<<32;
	KMALLOC(km, lis, n_b);
	n_lis = mg_lis_64(km, n_b, b, lis);
	a = Kmalloc(km, uint64_t, n_lis);
	for (i = 0; i < n_lis; ++i) a[i] = b[lis[i]];
	kfree(km, lis);
	kfree(km, b);
	b = Kmalloc(km, uint64_t, n_lis);
	memcpy(b, a, sizeof(uint64_t) * n_lis);
	kfree(km, a);
	*n_lis_ = n_lis;
	for (i = 0; i < n_lis; ++i) // switch back, such that seq1 on the high bits
		b[i] = b[i]>>32 | b[i]<<32;
	return b;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq 0x18(%rbp), %rax
movl $0x0, (%rax)
movl -0x14(%rbp), %eax
cmpl -0x34(%rbp), %eax
jl 0x1e122
movl -0x24(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x1e12f
movq $0x0, -0x8(%rbp)
jmp 0x1e52d
cmpl $0x2, -0x34(%rbp)
jl 0x1e13d
cmpl $0xf, -0x34(%rbp)
jg 0x1e13d
jmp 0x1e15c
leaq 0x1ee09(%rip), %rdi     # 0x3cf4d
leaq 0x1eb49(%rip), %rsi     # 0x3cc94
movl $0x299, %edx            # imm = 0x299
leaq 0x1ee08(%rip), %rcx     # 0x3cf5f
callq 0x2170
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %eax
addl -0x24(%rbp), %eax
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x2890
movq %rax, -0x60(%rbp)
movl -0x14(%rbp), %edi
movq -0x20(%rbp), %rsi
movl -0x34(%rbp), %ecx
movq -0x60(%rbp), %r8
xorl %edx, %edx
callq 0x200c0
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %edi
movq -0x30(%rbp), %rsi
movl -0x34(%rbp), %ecx
movq -0x60(%rbp), %r8
movslq -0x3c(%rbp), %rax
shlq $0x3, %rax
addq %rax, %r8
movl $0x1, %edx
callq 0x200c0
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x60(%rbp), %rdi
movq -0x60(%rbp), %rsi
movslq -0x3c(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x5440
movl $0x0, -0x44(%rbp)
movl $0x0, -0x40(%rbp)
movq $0x0, -0x68(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x1, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jg 0x1e399
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0x1e230
movq -0x60(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movq -0x60(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
cmpq %rcx, %rax
je 0x1e389
movl -0x38(%rbp), %eax
subl -0x48(%rbp), %eax
cmpl $0x2, %eax
jl 0x1e383
movl -0x48(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x38(%rbp), %ecx
movb %al, -0x75(%rbp)
jge 0x1e270
movq -0x60(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
andq $0x1, %rax
cmpq $0x0, %rax
sete %al
movb %al, -0x75(%rbp)
movb -0x75(%rbp), %al
testb $0x1, %al
jne 0x1e279
jmp 0x1e286
jmp 0x1e27b
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1e245
movl -0x6c(%rbp), %eax
cmpl -0x48(%rbp), %eax
jle 0x1e381
movl -0x6c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x1e381
movl -0x6c(%rbp), %eax
subl -0x48(%rbp), %eax
cmpl 0x10(%rbp), %eax
jg 0x1e381
movl -0x38(%rbp), %eax
subl -0x6c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jg 0x1e381
movl -0x48(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jge 0x1e37f
movl -0x6c(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x1e36f
movl -0x40(%rbp), %eax
cmpl -0x44(%rbp), %eax
jne 0x1e32a
jmp 0x1e2ea
cmpl $0x4, -0x44(%rbp)
jl 0x1e2ff
movl -0x44(%rbp), %eax
movl -0x44(%rbp), %ecx
sarl %ecx
addl %ecx, %eax
movl %eax, -0x7c(%rbp)
jmp 0x1e309
movl $0x10, %eax
movl %eax, -0x7c(%rbp)
jmp 0x1e309
movl -0x7c(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rsi
movslq -0x44(%rbp), %rdx
shlq $0x3, %rdx
callq 0x2ae0
movq %rax, -0x68(%rbp)
jmp 0x1e32a
movq -0x60(%rbp), %rax
movslq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shlq $0x20, %rdx
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
orq %rax, %rdx
movq -0x68(%rbp), %rax
movl -0x40(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x40(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x1e2d4
jmp 0x1e371
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x1e2c2
jmp 0x1e381
jmp 0x1e383
movl -0x38(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x1e38b
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1e1f3
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x2670
movq -0x68(%rbp), %rdi
movq -0x68(%rbp), %rsi
movslq -0x40(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x5440
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x1e407
movq -0x68(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shrq $0x20, %rdx
movq -0x68(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shlq $0x20, %rax
orq %rax, %rdx
movq -0x68(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1e3c5
movq -0x10(%rbp), %rdi
movslq -0x40(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2890
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movl -0x40(%rbp), %esi
movq -0x68(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x201c0
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x4c(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2890
movq %rax, -0x60(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x1e482
movq -0x68(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x60(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1e44f
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x2670
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x2670
movq -0x10(%rbp), %rdi
movslq -0x4c(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2890
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movslq -0x4c(%rbp), %rdx
shlq $0x3, %rdx
callq 0x2230
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x2670
movl -0x4c(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x1e525
movq -0x68(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shrq $0x20, %rdx
movq -0x68(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shlq $0x20, %rax
orq %rax, %rdx
movq -0x68(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1e4e3
movq -0x68(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)