// File: /workspace/github_c_makefile_star2_O0/nh13[P]ksw/src/ksw2/./ksw2.h
// Function: ksw_backtrack
static inline void ksw_backtrack(void *km, int is_rot, int is_rev, int with_N, 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[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[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, 0, 1), --i, --j; // match
		else if (state == 1 || (state == 3 && !with_N)) cigar = ksw_push_cigar(km, &n_cigar, &m_cigar, cigar, 2, 1), --i; // deletion
		else if (state == 3 && with_N) cigar = ksw_push_cigar(km, &n_cigar, &m_cigar, cigar, 3, 1), --i; // intron
		else cigar = ksw_push_cigar(km, &n_cigar, &m_cigar, cigar, 1, 1), --j; // insertion
	}
	if (i >= 0) cigar = ksw_push_cigar(km, &n_cigar, &m_cigar, cigar, 2, i + 1); // first deletion
	if (j >= 0) cigar = ksw_push_cigar(km, &n_cigar, &m_cigar, cigar, 1, 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 $0x60, %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 0x1a02b9
cmpl $0x0, -0x38(%rbp)
setge %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x1a02c5
jmp 0x1a04f0
movl $0xffffffff, -0x50(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, -0xc(%rbp)
je 0x1a034a
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 0x1a02f2
movl $0x2, -0x50(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x1a0310
movl -0x34(%rbp), %eax
movq 0x10(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x1a0310
movl $0x1, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jge 0x1a033b
movq -0x20(%rbp), %rax
movl -0x3c(%rbp), %ecx
imull 0x18(%rbp), %ecx
addl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rdx
movslq -0x3c(%rbp), %rsi
subl (%rdx,%rsi,4), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x58(%rbp)
jmp 0x1a0342
xorl %eax, %eax
movl %eax, -0x58(%rbp)
jmp 0x1a0342
movl -0x58(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x1a03b7
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
movslq -0x34(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x1a0361
movl $0x2, -0x50(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x1a037f
movl -0x38(%rbp), %eax
movq 0x10(%rbp), %rcx
movslq -0x34(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x1a037f
movl $0x1, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jge 0x1a03aa
movq -0x20(%rbp), %rax
movl -0x34(%rbp), %ecx
imull 0x18(%rbp), %ecx
addl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rdx
movslq -0x34(%rbp), %rsi
subl (%rdx,%rsi,4), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x5c(%rbp)
jmp 0x1a03b1
xorl %eax, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1a03b1
movl -0x5c(%rbp), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x1a03c8
movl -0x4c(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x40(%rbp)
jmp 0x1a03e4
movl -0x4c(%rbp), %eax
movl -0x40(%rbp), %ecx
addl $0x2, %ecx
shrl %cl, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1a03e2
movl $0x0, -0x40(%rbp)
jmp 0x1a03e4
cmpl $0x0, -0x40(%rbp)
jne 0x1a03f3
movl -0x4c(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x50(%rbp)
jl 0x1a03ff
movl -0x50(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x1a043e
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rcx
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x1a05e0
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 0x1a04eb
cmpl $0x1, -0x40(%rbp)
je 0x1a0450
cmpl $0x3, -0x40(%rbp)
jne 0x1a0480
cmpl $0x0, -0x14(%rbp)
jne 0x1a0480
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rcx
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
movl $0x2, %r8d
movl $0x1, %r9d
callq 0x1a05e0
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1a04e9
cmpl $0x3, -0x40(%rbp)
jne 0x1a04bc
cmpl $0x0, -0x14(%rbp)
je 0x1a04bc
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rcx
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
movl $0x3, %r8d
movl $0x1, %r9d
callq 0x1a05e0
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1a04e7
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rcx
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
movl $0x1, %r9d
movl %r9d, %r8d
callq 0x1a05e0
movq %rax, -0x48(%rbp)
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1a04e9
jmp 0x1a04eb
jmp 0x1a02a4
cmpl $0x0, -0x34(%rbp)
jl 0x1a051d
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rcx
movl -0x34(%rbp), %r9d
addl $0x1, %r9d
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
movl $0x2, %r8d
callq 0x1a05e0
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x38(%rbp)
jl 0x1a054a
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 0x1a05e0
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x1a05b2
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0x2c(%rbp), %ecx
sarl %ecx
cmpl %ecx, %eax
jge 0x1a05b0
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 0x1a0557
jmp 0x1a05b2
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 $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)