// File: /workspace/github_c_makefile_star2_O0/lh3[P]minimap2/align.c
// Function: mm_align_skeleton
mm_reg1_t *mm_align_skeleton(void *km, const mm_mapopt_t *opt, const mm_idx_t *mi, int qlen, const char *qstr, int *n_regs_, mm_reg1_t *regs, mm128_t *a)
{
	extern unsigned char seq_nt4_table[256];
	int32_t i, n_regs = *n_regs_, n_a;
	uint8_t *qseq0[2];
	ksw_extz_t ez;

	// encode the query sequence
	qseq0[0] = (uint8_t*)kmalloc(km, qlen * 2);
	qseq0[1] = qseq0[0] + qlen;
	for (i = 0; i < qlen; ++i) {
		qseq0[0][i] = seq_nt4_table[(uint8_t)qstr[i]];
		qseq0[1][qlen - 1 - i] = qseq0[0][i] < 4? 3 - qseq0[0][i] : 4;
	}

	// align through seed hits
	n_a = mm_squeeze_a(km, n_regs, regs, a);
	memset(&ez, 0, sizeof(ksw_extz_t));
	for (i = 0; i < n_regs; ++i) {
		mm_reg1_t r2; // only used for inversion
		if ((opt->flag&MM_F_SPLICE) && (opt->flag&MM_F_SPLICE_FOR) && (opt->flag&MM_F_SPLICE_REV)) { // then do two rounds of alignments for both strands
			mm_reg1_t s[2], s2[2], *r;
			s[0] = s[1] = regs[i];
			mm_align1(km, opt, mi, qlen, qseq0, &s[0], &s2[0], n_a, a, &ez, MM_F_SPLICE_FOR); // assume the transcript is on the + strand of the genome
			if ((opt->flag&MM_F_SR_RNA) && regs[i].qe - regs[i].qs == regs[i].re - regs[i].rs && s[0].qe - s[0].qs == s[0].re - s[0].rs && s[0].qs == 0 && s[0].qe == qlen) {
				regs[i] = s[0], r2 = s2[0];
				regs[i].p->trans_strand = 0;
			} else {
				int which, trans_strand;
				mm_align1(km, opt, mi, qlen, qseq0, &s[1], &s2[1], n_a, a, &ez, MM_F_SPLICE_REV); // assume the transcript on the - strand
				if (s[0].p->dp_score > s[1].p->dp_score) which = 0, trans_strand = 1;
				else if (s[0].p->dp_score < s[1].p->dp_score) which = 1, trans_strand = 2;
				else trans_strand = 3, which = (qlen + s[0].p->dp_score) & 1; // randomly choose a strand, effectively
				if (which == 0) {
					regs[i] = s[0], r2 = s2[0];
					free(s[1].p);
				} else {
					regs[i] = s[1], r2 = s2[1];
					free(s[0].p);
				}
				r = &regs[i];
				r->p->trans_strand = trans_strand;
				if (r->is_spliced) {
					if (trans_strand == 1 || trans_strand == 2) // this is an *approximate* way to tell if there are splice signals.
						r->p->dp_max += (opt->a + opt->b) + ((opt->a + opt->b) >> 1);
					else if (trans_strand == 3)
						r->p->dp_max -= opt->a + opt->b;
				}
			}
		} else { // one round of alignment
			mm_align1(km, opt, mi, qlen, qseq0, &regs[i], &r2, n_a, a, &ez, opt->flag);
			if (opt->flag&MM_F_SPLICE)
				regs[i].p->trans_strand = opt->flag&MM_F_SPLICE_FOR? 1 : 2;
		}
		if (r2.cnt > 0) regs = mm_insert_reg(&r2, i, &n_regs, regs);
		if (i > 0 && regs[i].split_inv && !(opt->flag & MM_F_NO_INV)) {
			if (mm_align1_inv(km, opt, mi, qlen, qseq0, &regs[i-1], &regs[i], &r2, &ez)) {
				regs = mm_insert_reg(&r2, i, &n_regs, regs);
				++i; // skip the inserted INV alignment
			}
		}
	}
	*n_regs_ = n_regs;
	kfree(km, qseq0[0]);
	kfree(km, ez.cigar);
	mm_filter_regs(opt, qlen, n_regs_, regs);
	if (!(opt->flag&(MM_F_SR|MM_F_SR_RNA|MM_F_ALL_CHAINS)) && !opt->split_prefix && qlen >= opt->rank_min_len) {
		mm_update_dp_max(qlen, *n_regs_, regs, opt->rank_frac, opt->a, opt->b);
		mm_filter_regs(opt, qlen, n_regs_, regs);
	}
	mm_hit_sort(km, n_regs_, regs, opt->alt_drop);
	return regs;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x270, %rsp            # imm = 0x270
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movl %ecx, -0x2c(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %eax
shll %eax
movslq %eax, %rsi
callq 0x1aae0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movslq -0x2c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x22d12
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x3bb7e(%rip), %rax     # 0x5e820
movb (%rax,%rcx), %dl
movq -0x60(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x60(%rbp), %rax
movslq -0x44(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x4, %eax
jge 0x22cdc
movq -0x60(%rbp), %rax
movslq -0x44(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
movl $0x3, %eax
subl %ecx, %eax
movl %eax, -0x244(%rbp)
jmp 0x22ce9
movl $0x4, %eax
movl %eax, -0x244(%rbp)
jmp 0x22ce9
movl -0x244(%rbp), %eax
movb %al, %dl
movq -0x58(%rbp), %rax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
subl -0x44(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x22c81
movq -0x18(%rbp), %rdi
movl -0x48(%rbp), %esi
movq 0x10(%rbp), %rdx
movq 0x18(%rbp), %rcx
callq 0x2b680
movl %eax, -0x4c(%rbp)
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x21b0
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x23315
movq -0x20(%rbp), %rax
movq (%rax), %rax
andq $0x80, %rax
cmpq $0x0, %rax
je 0x23166
movq -0x20(%rbp), %rax
movq (%rax), %rax
andq $0x100, %rax            # imm = 0x100
cmpq $0x0, %rax
je 0x23166
movq -0x20(%rbp), %rax
movq (%rax), %rax
andq $0x200, %rax            # imm = 0x200
cmpq $0x0, %rax
je 0x23166
leaq -0x190(%rbp), %rax
movq %rax, -0x258(%rbp)
leaq -0x190(%rbp), %rdi
addq $0x50, %rdi
movq %rdi, -0x250(%rbp)
movq 0x10(%rbp), %rsi
movslq -0x44(%rbp), %rax
imulq $0x50, %rax, %rax
addq %rax, %rsi
movl $0x50, %edx
callq 0x2290
movq -0x258(%rbp), %rdi
movq -0x250(%rbp), %rsi
movl $0x50, %edx
callq 0x2290
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
leaq -0x60(%rbp), %r8
leaq -0x190(%rbp), %r9
leaq -0x230(%rbp), %rbx
movl -0x4c(%rbp), %r11d
movq 0x18(%rbp), %r10
leaq -0x98(%rbp), %rax
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movl $0x100, 0x20(%rsp)      # imm = 0x100
callq 0x233f0
movq -0x20(%rbp), %rcx
movabsq $0x8000000000, %rax     # imm = 0x8000000000
andq (%rcx), %rax
cmpq $0x0, %rax
je 0x22f2f
movq 0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq 0x10(%rbp), %rcx
movslq -0x44(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rcx
subl 0x10(%rcx), %eax
movq 0x10(%rbp), %rcx
movslq -0x44(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rcx
movl 0x1c(%rcx), %ecx
movq 0x10(%rbp), %rdx
movslq -0x44(%rbp), %rsi
imulq $0x50, %rsi, %rsi
addq %rsi, %rdx
subl 0x18(%rdx), %ecx
cmpl %ecx, %eax
jne 0x22f2f
movl -0x17c(%rbp), %eax
subl -0x180(%rbp), %eax
movl -0x174(%rbp), %ecx
subl -0x178(%rbp), %ecx
cmpl %ecx, %eax
jne 0x22f2f
cmpl $0x0, -0x180(%rbp)
jne 0x22f2f
movl -0x17c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x22f2f
movq 0x10(%rbp), %rdi
movslq -0x44(%rbp), %rax
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq -0x190(%rbp), %rsi
movl $0x50, %edx
callq 0x2290
leaq -0x230(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
movl $0x50, %edx
callq 0x2290
movq 0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x48(%rax), %rax
movl 0x14(%rax), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
orl $0x0, %ecx
movl %ecx, 0x14(%rax)
jmp 0x23161
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
leaq -0x60(%rbp), %r8
leaq -0x190(%rbp), %r9
addq $0x50, %r9
leaq -0x230(%rbp), %rbx
addq $0x50, %rbx
movl -0x4c(%rbp), %r11d
movq 0x18(%rbp), %r10
leaq -0x98(%rbp), %rax
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movl $0x200, 0x20(%rsp)      # imm = 0x200
callq 0x233f0
movq -0x148(%rbp), %rax
movl 0x4(%rax), %eax
movq -0xf8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jle 0x22fb3
movl $0x0, -0x23c(%rbp)
movl $0x1, -0x240(%rbp)
jmp 0x23001
movq -0x148(%rbp), %rax
movl 0x4(%rax), %eax
movq -0xf8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x22fdf
movl $0x1, -0x23c(%rbp)
movl $0x2, -0x240(%rbp)
jmp 0x22fff
movl $0x3, -0x240(%rbp)
movl -0x2c(%rbp), %eax
movq -0x148(%rbp), %rcx
addl 0x4(%rcx), %eax
andl $0x1, %eax
movl %eax, -0x23c(%rbp)
jmp 0x23001
cmpl $0x0, -0x23c(%rbp)
jne 0x23050
movq 0x10(%rbp), %rdi
movslq -0x44(%rbp), %rax
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq -0x190(%rbp), %rsi
movl $0x50, %edx
callq 0x2290
leaq -0x230(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
movl $0x50, %edx
callq 0x2290
movq -0xf8(%rbp), %rdi
callq 0x2040
jmp 0x2309c
movq 0x10(%rbp), %rdi
movslq -0x44(%rbp), %rax
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq -0x190(%rbp), %rsi
addq $0x50, %rsi
movl $0x50, %edx
callq 0x2290
leaq -0x230(%rbp), %rsi
addq $0x50, %rsi
leaq -0xe8(%rbp), %rdi
movl $0x50, %edx
callq 0x2290
movq -0x148(%rbp), %rdi
callq 0x2040
movq 0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x238(%rbp)
movl -0x240(%rbp), %edx
movq -0x238(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x14(%rax), %ecx
andl $0x3, %edx
shll $0x1e, %edx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
orl %edx, %ecx
movl %ecx, 0x14(%rax)
movq -0x238(%rbp), %rax
movl 0x3c(%rax), %eax
shrl $0x1b, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2315f
cmpl $0x1, -0x240(%rbp)
je 0x230fe
cmpl $0x2, -0x240(%rbp)
jne 0x23131
movq -0x20(%rbp), %rax
movl 0x64(%rax), %ecx
movq -0x20(%rbp), %rax
addl 0x68(%rax), %ecx
movq -0x20(%rbp), %rax
movl 0x64(%rax), %eax
movq -0x20(%rbp), %rdx
addl 0x68(%rdx), %eax
sarl %eax
addl %eax, %ecx
movq -0x238(%rbp), %rax
movq 0x48(%rax), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
jmp 0x2315d
cmpl $0x3, -0x240(%rbp)
jne 0x2315b
movq -0x20(%rbp), %rax
movl 0x64(%rax), %edx
movq -0x20(%rbp), %rax
addl 0x68(%rax), %edx
movq -0x238(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
jmp 0x2315d
jmp 0x2315f
jmp 0x23161
jmp 0x2321a
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
leaq -0x60(%rbp), %r8
movq 0x10(%rbp), %r9
movslq -0x44(%rbp), %rax
imulq $0x50, %rax, %rax
addq %rax, %r9
movl -0x4c(%rbp), %ebx
movq 0x18(%rbp), %r11
movq -0x20(%rbp), %rax
movq (%rax), %rax
leaq -0xe8(%rbp), %r14
leaq -0x98(%rbp), %r10
movq %r14, (%rsp)
movl %ebx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0x233f0
movq -0x20(%rbp), %rax
movq (%rax), %rax
andq $0x80, %rax
cmpq $0x0, %rax
je 0x23218
movq -0x20(%rbp), %rax
movq (%rax), %rcx
andq $0x100, %rcx            # imm = 0x100
movl $0x2, %edx
movl $0x1, %eax
cmpq $0x0, %rcx
cmovnel %eax, %edx
movq 0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x48(%rax), %rax
movl 0x14(%rax), %ecx
andl $0x3, %edx
shll $0x1e, %edx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
orl %edx, %ecx
movl %ecx, 0x14(%rax)
jmp 0x2321a
cmpl $0x0, -0xe4(%rbp)
jle 0x2323e
movl -0x44(%rbp), %esi
movq 0x10(%rbp), %rcx
leaq -0xe8(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x25a00
movq %rax, 0x10(%rbp)
cmpl $0x0, -0x44(%rbp)
jle 0x23305
movq 0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movl 0x3c(%rax), %eax
shrl $0x18, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x23305
movq -0x20(%rbp), %rcx
movabsq $0x200000000, %rax      # imm = 0x200000000
andq (%rcx), %rax
cmpq $0x0, %rax
jne 0x23305
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
leaq -0x60(%rbp), %r8
movq 0x10(%rbp), %r9
movl -0x44(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x50, %rax, %rax
addq %rax, %r9
movq 0x10(%rbp), %r11
movslq -0x44(%rbp), %rax
imulq $0x50, %rax, %rax
addq %rax, %r11
leaq -0xe8(%rbp), %r10
leaq -0x98(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x25ac0
cmpl $0x0, %eax
je 0x23303
movl -0x44(%rbp), %esi
movq 0x10(%rbp), %rcx
leaq -0xe8(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x25a00
movq %rax, 0x10(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x23305
jmp 0x23307
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x22d43
movl -0x48(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x1a8c0
movq -0x18(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1a8c0
movq -0x20(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x40(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x2b4e0
movq -0x20(%rbp), %rcx
movabsq $0x8000801000, %rax     # imm = 0x8000801000
andq (%rcx), %rax
cmpq $0x0, %rax
jne 0x233c1
movq -0x20(%rbp), %rax
cmpq $0x0, 0x100(%rax)
jne 0x233c1
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0xb0(%rcx), %eax
jl 0x233c1
movl -0x2c(%rbp), %edi
movq -0x40(%rbp), %rax
movl (%rax), %esi
movq 0x10(%rbp), %rdx
movq -0x20(%rbp), %rax
movss 0xb4(%rax), %xmm0
movq -0x20(%rbp), %rax
movl 0x64(%rax), %ecx
movq -0x20(%rbp), %rax
movl 0x68(%rax), %r8d
callq 0x22860
movq -0x20(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x40(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x2b4e0
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq 0x10(%rbp), %rdx
movq -0x20(%rbp), %rax
movss 0x60(%rax), %xmm0
callq 0x2aae0
movq 0x10(%rbp), %rax
addq $0x270, %rsp            # imm = 0x270
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax,%rax)