// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x58(%rbp)
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3130
movq $0x0, -0x78(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movl $0x4, %esi
leaq 0x9fc3(%rip), %rdx      # 0x3b3f9
movl $0x81, %ecx
leaq 0xa050(%rip), %r8       # 0x3b492
callq 0x31bf0
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movl $0x1, %esi
leaq 0x9f9b(%rip), %rdx      # 0x3b3f9
movl $0x82, %ecx
leaq 0xa028(%rip), %r8       # 0x3b492
callq 0x31bf0
movq %rax, -0x80(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x4c(%rbp)
movslq -0x34(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x3150d
movq -0x8(%rbp), %rax
movss 0xa4(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x34(%rbp), %esi
callq 0x317f0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x314fd
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl 0x48(%rax), %eax
sarl $0x1e, %eax
cmpl $0x0, %eax
je 0x314fb
movq -0x80(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb $0x1, (%rax,%rcx)
jmp 0x314fd
jmp 0x314ff
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x31481
cmpl $0x0, -0x4c(%rbp)
jne 0x31518
jmp 0x317bf
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movl $0x18, %esi
leaq 0x9ece(%rip), %rdx      # 0x3b3f9
movl $0x8b, %ecx
leaq 0x9f5b(%rip), %r8       # 0x3b492
callq 0x31bf0
movq %rax, -0x58(%rbp)
movl $0x0, -0x34(%rbp)
movslq -0x34(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x31757
movq -0x8(%rbp), %rax
movss 0xa4(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x34(%rbp), %esi
callq 0x317f0
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
jge 0x31585
jmp 0x31749
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc0(%rcx), %eax
jg 0x315c1
movq -0x80(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x315c6
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
cmpl 0xbc(%rcx), %eax
jle 0x315c6
jmp 0x31749
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl -0x24(%rbp), %r8d
movq -0x30(%rbp), %r9
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x34(%rbp), %rdi
imulq $0x60, %rdi, %rdi
addq %rdi, %rax
leaq -0xf0(%rbp), %rdi
movq %rax, (%rsp)
callq 0x2b620
leaq -0xb8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
movl $0x38, %edx
callq 0x3250
movq $0x0, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xb0(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rdi
leaq -0x70(%rbp), %rsi
callq 0x31040
movl $0x2c, %edi
leaq -0x70(%rbp), %rsi
callq 0x31080
movl -0xa8(%rbp), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x90e3(%rip), %rax      # 0x3a745
movsbl (%rax,%rcx), %edi
leaq -0x70(%rbp), %rsi
callq 0x31080
movq -0xb8(%rbp), %rdi
addq $0x1, %rdi
leaq -0x70(%rbp), %rsi
callq 0x31870
movl $0x2c, %edi
leaq -0x70(%rbp), %rsi
callq 0x31080
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0xa4(%rbp), %eax
jge 0x316f1
movq -0xa0(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %edi
shrl $0x4, %edi
leaq -0x70(%rbp), %rsi
callq 0x311d0
movq -0xa0(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x9dc5(%rip), %rax      # 0x3b49e
movsbl (%rax,%rcx), %edi
leaq -0x70(%rbp), %rsi
callq 0x31080
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x31698
movl $0x2c, %edi
leaq -0x70(%rbp), %rsi
callq 0x31080
movl -0xa8(%rbp), %edi
shrl $0xa, %edi
leaq -0x70(%rbp), %rsi
callq 0x311d0
movl $0x3b, %edi
leaq -0x70(%rbp), %rsi
callq 0x31080
movq -0xa0(%rbp), %rdi
callq 0x3380
movq -0x60(%rbp), %rdi
movq -0x70(%rbp), %rax
movl %eax, %esi
movq -0x58(%rbp), %rdx
movslq -0x3c(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdx
callq 0x31a90
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x31547
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movl $0x8, %esi
leaq 0x9c8f(%rip), %rdx      # 0x3b3f9
movl $0x9e, %ecx
leaq 0x9d1c(%rip), %r8       # 0x3b492
callq 0x31bf0
movq %rax, -0x78(%rbp)
movl $0x0, -0x38(%rbp)
movslq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x317bd
movq -0x58(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdx
movq -0x78(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x31786
jmp 0x317bf
movq -0x80(%rbp), %rdi
callq 0x3380
movq -0x48(%rbp), %rdi
callq 0x3380
movq -0x58(%rbp), %rdi
callq 0x3380
movq -0x60(%rbp), %rdi
callq 0x3380
movq -0x78(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq