// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rdi, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
testl %esi, %esi
je 0x17ddb
movq %rdx, %rbx
movl %esi, %r15d
xorl %eax, %eax
testl %esi, %esi
movl $0x0, %r14d
cmovgl %esi, %r14d
imulq $0x60, %r14, %r13
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
imulq %rdx, %rcx
notq %rcx
movabsq $-0xffffffff, %rdx      # imm = 0xFFFFFFFF00000001
xorl %ebp, %ebp
cmpq %rax, %r13
je 0x17d18
andq $0x0, 0x24(%rbx,%rax)
orq $-0x1, 0x3c(%rbx,%rax)
movq %rcx, %rsi
shrq $0x16, %rsi
xorq %rcx, %rsi
movq %rsi, %rdi
shlq $0xd, %rdi
notq %rdi
addq %rsi, %rdi
movq %rdi, %rsi
shrq $0x8, %rsi
xorq %rdi, %rsi
leaq (%rsi,%rsi,8), %rsi
movq %rsi, %rdi
shrq $0xf, %rdi
xorq %rsi, %rdi
movq %rdi, %rsi
shlq $0x1b, %rsi
notq %rsi
addq %rdi, %rsi
movq %rsi, %rdi
shrq $0x1f, %rdi
xorq %rsi, %rdi
movq %rdi, 0x58(%rbx,%rax)
cmpl $0x40000000, 0x48(%rbx,%rax) # imm = 0x40000000
adcl $0x0, %ebp
addq $0x60, %rax
addq %rdx, %rcx
jmp 0x17ca8
movslq %r15d, %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1619a
leaq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x17e7f
leaq 0x48(%rbx), %rax
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x17d7a
movl %ecx, -0x8(%rax)
cmpl $0x3fffffff, (%rax)     # imm = 0x3FFFFFFF
ja 0x17d71
movslq -0xc(%rax), %rdx
testq %rdx, %rdx
js 0x17d71
imulq $0x60, %rdx, %rdx
cmpl $0x40000000, 0x48(%rbx,%rdx) # imm = 0x40000000
jb 0x17d71
addq %rbx, %rdx
movl 0x1c(%rdx), %edx
movl %edx, -0x20(%rax)
incq %rcx
addq $0x60, %rax
jmp 0x17d41
cmpl %r15d, %ebp
jge 0x17de2
movq %r12, 0x18(%rsp)
movq 0x20(%rsp), %rdi
leaq (,%r12,4), %rsi
leaq 0xbab8(%rip), %rdx      # 0x23850
leaq 0xbdbd(%rip), %r8       # 0x23b5c
movl $0x270, %ecx            # imm = 0x270
callq 0x1e0b4
movq %rax, %r15
movq %rax, 0x20(%rsp)
testl %ebp, %ebp
je 0x17dc0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x16ef6
leaq 0x40(%rbx), %rax
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x17df7
movslq (%rax), %rdx
movl %ecx, (%r15,%rdx,4)
incq %rcx
addq $0x60, %rax
jmp 0x17dc6
xorl %ebp, %ebp
jmp 0x17e6e
xorl %eax, %eax
cmpq %rax, %r13
je 0x17e64
movl 0x3c(%rbx,%rax), %ecx
movl %ecx, 0x40(%rbx,%rax)
addq $0x60, %rax
jmp 0x17de4
xorl %eax, %eax
cmpq %rax, %r13
je 0x17e2f
movslq 0x3c(%rbx,%rax), %rcx
testq %rcx, %rcx
js 0x17e24
movl (%r15,%rcx,4), %ecx
movl %ecx, 0x40(%rbx,%rax)
cmpl $0x40000000, 0x48(%rbx,%rax) # imm = 0x40000000
jb 0x17e29
movl $0x7fffffff, 0x3c(%rbx,%rax) # imm = 0x7FFFFFFF
jmp 0x17e29
orl $-0x1, 0x40(%rbx,%rax)
addq $0x60, %rax
jmp 0x17df9
testl %ebp, %ebp
je 0x17e64
movl %ebp, %eax
imulq $0x60, %rax, %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x17e50
andl $0x0, 0x24(%rbx,%rcx)
orl $-0x1, 0x3c(%rbx,%rcx)
addq $0x60, %rcx
jmp 0x17e3b
leaq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x17e7f
movq 0x20(%rsp), %rdi
callq 0x3390
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq