// File: /workspace/github_c_makefile_star2_O2/lh3[P]fermi2/correct.c
// Function: path_backtrack
static void path_backtrack(const ecstack_t *a, int start, const ecseq_t *o, ecseq_t *s)
{
	int i = start, last = -1;
	s->n = 0;
	while (i >= 0) {
		ecbase_t *c;
		ecstack1_t *p = &a->a[i];
		int is_match = (p->state == STATE_M || p->state == STATE_N);
		kv_pushp(ecbase_t, *s, &c);
		c->state = p->state;
		c->i = o->a[p->i].i;
		c->b = p->state == STATE_D? 4 : p->base;
		c->q = is_match && o->a[p->i].b == p->base? o->a[p->i].q : 0; // if we make a correction, reduce the base quality to 0.
		c->ob = p->state == STATE_I? 4 : o->a[p->i].ob; // no ob/oq for inserted bases
		c->oq = p->state == STATE_I? 0 : o->a[p->i].oq;
		c->f = (p->state != STATE_N);
		c->min_diff = is_match? o->a[p->i].min_diff : 0xff;
		last = p->i;
		i = p->parent;
	}
	assert(last > 0);
	for (i = last - 1; i >= 0; --i)
		kv_push(ecbase_t, *s, o->a[i]);
	for (i = 0; i < s->n>>1; ++i) { // reverse
		ecbase_t tmp = s->a[i];
		s->a[i] = s->a[s->n - 1 - i];
		s->a[s->n - 1 - i] = tmp;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdx, %r14
andq $0x0, (%rcx)
movq %rdi, %r15
pushq $-0x1
popq %rcx
movl $0xffffff0f, %ebp       # imm = 0xFFFFFF0F
testl %esi, %esi
js 0x9e0f
movq 0x10(%r15), %rax
movl %esi, %ecx
shlq $0x4, %rcx
leaq (%rax,%rcx), %r13
movb 0xc(%rax,%rcx), %r12b
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x9cfc
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rbx)
imulq $0xc, %rdx, %rsi
movq %rax, %rdi
callq 0x2260
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
movb 0xc(%r13), %dl
jmp 0x9cff
movl %r12d, %edx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
imulq $0xc, %rcx, %rcx
shlb $0x4, %dl
movzbl %dl, %esi
movl (%rax,%rcx), %edx
andl %ebp, %edx
orl %esi, %edx
movw %dx, (%rax,%rcx)
movq 0x10(%r14), %rsi
movslq 0x4(%r13), %rdi
imulq $0xc, %rdi, %rdi
movl 0x8(%rsi,%rdi), %esi
movl %esi, 0x8(%rax,%rcx)
movw $0x4, %si
cmpb $0x3, 0xc(%r13)
je 0x9d42
movzbl 0xd(%r13), %esi
andl $0xf, %esi
addq %rcx, %rax
andl $-0x10, %edx
movzwl %si, %ecx
orl %edx, %ecx
movw %cx, (%rax)
cmpb $0x1, %r12b
ja 0x9d7c
movq 0x10(%r14), %rdx
movslq 0x4(%r13), %rsi
imulq $0xc, %rsi, %rsi
movzwl (%rdx,%rsi), %edi
andl $0xf, %edi
movzbl 0xd(%r13), %r8d
cmpw %r8w, %di
jne 0x9d7c
addq %rsi, %rdx
movb 0x2(%rdx), %dl
jmp 0x9d7e
xorl %edx, %edx
movb %dl, 0x2(%rax)
movw $0x400, %dx             # imm = 0x400
cmpb $0x2, 0xc(%r13)
je 0x9da2
movq 0x10(%r14), %rdx
movslq 0x4(%r13), %rsi
imulq $0xc, %rsi, %rsi
movzwl (%rdx,%rsi), %edx
andl $0xf00, %edx            # imm = 0xF00
andl $0xfffff0ff, %ecx       # imm = 0xFFFFF0FF
movzwl %dx, %edx
orl %ecx, %edx
movw %dx, (%rax)
movb 0xc(%r13), %sil
cmpb $0x2, %sil
jne 0x9dbe
xorl %ecx, %ecx
jmp 0x9dce
movq 0x10(%r14), %rcx
movslq 0x4(%r13), %rdi
imulq $0xc, %rdi, %rdi
movb 0x3(%rcx,%rdi), %cl
xorl %edi, %edi
testb %sil, %sil
setne %dil
shll $0xc, %edi
andl $0xfff, %edx            # imm = 0xFFF
orl %edi, %edx
movb %cl, 0x3(%rax)
movw %dx, (%rax)
movl 0x4(%r13), %ecx
movb $-0x1, %dl
cmpb $0x1, %r12b
ja 0x9e03
movslq %ecx, %rdx
movq 0x10(%r14), %rsi
imulq $0xc, %rdx, %rdx
movb 0x4(%rsi,%rdx), %dl
movb %dl, 0x4(%rax)
movl (%r13), %esi
jmp 0x9ca9
testl %ecx, %ecx
jle 0x9efa
movl %ecx, %r15d
imulq $0xc, %r15, %r12
addq $-0xc, %r12
testq %r15, %r15
jle 0x9e82
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x9e59
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rbx)
imulq $0xc, %rdx, %rsi
movq %rax, %rdi
callq 0x2260
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
imulq $0xc, %rcx, %rcx
movq 0x10(%r14), %rdx
movl 0x8(%rdx,%r12), %esi
movl %esi, 0x8(%rax,%rcx)
movq (%rdx,%r12), %rdx
movq %rdx, (%rax,%rcx)
addq $-0xc, %r12
decq %r15
jmp 0x9e22
pushq $-0xc
popq %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq (%rbx), %rsi
movq %rsi, %rdi
shrq %rdi
cmpq %rdx, %rdi
jbe 0x9eeb
movq 0x10(%rbx), %rdi
movl 0x8(%rdi,%rcx), %r8d
movl %r8d, 0x10(%rsp)
movq (%rdi,%rcx), %r8
movq %r8, 0x8(%rsp)
imulq $0xc, %rsi, %rsi
addq %rdi, %rsi
movq (%rax,%rsi), %r8
movq %r8, (%rdi,%rcx)
movl 0x8(%rax,%rsi), %esi
movl %esi, 0x8(%rdi,%rcx)
imulq $0xc, (%rbx), %rsi
addq 0x10(%rbx), %rsi
movl 0x10(%rsp), %edi
movl %edi, 0x8(%rax,%rsi)
movq 0x8(%rsp), %rdi
movq %rdi, (%rax,%rsi)
incq %rdx
addq $0xc, %rcx
addq $-0xc, %rax
jmp 0x9e89
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xfd98(%rip), %rdi      # 0x19c99
leaq 0xf713(%rip), %rsi      # 0x1961b
leaq 0xfd93(%rip), %rcx      # 0x19ca2
movl $0x284, %edx            # imm = 0x284
callq 0x2120