// File: /workspace/github_c_makefile_star2_O3/lh3[P]minimap2/./ksw2.h
// Function: ksw_backtrack
static inline void ksw_backtrack(void *km, int is_rot, int is_rev, int min_intron_len, const uint8_t *p, const int *off, const int *off_end, int n_col, int i0, int j0,
								 int *m_cigar_, int *n_cigar_, uint32_t **cigar_)
{ // p[] - lower 3 bits: which type gets the max; bit
	int n_cigar = 0, m_cigar = *m_cigar_, i = i0, j = j0, r, state = 0;
	uint32_t *cigar = *cigar_, tmp;
	while (i >= 0 && j >= 0) { // at the beginning of the loop, _state_ tells us which state to check
		int force_state = -1;
		if (is_rot) {
			r = i + j;
			if (i < off[r]) force_state = 2;
			if (off_end && i > off_end[r]) force_state = 1;
			tmp = force_state < 0? p[(size_t)r * n_col + i - off[r]] : 0;
		} else {
			if (j < off[i]) force_state = 2;
			if (off_end && j > off_end[i]) force_state = 1;
			tmp = force_state < 0? p[(size_t)i * n_col + j - off[i]] : 0;
		}
		if (state == 0) state = tmp & 7; // if requesting the H state, find state one maximizes it.
		else if (!(tmp >> (state + 2) & 1)) state = 0; // if requesting other states, _state_ stays the same if it is a continuation; otherwise, set to H
		if (state == 0) state = tmp & 7; // TODO: probably this line can be merged into the "else if" line right above; not 100% sure
		if (force_state >= 0) state = force_state;
		if (state == 0) cigar = ksw_push_cigar(km, &n_cigar, &m_cigar, cigar, KSW_CIGAR_MATCH, 1), --i, --j;
		else if (state == 1 || (state == 3 && min_intron_len <= 0)) cigar = ksw_push_cigar(km, &n_cigar, &m_cigar, cigar, KSW_CIGAR_DEL, 1), --i;
		else if (state == 3 && min_intron_len > 0) cigar = ksw_push_cigar(km, &n_cigar, &m_cigar, cigar, KSW_CIGAR_N_SKIP, 1), --i;
		else cigar = ksw_push_cigar(km, &n_cigar, &m_cigar, cigar, KSW_CIGAR_INS, 1), --j;
	}
	if (i >= 0) cigar = ksw_push_cigar(km, &n_cigar, &m_cigar, cigar, min_intron_len > 0 && i >= min_intron_len? KSW_CIGAR_N_SKIP : KSW_CIGAR_DEL, i + 1); // first deletion
	if (j >= 0) cigar = ksw_push_cigar(km, &n_cigar, &m_cigar, cigar, KSW_CIGAR_INS, j + 1); // first insertion
	if (!is_rev)
		for (i = 0; i < n_cigar>>1; ++i) // reverse CIGAR
			tmp = cigar[i], cigar[i] = cigar[n_cigar-1-i], cigar[n_cigar-1-i] = tmp;
	*m_cigar_ = m_cigar, *n_cigar_ = n_cigar, *cigar_ = cigar;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x30(%rsp)
movl %edx, 0xc(%rsp)
movl %esi, 0x24(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x98(%rsp), %rbx
movq 0x88(%rsp), %rax
movl 0x80(%rsp), %ebp
movl 0x78(%rsp), %r12d
movl (%rax), %r10d
movq (%rbx), %rax
testl %ebp, %ebp
setns %r14b
movl %r12d, %ecx
orl %ebp, %ecx
js 0x24579
movq %r9, %r15
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r8, 0x18(%rsp)
leal (%r12,%rbp), %ecx
movslq (%r8,%rcx,4), %rdx
testq %r15, %r15
je 0x242f0
cmpl %edx, %r12d
setl %r9b
xorl %esi, %esi
cmpl (%r15,%rcx,4), %r12d
setg %dil
orb %dil, %r9b
je 0x24301
movb %dil, %sil
movl $0x2, %edx
subl %esi, %edx
xorl %esi, %esi
jmp 0x242fc
cmpl %edx, %r12d
jge 0x24301
xorl %esi, %esi
movl $0x2, %edx
movb $0x1, %dil
jmp 0x24322
movl 0x70(%rsp), %esi
imulq %rsi, %rcx
movl %r12d, %esi
addq %rcx, %rsi
subq %rdx, %rsi
movq 0x30(%rsp), %rcx
movzbl (%rcx,%rsi), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %edi, %edi
testl %ebx, %ebx
je 0x24343
movl %esi, %r9d
movl %ebx, %ecx
shrl %cl, %r9d
shll $0x1d, %r9d
sarl $0x1f, %r9d
andl %ebx, %r9d
andl $0x7, %esi
movl %esi, %ebx
movl %r9d, %esi
jmp 0x24348
andl $0x7, %esi
movl %esi, %ebx
testl %esi, %esi
cmovnel %esi, %ebx
testb %dil, %dil
cmovnel %edx, %ebx
cmpl $0x1, %ebx
je 0x243c6
testl %ebx, %ebx
jne 0x243ba
testl %r13d, %r13d
je 0x24371
movslq %r13d, %rcx
movl -0x4(%rax,%rcx,4), %edx
testb $0xf, %dl
je 0x244ba
cmpl %r10d, %r13d
jne 0x243a8
addl %r10d, %r10d
testl %r13d, %r13d
movl $0x4, %ecx
cmovel %ecx, %r10d
leal (,%r10,4), %ecx
movslq %ecx, %rdx
movq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r10, %r14
callq 0x12755
movq 0x18(%rsp), %r8
movq %r14, %r10
movslq %r13d, %rcx
incl %r13d
movl $0x10, (%rax,%rcx,4)
jmp 0x244c1
cmpl $0x0, 0xc(%rsp)
jg 0x24431
cmpl $0x3, %ebx
jne 0x24431
testl %r13d, %r13d
je 0x243e5
movslq %r13d, %rcx
movl -0x4(%rax,%rcx,4), %edx
movl %edx, %esi
andl $0xf, %esi
cmpl $0x2, %esi
jne 0x243e5
addl $0x10, %edx
movl %edx, -0x4(%rax,%rcx,4)
jmp 0x24429
cmpl %r10d, %r13d
jne 0x2441c
addl %r10d, %r10d
testl %r13d, %r13d
movl $0x4, %ecx
cmovel %ecx, %r10d
leal (,%r10,4), %ecx
movslq %ecx, %rdx
movq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r10, %r14
callq 0x12755
movq 0x18(%rsp), %r8
movq %r14, %r10
movslq %r13d, %rcx
incl %r13d
movl $0x12, (%rax,%rcx,4)
decl %r12d
jmp 0x244c6
cmpl $0x0, 0xc(%rsp)
jle 0x24499
cmpl $0x3, %ebx
jne 0x24499
testl %r13d, %r13d
je 0x24453
movslq %r13d, %rcx
movl -0x4(%rax,%rcx,4), %edx
movl %edx, %esi
andl $0xf, %esi
cmpl $0x3, %esi
je 0x243dc
cmpl %r10d, %r13d
jne 0x2448a
addl %r10d, %r10d
testl %r13d, %r13d
movl $0x4, %ecx
cmovel %ecx, %r10d
leal (,%r10,4), %ecx
movslq %ecx, %rdx
movq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r10, %r14
callq 0x12755
movq 0x18(%rsp), %r8
movq %r14, %r10
movslq %r13d, %rcx
incl %r13d
movl $0x13, (%rax,%rcx,4)
jmp 0x24429
movslq %r13d, %r14
testl %r13d, %r13d
je 0x244db
movl -0x4(%rax,%r14,4), %ecx
movl %ecx, %edx
andl $0xf, %edx
cmpl $0x1, %edx
jne 0x244db
addl $0x10, %ecx
movl %ecx, -0x4(%rax,%r14,4)
jmp 0x244c4
addl $0x10, %edx
movl %edx, -0x4(%rax,%rcx,4)
decl %r12d
decl %ebp
testl %ebp, %ebp
setns %r14b
testl %r12d, %r12d
js 0x24523
testl %ebp, %ebp
jns 0x242bf
jmp 0x24523
cmpl %r10d, %r13d
jne 0x24516
addl %r10d, %r10d
testl %r13d, %r13d
movl $0x4, %ecx
cmovel %ecx, %r10d
movq %r10, 0x28(%rsp)
leal (,%r10,4), %ecx
movslq %ecx, %rdx
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x12755
movq 0x18(%rsp), %r8
movq 0x28(%rsp), %r10
incl %r13d
movl $0x11, (%rax,%r14,4)
jmp 0x244c4
testl %r12d, %r12d
js 0x2459f
movl 0xc(%rsp), %edx
testl %edx, %edx
setg %cl
cmpl %edx, %r12d
setge %dl
andb %cl, %dl
movzbl %dl, %ebx
orl $0x2, %ebx
incl %r12d
testl %r13d, %r13d
je 0x24598
movslq %r13d, %rcx
movl -0x4(%rax,%rcx,4), %edx
movl %edx, %esi
andl $0xf, %esi
cmpl %ebx, %esi
jne 0x245b6
shll $0x4, %r12d
addl %r12d, %edx
movl %edx, -0x4(%rax,%rcx,4)
testl %ebp, %ebp
js 0x246d4
incl %ebp
movq 0x98(%rsp), %rbx
jmp 0x24610
testl %r12d, %r12d
js 0x245a9
movl 0xc(%rsp), %edx
testl %edx, %edx
setg %cl
cmpl %edx, %r12d
setge %dl
andb %cl, %dl
movzbl %dl, %ebx
orl $0x2, %ebx
incl %r12d
xorl %r13d, %r13d
movb $0x1, %cl
jmp 0x245b8
movq 0x98(%rsp), %rbx
jmp 0x245ac
xorl %r13d, %r13d
testb %r14b, %r14b
jne 0x24609
jmp 0x24677
xorl %ecx, %ecx
cmpl %r10d, %r13d
jne 0x245ec
leal (,%r13,2), %edx
testb %cl, %cl
movl $0x4, %r15d
cmovel %edx, %r15d
leal (,%r15,4), %ecx
movslq %ecx, %rdx
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x12755
movq %r15, %r10
shll $0x4, %r12d
orl %r12d, %ebx
movslq %r13d, %rcx
incl %r13d
movl %ebx, (%rax,%rcx,4)
testb %r14b, %r14b
movq 0x98(%rsp), %rbx
je 0x24677
incl %ebp
testl %r13d, %r13d
je 0x24630
movslq %r13d, %rcx
movl -0x4(%rax,%rcx,4), %edx
movl %edx, %esi
andl $0xf, %esi
cmpl $0x1, %esi
jne 0x2462c
shll $0x4, %ebp
addl %ebp, %edx
movl %edx, -0x4(%rax,%rcx,4)
jmp 0x24677
xorl %ecx, %ecx
jmp 0x24635
xorl %r13d, %r13d
movb $0x1, %cl
cmpl %r10d, %r13d
jne 0x24669
leal (,%r13,2), %edx
testb %cl, %cl
movl $0x4, %r14d
cmovel %edx, %r14d
leal (,%r14,4), %ecx
movslq %ecx, %rdx
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x12755
movq %r14, %r10
shll $0x4, %ebp
incl %ebp
movslq %r13d, %rcx
incl %r13d
movl %ebp, (%rax,%rcx,4)
movq 0x90(%rsp), %rcx
cmpl $0x0, 0x24(%rsp)
jne 0x246b4
movl %r13d, %edx
sarl %edx
testl %edx, %edx
jle 0x246b4
movl %edx, %edx
leal -0x1(%r13), %esi
xorl %edi, %edi
movl (%rax,%rdi,4), %r8d
movslq %esi, %rsi
movl (%rax,%rsi,4), %r9d
movl %r9d, (%rax,%rdi,4)
movl %r8d, (%rax,%rsi,4)
incq %rdi
decl %esi
cmpq %rdi, %rdx
jne 0x24697
movq 0x88(%rsp), %rdx
movl %r10d, (%rdx)
movl %r13d, (%rcx)
movq %rax, (%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x98(%rsp), %rbx
jmp 0x24677
nop