// File: /workspace/github_c_makefile_star2_O1/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 0x1a111
movq %rdx, %rbx
movl %esi, %r15d
movq %rdi, %r14
jle 0x1a118
movl %r15d, %edx
movq %rcx, %rax
shlq $0x20, %rax
subq %rcx, %rax
notq %rax
shlq $0x5, %rdx
leaq (%rdx,%rdx,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 0x1a09b
jmp 0x1a11a
xorl %ebp, %ebp
jmp 0x1a2b3
xorl %ebp, %ebp
movslq %r15d, %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1833d
movq %rsp, %rcx
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x1a2c4
testl %r15d, %r15d
jle 0x1a182
movl %r15d, %eax
leaq 0x48(%rbx), %rcx
xorl %edx, %edx
movl %edx, -0x8(%rcx)
cmpl $0x3fffffff, (%rcx)     # imm = 0x3FFFFFFF
ja 0x1a176
movslq -0xc(%rcx), %rsi
testq %rsi, %rsi
js 0x1a176
leaq (%rsi,%rsi,2), %rsi
shlq $0x5, %rsi
cmpl $0x40000000, 0x48(%rbx,%rsi) # imm = 0x40000000
jb 0x1a176
addq %rbx, %rsi
movl 0x1c(%rsi), %esi
movl %esi, -0x20(%rcx)
incq %rdx
addq $0x60, %rcx
cmpq %rdx, %rax
jne 0x1a147
testl %ebp, %ebp
setns %al
cmpl %r15d, %ebp
setl %cl
testb %cl, %al
je 0x1a286
movq %r12, 0x8(%rsp)
movq 0x10(%rsp), %rdi
leaq (,%r12,4), %rsi
leaq 0xe622(%rip), %rdx      # 0x287d0
leaq 0xe927(%rip), %r8       # 0x28adc
movl $0x270, %ecx            # imm = 0x270
callq 0x22d64
movq %rax, %r13
movq %rax, 0x10(%rsp)
testl %ebp, %ebp
je 0x1a1d6
movq %r12, %rdi
movq %rbx, %rsi
callq 0x191e2
testl %r15d, %r15d
jle 0x1a1f8
movl %r15d, %eax
leaq 0x40(%rbx), %rcx
xorl %edx, %edx
movslq (%rcx), %rsi
movl %edx, (%r13,%rsi,4)
incq %rdx
addq $0x60, %rcx
cmpq %rdx, %rax
jne 0x1a1e4
testl %r15d, %r15d
jle 0x1a242
movl %r15d, %eax
shlq $0x5, %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
movslq 0x3c(%rbx,%rcx), %rdx
testq %rdx, %rdx
js 0x1a231
movl (%r13,%rdx,4), %edx
movl %edx, 0x40(%rbx,%rcx)
cmpl $0x40000000, 0x48(%rbx,%rcx) # imm = 0x40000000
jb 0x1a239
movl $0x7fffffff, 0x3c(%rbx,%rcx) # imm = 0x7FFFFFFF
jmp 0x1a239
movl $0xffffffff, 0x40(%rbx,%rcx) # imm = 0xFFFFFFFF
addq $0x60, %rcx
cmpq %rcx, %rax
jne 0x1a20a
testl %ebp, %ebp
je 0x1a2a9
cmpl $0x2, %ebp
movl $0x1, %eax
cmovgel %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 0x1a25b
movq %rsp, %rcx
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x1a2c4
jmp 0x1a2a9
testl %r15d, %r15d
jle 0x1a2a9
movl %r15d, %eax
shlq $0x5, %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
movl 0x3c(%rbx,%rcx), %edx
movl %edx, 0x40(%rbx,%rcx)
addq $0x60, %rcx
cmpq %rcx, %rax
jne 0x1a298
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