// File: /workspace/github_c_makefile_star2_O3/ToniWestbrook[P]paladin/bwamem.c
// Function: mem_mark_primary_se
int mem_mark_primary_se(const mem_opt_t *opt, int n, mem_alnreg_t *a, int64_t id)
{
	int i, n_pri;
	int_v z = {0,0,0};
	if (n == 0) return 0;
	for (i = n_pri = 0; i < n; ++i) {
		a[i].sub = a[i].alt_sc = 0, a[i].secondary = a[i].secondary_all = -1, a[i].hash = hash_64(id+i);
		if (!a[i].is_alt) ++n_pri;
	}
	ks_introsort(mem_ars_hash, n, a);
	mem_mark_primary_se_core(opt, n, a, &z);
	for (i = 0; i < n; ++i) {
		mem_alnreg_t *p = &a[i];
		p->secondary_all = i; // keep the rank in the first round
		if (!p->is_alt && p->secondary >= 0 && a[p->secondary].is_alt)
			p->alt_sc = a[p->secondary].score;
	}
	if (n_pri >= 0 && n_pri < n) {
		kv_resize(int, z, n);
		if (n_pri > 0) ks_introsort(mem_ars_hash2, n, a);
		for (i = 0; i < n; ++i) z.a[a[i].secondary_all] = i;
		for (i = 0; i < n; ++i) {
			if (a[i].secondary >= 0) {
				a[i].secondary_all = z.a[a[i].secondary];
				if (a[i].is_alt) a[i].secondary = INT_MAX;
			} else a[i].secondary_all = -1;
		}
		if (n_pri > 0) { // mark primary for hits to the primary assembly only
			for (i = 0; i < n_pri; ++i) a[i].sub = 0, a[i].secondary = -1;
			mem_mark_primary_se_core(opt, n_pri, a, &z);
		}
	} else {
		for (i = 0; i < n; ++i)
			a[i].secondary_all = a[i].secondary;
	}
	free(z.a);
	return n_pri;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testl %esi, %esi
je 0x1a6c9
movq %rdx, %rbx
movl %esi, %r15d
movq %rdi, %r14
movl %esi, %r13d
jle 0x1a6d0
movq %rcx, %rax
shlq $0x20, %rax
subq %rcx, %rax
notq %rax
movq %r13, %rcx
shlq $0x5, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
movabsq $-0xffffffff, %rsi      # imm = 0xFFFFFFFF00000001
xorl %ebp, %ebp
movq $0x0, 0x24(%rbx,%rdx)
movq $-0x1, 0x3c(%rbx,%rdx)
movq %rax, %rdi
shrq $0x16, %rdi
xorq %rax, %rdi
movq %rdi, %r8
shlq $0xd, %r8
notq %r8
addq %rdi, %r8
movq %r8, %rdi
shrq $0x8, %rdi
xorq %r8, %rdi
leaq (%rdi,%rdi,8), %rdi
movq %rdi, %r8
shrq $0xf, %r8
xorq %rdi, %r8
movq %r8, %rdi
shlq $0x1b, %rdi
notq %rdi
addq %r8, %rdi
movq %rdi, %r8
shrq $0x1f, %r8
xorq %rdi, %r8
movq %r8, 0x58(%rbx,%rdx)
cmpl $0x40000000, 0x48(%rbx,%rdx) # imm = 0x40000000
adcl $0x0, %ebp
addq %rsi, %rax
addq $0x60, %rdx
cmpq %rdx, %rcx
jne 0x1a653
jmp 0x1a6d2
xorl %ebp, %ebp
jmp 0x1a850
xorl %ebp, %ebp
movslq %r15d, %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x188d3
movq %rsp, %rcx
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x1a861
testl %r15d, %r15d
jle 0x1a76c
leaq 0x48(%rbx), %rax
xorl %ecx, %ecx
movl %ecx, -0x8(%rax)
cmpl $0x3fffffff, (%rax)     # imm = 0x3FFFFFFF
ja 0x1a72b
movslq -0xc(%rax), %rdx
testq %rdx, %rdx
js 0x1a72b
leaq (%rdx,%rdx,2), %rdx
shlq $0x5, %rdx
cmpl $0x40000000, 0x48(%rbx,%rdx) # imm = 0x40000000
jb 0x1a72b
addq %rbx, %rdx
movl 0x1c(%rdx), %edx
movl %edx, -0x20(%rax)
incq %rcx
addq $0x60, %rax
cmpq %rcx, %r13
jne 0x1a6fc
cmpl %r13d, %ebp
jb 0x1a77f
testl %r15d, %r15d
jle 0x1a846
shlq $0x5, %r13
leaq (,%r13,2), %rax
addq %r13, %rax
xorl %ecx, %ecx
movl 0x3c(%rbx,%rcx), %edx
movl %edx, 0x40(%rbx,%rcx)
addq $0x60, %rcx
cmpq %rcx, %rax
jne 0x1a756
jmp 0x1a846
testl %ebp, %ebp
setns %al
cmpl %r15d, %ebp
setl %cl
testb %cl, %al
je 0x1a846
movq %r12, 0x8(%rsp)
movq 0x10(%rsp), %rdi
leaq (,%r12,4), %rsi
leaq 0xe128(%rip), %rdx      # 0x288c0
leaq 0xe42d(%rip), %r8       # 0x28bcc
movl $0x270, %ecx            # imm = 0x270
callq 0x2324c
movq %rax, %r15
movq %rax, 0x10(%rsp)
testl %ebp, %ebp
je 0x1a7c0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1978c
leaq 0x40(%rbx), %rax
xorl %ecx, %ecx
movslq (%rax), %rdx
movl %ecx, (%r15,%rdx,4)
incq %rcx
addq $0x60, %rax
cmpq %rcx, %r13
jne 0x1a7c6
leaq 0x3c(%rbx), %rax
movslq (%rax), %rcx
testq %rcx, %rcx
js 0x1a7fd
movl (%r15,%rcx,4), %ecx
movl %ecx, 0x4(%rax)
cmpl $0x40000000, 0xc(%rax)  # imm = 0x40000000
jb 0x1a804
movl $0x7fffffff, (%rax)     # imm = 0x7FFFFFFF
jmp 0x1a804
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
addq $0x60, %rax
decq %r13
jne 0x1a7dd
testl %ebp, %ebp
je 0x1a846
movl %ebp, %eax
shlq $0x5, %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
movl $0x0, 0x24(%rbx,%rcx)
movl $0xffffffff, 0x3c(%rbx,%rcx) # imm = 0xFFFFFFFF
addq $0x60, %rcx
cmpq %rcx, %rax
jne 0x1a81d
movq %rsp, %rcx
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x1a861
movq 0x10(%rsp), %rdi
callq 0x3390
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq