// File: /workspace/github_c_makefile_star2_O0/lh3[P]minigraph/miniwfa.c
// Function: wf_traceback
static uint32_t *wf_traceback(void *km, const mwf_opt_t *opt, wf_tb_t *tb, int32_t t_end, const char *ts, int32_t q_end, const char *qs, int32_t last, int32_t *n_cigar)
{
	wf_cigar_t cigar = {0,0,0};
	int32_t i = q_end, k = t_end, s = tb->n - 1;
	while (i >= 0 && k >= 0) {
		int32_t k0 = k, j, x, state, ext;
		if (last == 0) { // if the previous state is 0, check exact matches
			while (i >= 0 && k >= 0 && qs[i] == ts[k])
				--i, --k;
			if (k0 - k > 0)
				wf_cigar_push1(km, &cigar, 7, k0 - k);
			if (i < 0 || k < 0) break;
		}
		assert(s >= 0);
		j = i - k - tb->a[s].lo;
		assert(j <= tb->a[s].hi - tb->a[s].lo);
		x = tb->a[s].x[j];
		state = last == 0? x&7 : last;
		ext = state > 0? x>>(state+2)&1 : 0; // whether an extension
		//fprintf(stderr, "s=%d, %d->%d, ext=%d%d%d%d, i=%d, k=%d\n", s, last, state, x>>3&1, x>>4&1, x>>5&1, x>>6&1, i, k);
		if (state == 0) {
			wf_cigar_push1(km, &cigar, 8, 1);
			--i, --k, s -= opt->x;
		} else if (state == 1) {
			wf_cigar_push1(km, &cigar, 1, 1);
			--i, s -= ext? opt->e1 : opt->o1 + opt->e1;
		} else if (state == 3) {
			wf_cigar_push1(km, &cigar, 1, 1);
			--i, s -= ext? opt->e2 : opt->o2 + opt->e2;
		} else if (state == 2) {
			wf_cigar_push1(km, &cigar, 2, 1);
			--k, s -= ext? opt->e1 : opt->o1 + opt->e1;
		} else if (state == 4) {
			wf_cigar_push1(km, &cigar, 2, 1);
			--k, s -= ext? opt->e2 : opt->o2 + opt->e2;
		} else abort();
		last = state > 0 && ext? state : 0;
	}
	if (opt->flag&MWF_F_DEBUG) fprintf(stderr, "s0=%d, s=%d, i=%d, k=%d\n", tb->n-1, s, i, k);
	if (i >= 0) wf_cigar_push1(km, &cigar, 1, i + 1);
	else if (k >= 0) wf_cigar_push1(km, &cigar, 2, k + 1);
	for (i = 0; i < cigar.n>>1; ++i) { // reverse to the input order
		uint32_t t = cigar.cigar[i];
		cigar.cigar[i] = cigar.cigar[cigar.n - i - 1];
		cigar.cigar[cigar.n - i - 1] = t;
	}
	*n_cigar = cigar.n;
	return cigar.cigar;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2190
movl -0x2c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
movl %eax, -0x4c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x44(%rbp)
movb %al, -0x65(%rbp)
jl 0x1f8eb
cmpl $0x0, -0x48(%rbp)
setge %al
movb %al, -0x65(%rbp)
movb -0x65(%rbp), %al
testb $0x1, %al
jne 0x1f8f7
jmp 0x1fc66
movl -0x48(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, 0x18(%rbp)
jne 0x1f992
jmp 0x1f909
xorl %eax, %eax
cmpl $0x0, -0x44(%rbp)
movb %al, -0x66(%rbp)
jl 0x1f93f
xorl %eax, %eax
cmpl $0x0, -0x48(%rbp)
movb %al, -0x66(%rbp)
jl 0x1f93f
movq 0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x28(%rbp), %rcx
movslq -0x48(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x66(%rbp)
movb -0x66(%rbp), %al
testb $0x1, %al
jne 0x1f948
jmp 0x1f95c
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x48(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1f909
movl -0x50(%rbp), %eax
subl -0x48(%rbp), %eax
cmpl $0x0, %eax
jle 0x1f97f
movq -0x8(%rbp), %rdi
movl -0x50(%rbp), %ecx
subl -0x48(%rbp), %ecx
leaq -0x40(%rbp), %rsi
movl $0x7, %edx
callq 0x1e6d0
cmpl $0x0, -0x44(%rbp)
jl 0x1f98b
cmpl $0x0, -0x48(%rbp)
jge 0x1f990
jmp 0x1fc66
jmp 0x1f992
cmpl $0x0, -0x4c(%rbp)
jl 0x1f99a
jmp 0x1f9b9
leaq 0x1dc3f(%rip), %rdi     # 0x3d5e0
leaq 0x1d2ec(%rip), %rsi     # 0x3cc94
movl $0x156, %edx            # imm = 0x156
leaq 0x1d4e2(%rip), %rcx     # 0x3ce96
callq 0x2170
movl -0x44(%rbp), %eax
subl -0x48(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movslq -0x4c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
subl (%rcx), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movslq -0x4c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
movq -0x18(%rbp), %rdx
movq 0x8(%rdx), %rdx
movslq -0x4c(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rdx
subl (%rdx), %ecx
cmpl %ecx, %eax
jg 0x1fa0b
jmp 0x1fa2a
leaq 0x1d503(%rip), %rdi     # 0x3cf15
leaq 0x1d27b(%rip), %rsi     # 0x3cc94
movl $0x158, %edx            # imm = 0x158
leaq 0x1d471(%rip), %rcx     # 0x3ce96
callq 0x2170
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x4c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movslq -0x54(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x58(%rbp)
cmpl $0x0, 0x18(%rbp)
jne 0x1fa5d
movl -0x58(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1fa63
movl 0x18(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jle 0x1fa82
movl -0x58(%rbp), %eax
movl -0x5c(%rbp), %ecx
addl $0x2, %ecx
sarl %cl, %eax
andl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x1fa89
xorl %eax, %eax
movl %eax, -0x70(%rbp)
jmp 0x1fa89
movl -0x70(%rbp), %eax
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x5c(%rbp)
jne 0x1fad2
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl $0x8, %edx
movl $0x1, %ecx
callq 0x1e6d0
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x48(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movl -0x4c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1fc37
cmpl $0x1, -0x5c(%rbp)
jne 0x1fb28
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl $0x1, %ecx
movl %ecx, %edx
callq 0x1e6d0
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x1fb07
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x74(%rbp)
jmp 0x1fb18
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
addl 0xc(%rcx), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %ecx
movl -0x4c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1fc35
cmpl $0x3, -0x5c(%rbp)
jne 0x1fb7e
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl $0x1, %ecx
movl %ecx, %edx
callq 0x1e6d0
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x1fb5d
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x78(%rbp)
jmp 0x1fb6e
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x10(%rbp), %rcx
addl 0x14(%rcx), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %ecx
movl -0x4c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1fc33
cmpl $0x2, -0x5c(%rbp)
jne 0x1fbd4
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl $0x2, %edx
movl $0x1, %ecx
callq 0x1e6d0
movl -0x48(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x1fbb6
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x7c(%rbp)
jmp 0x1fbc7
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
addl 0xc(%rcx), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %ecx
movl -0x4c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1fc31
cmpl $0x4, -0x5c(%rbp)
jne 0x1fc2a
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl $0x2, %edx
movl $0x1, %ecx
callq 0x1e6d0
movl -0x48(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x1fc0c
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x80(%rbp)
jmp 0x1fc1d
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x10(%rbp), %rcx
addl 0x14(%rcx), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %ecx
movl -0x4c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1fc2f
callq 0x2050
jmp 0x1fc31
jmp 0x1fc33
jmp 0x1fc35
jmp 0x1fc37
cmpl $0x0, -0x5c(%rbp)
jle 0x1fc4e
cmpl $0x0, -0x60(%rbp)
je 0x1fc4e
movl -0x5c(%rbp), %eax
movl %eax, -0x84(%rbp)
jmp 0x1fc58
xorl %eax, %eax
movl %eax, -0x84(%rbp)
jmp 0x1fc58
movl -0x84(%rbp), %eax
movl %eax, 0x18(%rbp)
jmp 0x1f8d6
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0x1fca3
movq 0x2537b(%rip), %rax     # 0x44ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
subl $0x1, %edx
movl -0x4c(%rbp), %ecx
movl -0x44(%rbp), %r8d
movl -0x48(%rbp), %r9d
leaq 0x1d298(%rip), %rsi     # 0x3cf34
movb $0x0, %al
callq 0x2210
cmpl $0x0, -0x44(%rbp)
jl 0x1fcc3
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
leaq -0x40(%rbp), %rsi
movl $0x1, %edx
callq 0x1e6d0
jmp 0x1fce3
cmpl $0x0, -0x48(%rbp)
jl 0x1fce1
movq -0x8(%rbp), %rdi
movl -0x48(%rbp), %ecx
addl $0x1, %ecx
leaq -0x40(%rbp), %rsi
movl $0x2, %edx
callq 0x1e6d0
jmp 0x1fce3
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl -0x3c(%rbp), %ecx
sarl %ecx
cmpl %ecx, %eax
jge 0x1fd43
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x64(%rbp)
movq -0x38(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x64(%rbp), %edx
movq -0x38(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1fcea
movl -0x3c(%rbp), %ecx
movq 0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)