// File: /workspace/github_c_makefile_star2_O1/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, 0x10(%rsp)
movl %esi, 0x24(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x98(%rsp), %rax
movq 0x88(%rsp), %rcx
movl 0x80(%rsp), %r13d
movl 0x78(%rsp), %r12d
movl (%rcx), %r10d
movq (%rax), %rax
testl %r12d, %r12d
setns %cl
testl %r13d, %r13d
setns %bpl
movl %r12d, %edx
orl %r13d, %edx
js 0x244eb
movq %r9, %r15
xorl %ebx, %ebx
xorl %r14d, %r14d
movq %r8, 0x18(%rsp)
leal (%r12,%r13), %edi
movslq (%r8,%rdi,4), %rcx
xorl %edx, %edx
cmpl %ecx, %r12d
setl %dl
leal (%rdx,%rdx,2), %edx
decl %edx
testq %r15, %r15
je 0x242dc
cmpl (%r15,%rdi,4), %r12d
movl $0x1, %esi
cmovgl %esi, %edx
xorl %esi, %esi
testl %edx, %edx
jns 0x242fc
movl 0x70(%rsp), %esi
imulq %rsi, %rdi
movl %r12d, %esi
addq %rdi, %rsi
subq %rcx, %rsi
movq 0x30(%rsp), %rcx
movzbl (%rcx,%rsi), %esi
movl %esi, %edi
testl %ebx, %ebx
je 0x24310
movl %ebx, %ecx
shrl %cl, %edi
shll $0x1d, %edi
sarl $0x1f, %edi
andl %ebx, %edi
jmp 0x24313
andl $0x7, %edi
andl $0x7, %esi
testl %edi, %edi
cmovnel %edi, %esi
testl %edx, %edx
movl %esi, %ebx
cmovnsl %edx, %ebx
cmpl $0x1, %ebx
je 0x24391
testl %ebx, %ebx
jne 0x24385
testl %r14d, %r14d
je 0x24340
movslq %r14d, %rcx
movl -0x4(%rax,%rcx,4), %edx
testb $0xf, %dl
je 0x2447b
cmpl %r10d, %r14d
jne 0x24373
leal (%r10,%r10), %ebp
testl %r10d, %r10d
movl $0x4, %ecx
cmovel %ecx, %ebp
leal (,%rbp,4), %ecx
movslq %ecx, %rdx
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x127ec
movq 0x18(%rsp), %r8
movl %ebp, %r10d
movslq %r14d, %rcx
incl %r14d
movl $0x10, (%rax,%rcx,4)
jmp 0x24482
cmpl $0x0, 0x10(%rsp)
jg 0x243f8
cmpl $0x3, %ebx
jne 0x243f8
testl %r14d, %r14d
je 0x243b0
movslq %r14d, %rcx
movl -0x4(%rax,%rcx,4), %edx
movl %edx, %esi
andl $0xf, %esi
cmpl $0x2, %esi
jne 0x243b0
addl $0x10, %edx
movl %edx, -0x4(%rax,%rcx,4)
jmp 0x243f0
cmpl %r10d, %r14d
jne 0x243e3
leal (%r10,%r10), %ebp
testl %r10d, %r10d
movl $0x4, %ecx
cmovel %ecx, %ebp
leal (,%rbp,4), %ecx
movslq %ecx, %rdx
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x127ec
movq 0x18(%rsp), %r8
movl %ebp, %r10d
movslq %r14d, %rcx
incl %r14d
movl $0x12, (%rax,%rcx,4)
decl %r12d
jmp 0x24488
cmpl $0x0, 0x10(%rsp)
jle 0x2445c
cmpl $0x3, %ebx
jne 0x2445c
testl %r14d, %r14d
je 0x2441a
movslq %r14d, %rcx
movl -0x4(%rax,%rcx,4), %edx
movl %edx, %esi
andl $0xf, %esi
cmpl $0x3, %esi
je 0x243a7
cmpl %r10d, %r14d
jne 0x2444d
leal (%r10,%r10), %ebp
testl %r10d, %r10d
movl $0x4, %ecx
cmovel %ecx, %ebp
leal (,%rbp,4), %ecx
movslq %ecx, %rdx
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x127ec
movq 0x18(%rsp), %r8
movl %ebp, %r10d
movslq %r14d, %rcx
incl %r14d
movl $0x13, (%rax,%rcx,4)
jmp 0x243f0
movslq %r14d, %rsi
testl %r14d, %r14d
je 0x244a2
movl -0x4(%rax,%rsi,4), %ecx
movl %ecx, %edx
andl $0xf, %edx
cmpl $0x1, %edx
jne 0x244a2
addl $0x10, %ecx
movl %ecx, -0x4(%rax,%rsi,4)
jmp 0x24485
addl $0x10, %edx
movl %edx, -0x4(%rax,%rcx,4)
decl %r12d
decl %r13d
testl %r13d, %r13d
setns %bpl
testl %r12d, %r12d
setns %cl
js 0x244ee
testl %r13d, %r13d
jns 0x242b6
jmp 0x244ee
cmpl %r10d, %r14d
jne 0x244df
leal (%r10,%r10), %ebp
testl %r10d, %r10d
movl $0x4, %ecx
cmovel %ecx, %ebp
leal (,%rbp,4), %ecx
movslq %ecx, %rdx
movq 0x8(%rsp), %rdi
movq %rsi, 0x28(%rsp)
movq %rax, %rsi
callq 0x127ec
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %r8
movl %ebp, %r10d
incl %r14d
movl $0x11, (%rax,%rsi,4)
jmp 0x24485
xorl %r14d, %r14d
testb %cl, %cl
je 0x2457a
movl 0x10(%rsp), %edx
testl %edx, %edx
setg %cl
cmpl %edx, %r12d
setge %dl
andb %cl, %dl
movzbl %dl, %ebx
orl $0x2, %ebx
incl %r12d
movslq %r14d, %rsi
testl %r14d, %r14d
je 0x24532
movl -0x4(%rax,%rsi,4), %ecx
movl %ecx, %edx
andl $0xf, %edx
cmpl %ebx, %edx
jne 0x24532
shll $0x4, %r12d
addl %r12d, %ecx
movl %ecx, -0x4(%rax,%rsi,4)
jmp 0x2457a
cmpl %r10d, %r14d
jne 0x2456d
leal (%r10,%r10), %ecx
testl %r10d, %r10d
movl $0x4, %r15d
cmovnel %ecx, %r15d
leal (,%r15,4), %ecx
movslq %ecx, %rdx
movq 0x8(%rsp), %rdi
movq %rsi, 0x10(%rsp)
movq %rax, %rsi
callq 0x127ec
movq 0x10(%rsp), %rsi
movq %r15, %r10
shll $0x4, %r12d
orl %r12d, %ebx
incl %r14d
movl %ebx, (%rax,%rsi,4)
testb %bpl, %bpl
je 0x245e4
incl %r13d
movslq %r14d, %rbx
testl %r14d, %r14d
je 0x245a5
movl -0x4(%rax,%rbx,4), %ecx
movl %ecx, %edx
andl $0xf, %edx
cmpl $0x1, %edx
jne 0x245a5
shll $0x4, %r13d
addl %r13d, %ecx
movl %ecx, -0x4(%rax,%rbx,4)
jmp 0x245e4
cmpl %r10d, %r14d
jne 0x245d6
leal (%r10,%r10), %ecx
testl %r10d, %r10d
movl $0x4, %r15d
cmovnel %ecx, %r15d
leal (,%r15,4), %ecx
movslq %ecx, %rdx
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x127ec
movq %r15, %r10
shll $0x4, %r13d
incl %r13d
incl %r14d
movl %r13d, (%rax,%rbx,4)
movq 0x90(%rsp), %rcx
cmpl $0x0, 0x24(%rsp)
jne 0x24621
movl %r14d, %edx
sarl %edx
testl %edx, %edx
jle 0x24621
movl %edx, %edx
leal -0x1(%r14), %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 0x24604
movq 0x88(%rsp), %rdx
movl %r10d, (%rdx)
movl %r14d, (%rcx)
movq 0x98(%rsp), %rcx
movq %rax, (%rcx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)