// File: /workspace/github_c_makefile_star2_O0/lh3[P]minimap2/lchain.c
// Function: compact_a
static mm128_t *compact_a(void *km, int32_t n_u, uint64_t *u, int32_t n_v, int32_t *v, mm128_t *a)
{
	mm128_t *b, *w;
	uint64_t *u2;
	int64_t i, j, k;

	// write the result to b[]
	b = Kmalloc(km, mm128_t, n_v);
	for (i = 0, k = 0; i < n_u; ++i) {
		int32_t k0 = k, ni = (int32_t)u[i];
		for (j = 0; j < ni; ++j)
			b[k++] = a[v[k0 + (ni - j - 1)]];
	}
	kfree(km, v);

	// sort u[] and a[] by the target position, such that adjacent chains may be joined
	w = Kmalloc(km, mm128_t, n_u);
	for (i = k = 0; i < n_u; ++i) {
		w[i].x = b[k].x, w[i].y = (uint64_t)k<<32|i;
		k += (int32_t)u[i];
	}
	radix_sort_128x(w, w + n_u);
	u2 = Kmalloc(km, uint64_t, n_u);
	for (i = k = 0; i < n_u; ++i) {
		int32_t j = (int32_t)w[i].y, n = (int32_t)u[j];
		u2[i] = u[j];
		memcpy(&a[k], &b[w[i].y>>32], n * sizeof(mm128_t));
		k += n;
	}
	memcpy(u, u2, n_u * 8);
	memcpy(b, a, k * sizeof(mm128_t)); // write _a_ to _b_ and deallocate _a_ because _a_ is oversized, sometimes a lot
	kfree(km, a); kfree(km, w); kfree(km, u2);
	return b;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
shlq $0x4, %rsi
callq 0x1aae0
movq %rax, -0x38(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x50(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1f82e
movq -0x60(%rbp), %rax
movl %eax, -0x64(%rbp)
movq -0x18(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x68(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movslq -0x68(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1f81b
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x60(%rbp)
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rdx
movslq -0x64(%rbp), %rsi
movslq -0x68(%rbp), %rdi
subq -0x58(%rbp), %rdi
subq $0x1, %rdi
addq %rdi, %rsi
movslq (%rdx,%rsi,4), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x1f7b2
jmp 0x1f81d
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x1f783
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x1a8c0
movq -0x8(%rbp), %rdi
movslq -0xc(%rbp), %rsi
shlq $0x4, %rsi
callq 0x1aae0
movq %rax, -0x40(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1f8d4
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rcx
shlq $0x20, %rcx
orq -0x50(%rbp), %rcx
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cltq
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x1f860
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rsi
movslq -0xc(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0x5ad0
movq -0x8(%rbp), %rdi
movslq -0xc(%rbp), %rsi
shlq $0x3, %rsi
callq 0x1aae0
movq %rax, -0x48(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1f9ba
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movl %eax, -0x6c(%rbp)
movq -0x18(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rdi
movq -0x60(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
shlq $0x4, %rax
addq %rax, %rsi
movslq -0x70(%rbp), %rdx
shlq $0x4, %rdx
callq 0x2290
movslq -0x70(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x1f911
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0xc(%rbp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x2290
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x60(%rbp), %rdx
shlq $0x4, %rdx
callq 0x2290
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1a8c0
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x1a8c0
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x1a8c0
movq -0x38(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)