// File: chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: pop_trace_bp_rev_f(asg16_v*, long, unsigned short*, unsigned short*, unsigned short*, unsigned int*)
inline int64_t pop_trace_bp_rev_f(asg16_v *res, int64_t i, uint16_t *c, uint16_t *bq, uint16_t *bt, uint32_t *len)
{
	(*c) = (res->a[i]>>14); (*bq) = (*bt) = (uint16_t)-1;
	if((*c) == 2 || (*c) == 3) {
		(*bt) = ((res->a[i]>>12)&3); 
		(*len) = (res->a[i]&(0xfff));
	} else if((*c) == 1) {
		(*bt) = ((res->a[i]>>12)&3);
		(*bq) = ((res->a[i]>>10)&3);
		(*len) = (res->a[i]&(0x3ff));
	} else {
		(*len) = (res->a[i]&(0x3fff));
	}

	uint32_t sl; uint16_t sbq, sbt;
	for (i--; (i >= 0) && ((*c) == (res->a[i]>>14)); i--) {
		sbq = sbt = (uint16_t)-1;
		if((*c) == 2 || (*c) == 3) {
			sbt = ((res->a[i]>>12)&3); 
			sl = (res->a[i]&(0xfff));
		} else if((*c) == 1) {
			sbt = ((res->a[i]>>12)&3);
			sbq = ((res->a[i]>>10)&3);
			sl = (res->a[i]&(0x3ff));
		} else {
			sl = (res->a[i]&(0x3fff));
		}
		if((*bq) != sbq || (*bt) != sbt) break;
		(*len) += sl;
	}
	if((*c) == 3) {
		(*bq) = (*bt); (*bt) = (uint16_t)-1;
	}
	return i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0xe, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movq -0x28(%rbp), %rax
movw $0xffff, (%rax)         # imm = 0xFFFF
movq -0x20(%rbp), %rax
movw $0xffff, (%rax)         # imm = 0xFFFF
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x2, %eax
je 0x26ddb3
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0x26ddf4
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0xc, %eax
andl $0x3, %eax
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, (%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
jmp 0x26de7c
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0x26de5e
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0xc, %eax
andl $0x3, %eax
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, (%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0xa, %eax
andl $0x3, %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, (%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x3ff, %ecx            # imm = 0x3FF
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
jmp 0x26de7a
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
jmp 0x26de7c
movq -0x10(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x10(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x10(%rbp)
movb %al, -0x39(%rbp)
jl 0x26deb6
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x10(%rbp), %rdx
movzwl (%rcx,%rdx,2), %ecx
sarl $0xe, %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x26dec2
jmp 0x26dfca
movw $0xffff, -0x38(%rbp)    # imm = 0xFFFF
movw $0xffff, -0x36(%rbp)    # imm = 0xFFFF
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x2, %eax
je 0x26dee6
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0x26df1a
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0xc, %eax
andl $0x3, %eax
movw %ax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, -0x34(%rbp)
jmp 0x26df8e
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0x26df74
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0xc, %eax
andl $0x3, %eax
movw %ax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0xa, %eax
andl $0x3, %eax
movw %ax, -0x36(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, -0x34(%rbp)
jmp 0x26df8c
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
movl %eax, -0x34(%rbp)
jmp 0x26df8e
movq -0x20(%rbp), %rax
movzwl (%rax), %eax
movzwl -0x36(%rbp), %ecx
cmpl %ecx, %eax
jne 0x26dfac
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
movzwl -0x38(%rbp), %ecx
cmpl %ecx, %eax
je 0x26dfae
jmp 0x26dfca
movl -0x34(%rbp), %ecx
movq -0x30(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x26de88
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0x26dfed
movq -0x28(%rbp), %rax
movw (%rax), %cx
movq -0x20(%rbp), %rax
movw %cx, (%rax)
movq -0x28(%rbp), %rax
movw $0xffff, (%rax)         # imm = 0xFFFF
movq -0x10(%rbp), %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)