// File: /workspace/github_c_makefile_star2_O1/ToniWestbrook[P]paladin/bwamem_extra.c
// Function: mem_gen_alt
char **mem_gen_alt(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, const mem_alnreg_v *a, int l_query, const char *query) // ONLY work after mem_mark_primary_se()
{
	int i, k, r, *cnt, tot;
	kstring_t *aln = 0, str = {0,0,0};
	char **XA = 0, *has_alt;

	cnt = calloc(a->n, sizeof(int));
	has_alt = calloc(a->n, 1);
	for (i = 0, tot = 0; i < a->n; ++i) {
		r = get_pri_idx(opt->XA_drop_ratio, a->a, i);
		if (r >= 0) {
			++cnt[r], ++tot;
			if (a->a[i].is_alt) has_alt[r] = 1;
		}
	}
	if (tot == 0) goto end_gen_alt;
	aln = calloc(a->n, sizeof(kstring_t));
	for (i = 0; i < a->n; ++i) {
		mem_aln_t t;
		if ((r = get_pri_idx(opt->XA_drop_ratio, a->a, i)) < 0) continue;
		if (cnt[r] > opt->max_XA_hits_alt || (!has_alt[r] && cnt[r] > opt->max_XA_hits)) continue;
		t = mem_reg2aln(opt, bns, pac, l_query, query, &a->a[i]);
		str.l = 0;
		kputs(bns->anns[t.rid].name, &str);
		kputc(',', &str); kputc("+-"[t.is_rev], &str); kputl(t.pos + 1, &str);
		kputc(',', &str);
		for (k = 0; k < t.n_cigar; ++k) {
			kputw(t.cigar[k]>>4, &str);
			kputc("MIDSHN"[t.cigar[k]&0xf], &str);
		}
		kputc(',', &str); kputw(t.NM, &str);
		kputc(';', &str);
		free(t.cigar);
		kputsn(str.s, str.l, &aln[r]);
	}
	XA = calloc(a->n, sizeof(char*));
	for (k = 0; k < a->n; ++k)
		XA[k] = aln[k].s;

end_gen_alt:
	free(has_alt); free(cnt); free(aln); free(str.s);
	return XA;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, 0x68(%rsp)
movl %r8d, 0x34(%rsp)
movq %rcx, %r15
movq %rdx, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdi, %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%rcx), %rdi
leaq 0x719e(%rip), %rbx      # 0x29518
leaq 0x7230(%rip), %r14      # 0x295b1
movl $0x4, %esi
movq %rbx, %rdx
movl $0x81, %ecx
movq %r14, %r8
callq 0x22cb4
movq %rax, %r12
movq (%r15), %rdi
movl $0x1, %esi
movq %rbx, %rdx
movl $0x82, %ecx
movq %r14, %r8
callq 0x22cb4
movq %rax, %r14
movq (%r15), %rdi
testq %rdi, %rdi
je 0x22439
xorl %eax, %eax
movl $0x48, %ecx
xorl %edx, %edx
movq 0x18(%r15), %rsi
movslq -0x8(%rsi,%rcx), %rdi
testq %rdi, %rdi
js 0x22404
xorps %xmm0, %xmm0
cvtss2sd 0xa4(%r13), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl -0x2c(%rsi,%rcx), %xmm1
leaq (%rdi,%rdi,2), %r8
shlq $0x5, %r8
xorps %xmm2, %xmm2
cvtsi2sdl 0x1c(%rsi,%r8), %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jae 0x22409
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
testl %edi, %edi
js 0x22423
movl %edi, %edi
incl (%r12,%rdi,4)
incl %edx
cmpl $0x40000000, (%rsi,%rcx) # imm = 0x40000000
jb 0x22423
movb $0x1, (%r14,%rdi)
incq %rax
movq (%r15), %rdi
addq $0x60, %rcx
cmpq %rax, %rdi
ja 0x223c5
testl %edx, %edx
sete %al
jmp 0x2243b
movb $0x1, %al
testb %al, %al
je 0x22449
xorl %ebx, %ebx
xorl %r15d, %r15d
jmp 0x22c7a
leaq 0x70c8(%rip), %rdx      # 0x29518
leaq 0x715a(%rip), %r8       # 0x295b1
movl $0x18, %esi
movl $0x8b, %ecx
callq 0x22cb4
movq %rax, 0x28(%rsp)
movq (%r15), %rdi
testq %rdi, %rdi
je 0x22c2a
xorl %ebp, %ebp
movq %r12, 0x50(%rsp)
movq %r14, 0x48(%rsp)
movq %r13, 0x40(%rsp)
movq 0x18(%r15), %rdx
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
shlq $0x5, %rcx
leaq (%rdx,%rcx), %rax
movslq 0x40(%rdx,%rcx), %rcx
testq %rcx, %rcx
js 0x224d8
xorps %xmm0, %xmm0
cvtss2sd 0xa4(%r13), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x1c(%rax), %xmm1
leaq (%rcx,%rcx,2), %rsi
shlq $0x5, %rsi
xorps %xmm2, %xmm2
cvtsi2sdl 0x1c(%rdx,%rsi), %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jae 0x224dd
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %ecx, %ecx
js 0x22c1b
movl %ecx, %edx
movl (%r12,%rdx,4), %ecx
cmpl 0xc0(%r13), %ecx
jg 0x22c1b
cmpb $0x0, (%r14,%rdx)
jne 0x2250c
cmpl 0xbc(%r13), %ecx
jg 0x22c1b
movq %rdx, 0x78(%rsp)
movq %rax, (%rsp)
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
movq 0x58(%rsp), %rbx
movq %rbx, %rdx
movq 0x60(%rsp), %rcx
movl 0x34(%rsp), %r8d
movq 0x68(%rsp), %r9
callq 0x1e2f7
movq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movslq 0x88(%rsp), %rax
movl 0x90(%rsp), %ecx
movq %rcx, 0x38(%rsp)
movl 0x94(%rsp), %r14d
movq 0x98(%rsp), %r13
movq $0x0, 0x10(%rsp)
movq 0x10(%rbx), %rcx
leaq (%rax,%rax,4), %rax
movq 0x18(%rcx,%rax,8), %r12
movq %r12, %rdi
callq 0x3100
movslq %eax, %rbx
leaq 0x1(%rbx), %rax
cmpq 0x18(%rsp), %rax
jb 0x225f4
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x616a(%rip), %rdx      # 0x28748
movl $0x25, %ecx
leaq 0x6b16(%rip), %r8       # 0x29100
callq 0x22d64
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
addq 0x10(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x3260
addq 0x10(%rsp), %rbx
movq %rbx, 0x10(%rsp)
movq 0x20(%rsp), %rax
movb $0x0, (%rax,%rbx)
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x18(%rsp), %rax
jb 0x22686
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x60d8(%rip), %rdx      # 0x28748
movl $0x37, %ecx
leaq 0x60de(%rip), %r8       # 0x2875a
callq 0x22d64
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%rsp)
movb $0x2c, (%rcx,%rax)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movq 0x38(%rsp), %rax
andl $0x1, %eax
leaq 0x61a3(%rip), %rcx      # 0x2885d
movb (%rax,%rcx), %bl
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x18(%rsp), %rax
jb 0x22727
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x6037(%rip), %rdx      # 0x28748
movl $0x37, %ecx
leaq 0x603d(%rip), %r8       # 0x2875a
callq 0x22d64
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%rsp)
movb %bl, (%rcx,%rax)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movq 0x70(%rsp), %r8
movq %r8, %rax
incq %rax
jne 0x227e2
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x18(%rsp), %rax
jb 0x227c6
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x5f98(%rip), %rdx      # 0x28748
movl $0x37, %ecx
leaq 0x5f9e(%rip), %r8       # 0x2875a
callq 0x22d64
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%rsp)
movb $0x30, (%rcx,%rax)
jmp 0x228c8
movq %rax, %rcx
negq %rcx
cmovsq %rax, %rcx
xorl %ebx, %ebx
movabsq $-0x3333333333333333, %rdi # imm = 0xCCCCCCCCCCCCCCCD
movq %rcx, %rax
mulq %rdi
shrq $0x3, %rdx
leal (%rdx,%rdx), %eax
leal (%rax,%rax,4), %eax
movl %ecx, %esi
subl %eax, %esi
orb $0x30, %sil
movb %sil, 0x80(%rsp,%rbx)
incq %rbx
cmpq $0x9, %rcx
movq %rdx, %rcx
ja 0x227f8
cmpq $-0x2, %r8
jg 0x22835
movb $0x2d, 0x80(%rsp,%rbx)
incq %rbx
movq 0x10(%rsp), %rax
addq %rbx, %rax
incq %rax
cmpq 0x18(%rsp), %rax
jb 0x228a2
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x5ebc(%rip), %rdx      # 0x28748
movl $0x6a, %ecx
leaq 0x686f(%rip), %r8       # 0x29107
callq 0x22d64
movq %rax, 0x20(%rsp)
incq %rbx
movb 0x7e(%rsp,%rbx), %al
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x10(%rsp)
movb %al, (%rdx,%rcx)
decq %rbx
cmpq $0x1, %rbx
jg 0x228a5
movq 0x20(%rsp), %rax
addq 0x10(%rsp), %rax
movb $0x0, (%rax)
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x18(%rsp), %rax
jb 0x2293f
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x5e1f(%rip), %rdx      # 0x28748
movl $0x37, %ecx
leaq 0x5e25(%rip), %r8       # 0x2875a
callq 0x22d64
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%rsp)
movb $0x2c, (%rcx,%rax)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movb $0x0, (%rcx,%rax)
testl %r14d, %r14d
jle 0x22a2f
xorl %ebx, %ebx
movl (%r13,%rbx,4), %edi
shrl $0x4, %edi
leaq 0x10(%rsp), %rsi
callq 0x221ba
movl (%r13,%rbx,4), %eax
andl $0xf, %eax
leaq 0x6c2d(%rip), %rcx      # 0x295bd
movb (%rax,%rcx), %r12b
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x18(%rsp), %rax
jb 0x229fe
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x5d60(%rip), %rdx      # 0x28748
movl $0x37, %ecx
leaq 0x5d66(%rip), %r8       # 0x2875a
callq 0x22d64
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%rsp)
movb %r12b, (%rcx,%rax)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movb $0x0, (%rcx,%rax)
incq %rbx
cmpq %rbx, %r14
jne 0x2296f
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x18(%rsp), %rax
jb 0x22a99
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x5cc5(%rip), %rdx      # 0x28748
movl $0x37, %ecx
leaq 0x5ccb(%rip), %r8       # 0x2875a
callq 0x22d64
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%rsp)
movb $0x2c, (%rcx,%rax)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movq 0x38(%rsp), %rdi
shrl $0xa, %edi
leaq 0x10(%rsp), %rsi
callq 0x221ba
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x18(%rsp), %rax
jb 0x22b3a
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x5c24(%rip), %rdx      # 0x28748
movl $0x37, %ecx
leaq 0x5c2a(%rip), %r8       # 0x2875a
callq 0x22d64
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%rsp)
movb $0x3b, (%rcx,%rax)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movq %r13, %rdi
callq 0x3390
movq 0x20(%rsp), %r12
movslq 0x10(%rsp), %rbx
movq 0x78(%rsp), %rax
leaq (%rax,%rax,2), %rcx
movq 0x28(%rsp), %rdx
leaq (%rdx,%rcx,8), %r14
movq (%rdx,%rcx,8), %rax
addq %rbx, %rax
incq %rax
cmpq 0x8(%rdx,%rcx,8), %rax
jb 0x22bec
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
leaq 0x5b71(%rip), %rdx      # 0x28748
movl $0x25, %ecx
leaq 0x651d(%rip), %r8       # 0x29100
callq 0x22d64
movq %rax, 0x10(%r14)
movq 0x10(%r14), %rdi
addq (%r14), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x3260
addq (%r14), %rbx
movq %rbx, (%r14)
movq 0x10(%r14), %rax
movb $0x0, (%rax,%rbx)
movq 0x50(%rsp), %r12
movq 0x48(%rsp), %r14
movq 0x40(%rsp), %r13
incq %rbp
movq (%r15), %rdi
cmpq %rbp, %rdi
ja 0x22488
leaq 0x68e7(%rip), %rdx      # 0x29518
leaq 0x6979(%rip), %r8       # 0x295b1
movl $0x8, %esi
movl $0x9e, %ecx
callq 0x22cb4
movq %rax, %rbx
movq (%r15), %rax
testq %rax, %rax
je 0x22c75
movq 0x28(%rsp), %r15
movq %r15, %rcx
addq $0x10, %rcx
xorl %edx, %edx
movq (%rcx), %rsi
movq %rsi, (%rbx,%rdx,8)
incq %rdx
addq $0x18, %rcx
cmpq %rdx, %rax
jne 0x22c60
jmp 0x22c7a
movq 0x28(%rsp), %r15
movq %r14, %rdi
callq 0x3390
movq %r12, %rdi
callq 0x3390
movq %r15, %rdi
callq 0x3390
movq 0x20(%rsp), %rdi
callq 0x3390
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)