// File: chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: alignment_extension(char*, int, char*, int, unsigned short, int, unsigned int*, int*, int*, int*)
inline int alignment_extension(char *pattern, int p_length, char *text, int t_length, 
unsigned short errthold, int direction, unsigned int* return_err, int* return_p_end, 
int* return_t_end, int* return_aligned_t_len)
{
	(*return_aligned_t_len) = 0;
	
	if(direction == 0)
	{
		Reserve_Banded_BPM_Extension(pattern, p_length, text, t_length, errthold, return_err, 
		return_p_end, return_t_end);
		if((*return_p_end) != -1 && (*return_t_end) != -1)
		{
			(*return_aligned_t_len) = (*return_t_end) + 1;
			return 1;
		}
		else
		{
			return -1;
		}
		
	}
	else
	{
		reverse_string(pattern, p_length);
		reverse_string(text, t_length);

		Reserve_Banded_BPM_Extension(pattern, p_length, text, t_length, errthold, return_err, 
		return_p_end, return_t_end);

		reverse_string(pattern, p_length);
		reverse_string(text, t_length);

		if((*return_p_end) != -1 && (*return_t_end) != -1)
		{
			(*return_aligned_t_len) = (*return_t_end) + 1;
			(*return_p_end) = p_length - (*return_p_end);
			(*return_t_end) = t_length - (*return_t_end);
			return 1;
		}
		else
		{
			return -1;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movw %r8w, %ax
movq 0x28(%rbp), %r8
movq 0x20(%rbp), %r8
movq 0x18(%rbp), %r8
movq 0x10(%rbp), %r8
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movw %ax, -0x26(%rbp)
movl %r9d, -0x2c(%rbp)
movq 0x28(%rbp), %rax
movl $0x0, (%rax)
cmpl $0x0, -0x2c(%rbp)
jne 0xc53fc
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
movw -0x26(%rbp), %r8w
movq 0x10(%rbp), %r9
movq 0x18(%rbp), %r10
movq 0x20(%rbp), %rax
movzwl %r8w, %r8d
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xc54c0
movq 0x18(%rbp), %rax
cmpl $-0x1, (%rax)
je 0xc53f0
movq 0x20(%rbp), %rax
cmpl $-0x1, (%rax)
je 0xc53f0
movq 0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movq 0x28(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0xc54ac
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xc54ac
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xc5ac0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0xc5ac0
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
movw -0x26(%rbp), %r8w
movq 0x10(%rbp), %r9
movq 0x18(%rbp), %r10
movq 0x20(%rbp), %rax
movzwl %r8w, %r8d
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xc54c0
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xc5ac0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0xc5ac0
movq 0x18(%rbp), %rax
cmpl $-0x1, (%rax)
je 0xc54a5
movq 0x20(%rbp), %rax
cmpl $-0x1, (%rax)
je 0xc54a5
movq 0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movq 0x28(%rbp), %rax
movl %ecx, (%rax)
movl -0x14(%rbp), %ecx
movq 0x18(%rbp), %rax
subl (%rax), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x24(%rbp), %ecx
movq 0x20(%rbp), %rax
subl (%rax), %ecx
movq 0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0xc54ac
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop