// File: /workspace/github_c_makefile_star2_O2/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, 0x58(%rsp)
movl %r8d, 0x34(%rsp)
movq %rcx, %r13
movq %rdx, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdi, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq (%rcx), %rdi
leaq 0x6aba(%rip), %rbx      # 0x245c8
leaq 0x6b4c(%rip), %r14      # 0x24661
pushq $0x4
popq %rsi
movq %rbx, %rdx
movl $0x81, %ecx
movq %r14, %r8
callq 0x1dfd0
movq %rax, %r12
movq (%r13), %rdi
pushq $0x1
popq %rsi
movq %rbx, %rdx
movl $0x82, %ecx
movq %r14, %r8
callq 0x1dfd0
movq %rax, 0x28(%rsp)
xorl %ebx, %ebx
pushq $0x48
popq %r15
xorl %ebp, %ebp
movq (%r13), %rdi
cmpq %rbx, %rdi
jbe 0x1db9b
movq 0x8(%rsp), %rax
cvtss2sd 0xa4(%rax), %xmm0
movq 0x18(%r13), %r14
movq %r14, %rdi
movl %ebx, %esi
callq 0x1def7
testl %eax, %eax
js 0x1db92
movl %eax, %eax
incl (%r12,%rax,4)
incl %ebp
cmpl $0x40000000, (%r14,%r15) # imm = 0x40000000
jb 0x1db92
movq 0x28(%rsp), %rcx
movb $0x1, (%rcx,%rax)
incq %rbx
addq $0x60, %r15
jmp 0x1db4f
xorl %ebx, %ebx
testl %ebp, %ebp
je 0x1debb
movq %r12, 0x38(%rsp)
leaq 0x6a17(%rip), %rdx      # 0x245c8
leaq 0x6aa9(%rip), %r8       # 0x24661
pushq $0x18
popq %rsi
movl $0x8b, %ecx
callq 0x1dfd0
movq %rax, %rbp
leaq 0x10(%rsp), %r12
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x8(%rsp), %r15
movq %r13, 0x78(%rsp)
movq %rax, 0x40(%rsp)
movq (%r13), %rdi
cmpq %r14, %rdi
jbe 0x1de73
cvtss2sd 0xa4(%r15), %xmm0
movq 0x18(%r13), %r13
movq %r13, %rdi
movl %r14d, %esi
callq 0x1def7
testl %eax, %eax
js 0x1de66
movl %eax, %edx
movq 0x38(%rsp), %rax
movl (%rax,%rdx,4), %eax
cmpl 0xc0(%r15), %eax
jg 0x1de66
movq 0x28(%rsp), %rcx
cmpb $0x0, (%rcx,%rdx)
jne 0x1dc3d
cmpl 0xbc(%r15), %eax
jg 0x1de66
movq %rdx, 0x70(%rsp)
imulq $0x60, %r14, %rax
addq %rax, %r13
movq %r13, (%rsp)
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
movq 0x48(%rsp), %rbx
movq %rbx, %rdx
movq 0x50(%rsp), %rcx
movl 0x34(%rsp), %r8d
movq 0x58(%rsp), %r9
callq 0x1a4cd
movq 0x80(%rsp), %rax
movq %rax, 0x60(%rsp)
movslq 0x88(%rsp), %rax
movl 0x90(%rsp), %r15d
movl 0x94(%rsp), %ebp
andq $0x0, 0x10(%rsp)
movq 0x98(%rsp), %r13
movq 0x10(%rbx), %rcx
imulq $0x28, %rax, %rax
movq 0x18(%rcx,%rax), %rdi
movq %r12, %rsi
callq 0x1d923
pushq $0x2c
popq %rdi
movq %r12, %rsi
callq 0x1d946
movq %r15, 0x68(%rsp)
movl %r15d, %eax
andl $0x1, %eax
leaq 0x5c05(%rip), %rcx      # 0x238dd
movsbl (%rax,%rcx), %edi
movq %r12, %rsi
callq 0x1d946
movq 0x60(%rsp), %rsi
movq %rsi, %rcx
incq %rcx
jne 0x1dd01
pushq $0x30
popq %rdi
movq %r12, %rsi
callq 0x1d946
jmp 0x1ddc8
movq %rcx, %rax
negq %rax
cmovsq %rcx, %rax
xorl %ebx, %ebx
pushq $0xa
popq %rcx
testq %rax, %rax
je 0x1dd29
xorl %edx, %edx
divq %rcx
orb $0x30, %dl
movb %dl, 0x80(%rsp,%rbx)
incq %rbx
jmp 0x1dd10
cmpq $-0x2, %rsi
jg 0x1dd3a
movb $0x2d, 0x80(%rsp,%rbx)
incq %rbx
movq 0x10(%rsp), %r15
movq 0x20(%rsp), %rax
leaq (%rbx,%r15), %rcx
incq %rcx
cmpq 0x18(%rsp), %rcx
jb 0x1ddb9
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 0x59df(%rip), %rdx      # 0x23774
pushq $0x6a
popq %rcx
leaq 0x63e8(%rip), %r8       # 0x24187
callq 0x1e0b4
movq %rax, 0x20(%rsp)
jmp 0x1ddb9
movb 0x7f(%rsp,%rbx), %cl
decq %rbx
movb %cl, (%rax,%r15)
incq %r15
testq %rbx, %rbx
jg 0x1ddab
movq %r15, 0x10(%rsp)
movb $0x0, (%rax,%r15)
movq 0x8(%rsp), %r15
pushq $0x2c
popq %rdi
movq %r12, %rsi
callq 0x1d946
testl %ebp, %ebp
movl $0x0, %eax
cmovlel %eax, %ebp
xorl %ebx, %ebx
cmpq %rbx, %rbp
je 0x1de19
movl (%r13,%rbx,4), %edi
shrl $0x4, %edi
movq %r12, %rsi
callq 0x1d9da
movl (%r13,%rbx,4), %eax
andl $0xf, %eax
leaq 0x6865(%rip), %rcx      # 0x2466d
movsbl (%rax,%rcx), %edi
movq %r12, %rsi
callq 0x1d946
incq %rbx
jmp 0x1dde4
pushq $0x2c
popq %rdi
movq %r12, %rsi
callq 0x1d946
movq 0x68(%rsp), %rdi
shrl $0xa, %edi
movq %r12, %rsi
callq 0x1d9da
pushq $0x3b
popq %rdi
movq %r12, %rsi
callq 0x1d946
movq %r13, %rdi
callq 0x3390
movq 0x20(%rsp), %rbx
movl 0x10(%rsp), %esi
imulq $0x18, 0x70(%rsp), %rdx
movq 0x40(%rsp), %rbp
addq %rbp, %rdx
movq %rbx, %rdi
callq 0x1df28
incq %r14
movq 0x78(%rsp), %r13
jmp 0x1dbe1
movq %rbx, %r14
leaq 0x674b(%rip), %rdx      # 0x245c8
leaq 0x67dd(%rip), %r8       # 0x24661
pushq $0x8
popq %rsi
movl $0x9e, %ecx
callq 0x1dfd0
movq %rax, %rbx
movq (%r13), %rax
movq %rbp, %rcx
addq $0x10, %rcx
xorl %edx, %edx
movq 0x38(%rsp), %r12
cmpq %rdx, %rax
je 0x1dec0
movq (%rcx), %rsi
movq %rsi, (%rbx,%rdx,8)
incq %rdx
addq $0x18, %rcx
jmp 0x1dea6
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x28(%rsp), %rdi
callq 0x3390
movq %r12, %rdi
callq 0x3390
movq %rbp, %rdi
callq 0x3390
movq %r14, %rdi
callq 0x3390
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq