// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq 0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movl 0x20(%rbp), %eax
movl %eax, -0x34(%rbp)
movl 0x28(%rbp), %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
movq 0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x34(%rbp)
movb %al, -0x51(%rbp)
jl 0x33f99
cmpl $0x0, -0x38(%rbp)
setge %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x33fa5
jmp 0x341e8
movl $0xffffffff, -0x50(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, -0xc(%rbp)
je 0x34038
movl -0x34(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x34(%rbp), %eax
movq -0x28(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x33fd6
movl $0x2, -0x50(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x33ff4
movl -0x34(%rbp), %eax
movq 0x10(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x33ff4
movl $0x1, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jge 0x34029
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movslq 0x18(%rbp), %rdx
imulq %rdx, %rcx
movslq -0x34(%rbp), %rdx
addq %rdx, %rcx
movq -0x28(%rbp), %rdx
movslq -0x3c(%rbp), %rsi
movslq (%rdx,%rsi,4), %rdx
subq %rdx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x58(%rbp)
jmp 0x34030
xorl %eax, %eax
movl %eax, -0x58(%rbp)
jmp 0x34030
movl -0x58(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x340af
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
movslq -0x34(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x3404f
movl $0x2, -0x50(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x3406d
movl -0x38(%rbp), %eax
movq 0x10(%rbp), %rcx
movslq -0x34(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x3406d
movl $0x1, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jge 0x340a2
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movslq 0x18(%rbp), %rdx
imulq %rdx, %rcx
movslq -0x38(%rbp), %rdx
addq %rdx, %rcx
movq -0x28(%rbp), %rdx
movslq -0x34(%rbp), %rsi
movslq (%rdx,%rsi,4), %rdx
subq %rdx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x5c(%rbp)
jmp 0x340a9
xorl %eax, %eax
movl %eax, -0x5c(%rbp)
jmp 0x340a9
movl -0x5c(%rbp), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x340c0
movl -0x4c(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x40(%rbp)
jmp 0x340dc
movl -0x4c(%rbp), %eax
movl -0x40(%rbp), %ecx
addl $0x2, %ecx
shrl %cl, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x340da
movl $0x0, -0x40(%rbp)
jmp 0x340dc
cmpl $0x0, -0x40(%rbp)
jne 0x340eb
movl -0x4c(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x50(%rbp)
jl 0x340f7
movl -0x50(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x34136
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rcx
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x34310
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x341e3
cmpl $0x1, -0x40(%rbp)
je 0x34148
cmpl $0x3, -0x40(%rbp)
jne 0x34178
cmpl $0x0, -0x14(%rbp)
jg 0x34178
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rcx
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
movl $0x2, %r8d
movl $0x1, %r9d
callq 0x34310
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x341e1
cmpl $0x3, -0x40(%rbp)
jne 0x341b4
cmpl $0x0, -0x14(%rbp)
jle 0x341b4
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rcx
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
movl $0x3, %r8d
movl $0x1, %r9d
callq 0x34310
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x341df
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rcx
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
movl $0x1, %r9d
movl %r9d, %r8d
callq 0x34310
movq %rax, -0x48(%rbp)
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x341e1
jmp 0x341e3
jmp 0x33f84
cmpl $0x0, -0x34(%rbp)
jl 0x3424b
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x68(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x14(%rbp)
movb %al, -0x5d(%rbp)
jle 0x34215
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
setge %al
movb %al, -0x5d(%rbp)
movq -0x68(%rbp), %rcx
movq -0x70(%rbp), %rdi
movb -0x5d(%rbp), %dl
movl $0x2, %r8d
movl $0x3, %eax
testb $0x1, %dl
cmovnel %eax, %r8d
movl -0x34(%rbp), %r9d
addl $0x1, %r9d
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x34310
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x38(%rbp)
jl 0x34278
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rcx
movl -0x38(%rbp), %r9d
addl $0x1, %r9d
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
movl $0x1, %r8d
callq 0x34310
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x342e0
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0x2c(%rbp), %ecx
sarl %ecx
cmpl %ecx, %eax
jge 0x342de
movq -0x48(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
subl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x48(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x4c(%rbp), %edx
movq -0x48(%rbp), %rax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
subl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x34285
jmp 0x342e0
movl -0x30(%rbp), %ecx
movq 0x30(%rbp), %rax
movl %ecx, (%rax)
movl -0x2c(%rbp), %ecx
movq 0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rcx
movq 0x40(%rbp), %rax
movq %rcx, (%rax)
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)