// File: chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: pop_trace_bp_f(asg16_v*, unsigned int, unsigned short*, unsigned short*, unsigned short*, unsigned int*)
inline uint32_t pop_trace_bp_f(asg16_v *res, uint32_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 < res->n) && ((*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)
movl %esi, -0xc(%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
movl -0xc(%rbp), %ecx
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 0x1b5451
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0x1b5490
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xc(%rbp), %ecx
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
movl -0xc(%rbp), %ecx
movzwl (%rax,%rcx,2), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
jmp 0x1b5514
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0x1b54f7
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xc(%rbp), %ecx
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
movl -0xc(%rbp), %ecx
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
movl -0xc(%rbp), %ecx
movzwl (%rax,%rcx,2), %ecx
andl $0x3ff, %ecx            # imm = 0x3FF
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
jmp 0x1b5512
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xc(%rbp), %ecx
movzwl (%rax,%rcx,2), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
jmp 0x1b5514
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %ecx
movq -0x8(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0x39(%rbp)
jae 0x1b5551
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0xc(%rbp), %edx
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 0x1b555d
jmp 0x1b565c
movw $0xffff, -0x38(%rbp)    # imm = 0xFFFF
movw $0xffff, -0x36(%rbp)    # imm = 0xFFFF
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x2, %eax
je 0x1b5581
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0x1b55b3
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xc(%rbp), %ecx
movzwl (%rax,%rcx,2), %eax
sarl $0xc, %eax
andl $0x3, %eax
movw %ax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xc(%rbp), %ecx
movzwl (%rax,%rcx,2), %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, -0x34(%rbp)
jmp 0x1b5623
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0x1b560a
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xc(%rbp), %ecx
movzwl (%rax,%rcx,2), %eax
sarl $0xc, %eax
andl $0x3, %eax
movw %ax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xc(%rbp), %ecx
movzwl (%rax,%rcx,2), %eax
sarl $0xa, %eax
andl $0x3, %eax
movw %ax, -0x36(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xc(%rbp), %ecx
movzwl (%rax,%rcx,2), %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, -0x34(%rbp)
jmp 0x1b5621
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xc(%rbp), %ecx
movzwl (%rax,%rcx,2), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
movl %eax, -0x34(%rbp)
jmp 0x1b5623
movq -0x20(%rbp), %rax
movzwl (%rax), %eax
movzwl -0x36(%rbp), %ecx
cmpl %ecx, %eax
jne 0x1b5641
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
movzwl -0x38(%rbp), %ecx
cmpl %ecx, %eax
je 0x1b5643
jmp 0x1b565c
movl -0x34(%rbp), %ecx
movq -0x30(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1b551d
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0x1b567f
movq -0x28(%rbp), %rax
movw (%rax), %cx
movq -0x20(%rbp), %rax
movw %cx, (%rax)
movq -0x28(%rbp), %rax
movw $0xffff, (%rax)         # imm = 0xFFFF
movl -0xc(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop