// File: /workspace/github_c_makefile_star2_O3/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 $0xc8, %rsp
movq %r9, 0x88(%rsp)
movl %r8d, 0x3c(%rsp)
movq %rcx, %r13
movq %rdx, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdi, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%rcx), %rdi
leaq 0x6d85(%rip), %rbx      # 0x29648
leaq 0x6e17(%rip), %r14      # 0x296e1
movl $0x4, %esi
movq %rbx, %rdx
movl $0x81, %ecx
movq %r14, %r8
callq 0x2319c
movq %rax, %r15
movq (%r13), %rdi
movl $0x1, %esi
movq %rbx, %rdx
movl $0x82, %ecx
movq %r14, %r8
callq 0x2319c
movq %rax, %r14
movq (%r13), %rdi
xorl %r12d, %r12d
testq %rdi, %rdi
je 0x2310d
movl $0x48, %eax
xorl %ecx, %ecx
movq 0x50(%rsp), %rbx
movq 0x18(%r13), %rsi
movslq -0x8(%rsi,%rax), %rdx
testq %rdx, %rdx
js 0x22971
xorps %xmm0, %xmm0
cvtss2sd 0xa4(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl -0x2c(%rsi,%rax), %xmm1
leaq (%rdx,%rdx,2), %r8
shlq $0x5, %r8
xorps %xmm2, %xmm2
cvtsi2sdl 0x1c(%rsi,%r8), %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jb 0x22971
incl (%r15,%rdx,4)
incl %r12d
cmpl $0x40000000, (%rsi,%rax) # imm = 0x40000000
jb 0x22971
movb $0x1, (%r14,%rdx)
movq (%r13), %rdi
incq %rcx
addq $0x60, %rax
cmpq %rcx, %rdi
ja 0x2291a
testl %r12d, %r12d
je 0x2310a
leaq 0x6cbb(%rip), %rdx      # 0x29648
leaq 0x6d4d(%rip), %r8       # 0x296e1
movl $0x18, %esi
movl $0x8b, %ecx
callq 0x2319c
movq %rax, 0x30(%rsp)
movq (%r13), %rdi
xorl %r12d, %r12d
testq %rdi, %rdi
je 0x23114
movq $0x0, 0x28(%rsp)
xorl %ebp, %ebp
movq %r15, 0x48(%rsp)
movq %r13, 0x68(%rsp)
movq %r14, 0x40(%rsp)
movq 0x18(%r13), %rdx
leaq (,%rbp,2), %rax
addq %rbp, %rax
shlq $0x5, %rax
movslq 0x40(%rdx,%rax), %rcx
testq %rcx, %rcx
js 0x230fc
xorps %xmm0, %xmm0
cvtss2sd 0xa4(%rbx), %xmm0
addq %rdx, %rax
xorps %xmm1, %xmm1
cvtsi2sdl 0x1c(%rax), %xmm1
leaq (%rcx,%rcx,2), %r8
movq %r8, %rsi
shlq $0x5, %rsi
xorps %xmm2, %xmm2
cvtsi2sdl 0x1c(%rdx,%rsi), %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jb 0x230fc
movl (%r15,%rcx,4), %edx
cmpl 0xc0(%rbx), %edx
jg 0x230fc
cmpb $0x0, (%r14,%rcx)
jne 0x22a4e
cmpl 0xbc(%rbx), %edx
jg 0x230fc
movq %r8, 0x70(%rsp)
movq %rax, (%rsp)
leaq 0x90(%rsp), %rdi
movq %rbx, %rsi
movq 0x78(%rsp), %rbx
movq %rbx, %rdx
movq 0x80(%rsp), %rcx
movl 0x3c(%rsp), %r8d
movq 0x88(%rsp), %r9
callq 0x1e9f1
movq 0x90(%rsp), %r13
movslq 0x98(%rsp), %rax
movl 0xa0(%rsp), %r15d
movl 0xa4(%rsp), %ecx
movq %rcx, 0x58(%rsp)
movq 0xa8(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x10(%rbx), %rcx
leaq (%rax,%rax,4), %rax
movq 0x18(%rcx,%rax,8), %rbx
movq %rbx, %rdi
callq 0x3100
movslq %eax, %r14
leaq 0x1(%r14), %rax
cmpq 0x28(%rsp), %rax
jae 0x22ae5
xorl %edi, %edi
jmp 0x22b46
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 %r12, %rdi
leaq 0x5cb4(%rip), %rdx      # 0x287dc
movl $0x25, %ecx
leaq 0x66bc(%rip), %r8       # 0x291f0
callq 0x2324c
movq %rax, %r12
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rdi
addq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3260
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rax
leaq (%rcx,%r14), %r12
movb $0x0, (%rax,%r12)
addq %rcx, %r14
incq %r14
movq 0x18(%rsp), %rbx
cmpq %rbx, %r14
jb 0x22bd3
movq %r14, %rcx
shrq %rcx
orq %r14, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rbx
shrq $0x10, %rbx
orq %rdx, %rbx
incq %rbx
movq %rbx, 0x18(%rsp)
movq %rax, %rdi
movq %rbx, %rsi
leaq 0x5c1f(%rip), %rdx      # 0x287dc
movl $0x37, %ecx
leaq 0x5c25(%rip), %r8       # 0x287ee
callq 0x2324c
movq %rax, 0x20(%rsp)
movw $0x2c, (%rax,%r12)
movq %r15, 0x28(%rsp)
movl %r15d, %ecx
andl $0x1, %ecx
leaq 0x5d61(%rip), %rdx      # 0x2894d
movb (%rcx,%rdx), %r15b
addq $0x2, %r12
cmpq %rbx, %r12
jb 0x22c52
movq %r12, %rcx
shrq %rcx
orq %r12, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rsi
shrq $0x10, %rsi
orq %rdx, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq %rax, %rdi
leaq 0x5ba0(%rip), %rdx      # 0x287dc
movl $0x37, %ecx
leaq 0x5ba6(%rip), %r8       # 0x287ee
callq 0x2324c
movq %rax, 0x20(%rsp)
movq %r12, 0x10(%rsp)
movb %r15b, (%rax,%r14)
movq 0x10(%rsp), %rbx
movq 0x20(%rsp), %rdi
movb $0x0, (%rdi,%rbx)
movq %r13, %rax
incq %rax
jne 0x22ce3
leaq 0x1(%rbx), %r14
cmpq 0x18(%rsp), %r14
jb 0x22cd5
movq %r14, %rax
shrq %rax
orq %r14, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
leaq 0x5b20(%rip), %rdx      # 0x287dc
movl $0x37, %ecx
leaq 0x5b26(%rip), %r8       # 0x287ee
callq 0x2324c
movq %rax, %rdi
movq %rax, 0x20(%rsp)
movq %r14, 0x10(%rsp)
movb $0x30, (%rdi,%rbx)
jmp 0x22dc1
movq %rax, %rcx
negq %rcx
cmovsq %rax, %rcx
xorl %r14d, %r14d
movabsq $-0x3333333333333333, %r8 # imm = 0xCCCCCCCCCCCCCCCD
movq %rcx, %rax
mulq %r8
shrq $0x3, %rdx
leal (%rdx,%rdx), %eax
leal (%rax,%rax,4), %eax
movl %ecx, %esi
subl %eax, %esi
orb $0x30, %sil
movb %sil, 0x90(%rsp,%r14)
incq %r14
cmpq $0x9, %rcx
movq %rdx, %rcx
ja 0x22cfa
cmpq $-0x2, %r13
jg 0x22d38
movb $0x2d, 0x90(%rsp,%r14)
incq %r14
leaq (%r14,%rbx), %rax
incq %rax
cmpq 0x18(%rsp), %rax
jb 0x22d9f
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)
leaq 0x5a56(%rip), %rdx      # 0x287dc
movl $0x6a, %ecx
leaq 0x6465(%rip), %r8       # 0x291f7
callq 0x2324c
movq %rax, %rdi
movq %rax, 0x20(%rsp)
incq %r14
movb 0x8e(%rsp,%r14), %al
movb %al, (%rdi,%rbx)
incq %rbx
decq %r14
cmpq $0x1, %r14
jg 0x22da2
movq %rbx, 0x10(%rsp)
movq %rbx, %r14
movb $0x0, (%rdi,%r14)
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %rbx
leaq 0x1(%r12), %r14
cmpq %rbx, %r14
jae 0x22de1
movq 0x20(%rsp), %rax
jmp 0x22e3f
movq %r14, %rax
shrq %rax
orq %r14, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rbx
shrq $0x10, %rbx
orq %rcx, %rbx
incq %rbx
movq %rbx, 0x18(%rsp)
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
leaq 0x59b3(%rip), %rdx      # 0x287dc
movl $0x37, %ecx
leaq 0x59b9(%rip), %r8       # 0x287ee
callq 0x2324c
movq %rax, 0x20(%rsp)
movq %r14, 0x10(%rsp)
movw $0x2c, (%rax,%r12)
cmpl $0x0, 0x58(%rsp)
jle 0x22f16
xorl %r12d, %r12d
movq 0x60(%rsp), %rbx
movl (%rbx,%r12,4), %edi
shrl $0x4, %edi
leaq 0x10(%rsp), %rsi
callq 0x226f8
movl (%rbx,%r12,4), %eax
andl $0xf, %eax
leaq 0x6870(%rip), %rcx      # 0x296ed
movb (%rax,%rcx), %r15b
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %rbx
leaq 0x1(%r13), %r14
cmpq %rbx, %r14
jae 0x22e9b
movq 0x20(%rsp), %rax
jmp 0x22ef9
movq %r14, %rax
shrq %rax
orq %r14, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rbx
shrq $0x10, %rbx
orq %rcx, %rbx
incq %rbx
movq %rbx, 0x18(%rsp)
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
leaq 0x58f9(%rip), %rdx      # 0x287dc
movl $0x37, %ecx
leaq 0x58ff(%rip), %r8       # 0x287ee
callq 0x2324c
movq %rax, 0x20(%rsp)
movq %r14, 0x10(%rsp)
movb %r15b, (%rax,%r13)
movb $0x0, 0x1(%rax,%r13)
incq %r12
cmpq %r12, 0x58(%rsp)
jne 0x22e59
leaq 0x1(%r14), %rcx
cmpq %rbx, %rcx
jb 0x22f81
movq %rcx, %rdx
shrq %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x2, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x4, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x8, %rcx
orq %rdx, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq %rax, %rdi
leaq 0x587a(%rip), %rdx      # 0x287dc
movl $0x37, %ecx
leaq 0x5880(%rip), %r8       # 0x287ee
callq 0x2324c
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %r14
leaq 0x1(%r14), %rcx
movq 0x48(%rsp), %r15
movq %rcx, 0x10(%rsp)
movb $0x2c, (%rax,%r14)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movq 0x28(%rsp), %rdi
shrl $0xa, %edi
leaq 0x10(%rsp), %rsi
callq 0x226f8
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rax
leaq 0x1(%rbx), %r14
cmpq %rax, %r14
jae 0x22fcf
movq %rax, 0x28(%rsp)
movq 0x20(%rsp), %r12
jmp 0x23032
movq %r14, %rax
shrq %rax
orq %r14, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rdi
movq %rsi, 0x28(%rsp)
leaq 0x57c3(%rip), %rdx      # 0x287dc
movl $0x37, %ecx
leaq 0x57c9(%rip), %r8       # 0x287ee
callq 0x2324c
movq %rax, %r12
movq %rax, 0x20(%rsp)
movq %r14, 0x10(%rsp)
movw $0x3b, (%r12,%rbx)
movq 0x60(%rsp), %rdi
callq 0x3390
movq 0x30(%rsp), %rcx
movq 0x70(%rsp), %rdx
leaq (%rcx,%rdx,8), %rbx
movq (%rcx,%rdx,8), %rdi
movslq %r14d, %r13
leaq (%rdi,%r13), %rax
incq %rax
cmpq 0x8(%rcx,%rdx,8), %rax
jae 0x23071
movq 0x10(%rbx), %rax
jmp 0x230cc
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(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x5728(%rip), %rdx      # 0x287dc
movl $0x25, %ecx
leaq 0x6130(%rip), %r8       # 0x291f0
callq 0x2324c
movq %rax, 0x10(%rbx)
movq (%rbx), %rdi
movq 0x40(%rsp), %r14
addq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x3260
addq (%rbx), %r13
movq %r13, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r13)
movq 0x68(%rsp), %r13
movq (%r13), %rdi
movq 0x50(%rsp), %rbx
incq %rbp
cmpq %rbp, %rdi
ja 0x229d2
jmp 0x23116
xorl %r12d, %r12d
xorl %ebx, %ebx
xorl %r13d, %r13d
jmp 0x23167
xorl %edi, %edi
leaq 0x652b(%rip), %rdx      # 0x29648
leaq 0x65bd(%rip), %r8       # 0x296e1
movl $0x8, %esi
movl $0x9e, %ecx
callq 0x2319c
movq %rax, %rbx
movq (%r13), %rax
testq %rax, %rax
je 0x23162
movq 0x30(%rsp), %r13
movq %r13, %rcx
addq $0x10, %rcx
xorl %edx, %edx
movq (%rcx), %rsi
movq %rsi, (%rbx,%rdx,8)
incq %rdx
addq $0x18, %rcx
cmpq %rdx, %rax
jne 0x2314d
jmp 0x23167
movq 0x30(%rsp), %r13
movq %r14, %rdi
callq 0x3390
movq %r15, %rdi
callq 0x3390
movq %r13, %rdi
callq 0x3390
movq %r12, %rdi
callq 0x3390
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq