// File: VanAndelInstitute[P]intent/src/seq_tools.cpp
// Function: levenshteinDistance(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned long)
int levenshteinDistance(const std::string &s1, const std::string &s2, size_t max)
{
  const size_t m(s1.size());
  const size_t n(s2.size());
 
  if( m==0 ) return n;
  if( n==0 ) return m;
 
  size_t *costs = new size_t[n + 1];
 
  for( size_t k=0; k<=n; k++ ) costs[k] = k;
 
  size_t i = 0;
  for ( std::string::const_iterator it1 = s1.begin(); it1 != s1.end(); ++it1, ++i )
  {
    costs[0] = i+1;
    size_t corner = i;
 
    size_t j = 0;
    size_t min = 999;
    for ( std::string::const_iterator it2 = s2.begin(); it2 != s2.end(); ++it2, ++j )
    {
      size_t upper = costs[j+1];
      if( *it1 == *it2 )
      {
		  costs[j+1] = corner;
	  }
      else
	  {
		size_t t(upper<corner?upper:corner);
        costs[j+1] = (costs[j]<t?costs[j]:t)+1;
	  }
      min = std::min(min, costs[j+1]); 
      corner = upper;
    }
    if(min > max) {
        delete [] costs;
        return(static_cast<int>(max));
    }

  }
  size_t result = costs[n];
  delete [] costs;
 
  return(static_cast<int>(result));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8410
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x8410
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6b534
movq -0x30(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x6b7dc
cmpq $0x0, -0x30(%rbp)
jne 0x6b547
movq -0x28(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x6b7dc
movq -0x30(%rbp), %rax
addq $0x1, %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x8040
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x30(%rbp), %rax
ja 0x6b5a4
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x6b57c
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8510
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x89e0
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x5c8f0
testb $0x1, %al
jne 0x6b5dc
jmp 0x6b7a2
movq -0x48(%rbp), %rcx
addq $0x1, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x3e7, -0x70(%rbp)     # imm = 0x3E7
movq -0x18(%rbp), %rdi
callq 0x8510
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
callq 0x89e0
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x5c8f0
testb $0x1, %al
jne 0x6b633
jmp 0x6b756
movq -0x38(%rbp), %rax
movq -0x68(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movq %rax, -0x88(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x60bb0
movsbl (%rax), %eax
movl %eax, -0x9c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x60bb0
movq %rax, %rcx
movl -0x9c(%rbp), %eax
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x6b688
movq -0x60(%rbp), %rdx
movq -0x38(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rdx, 0x8(%rax,%rcx,8)
jmp 0x6b70e
movq -0x88(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x6b6a5
movq -0x88(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x6b6b0
movq -0x60(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x38(%rbp), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x90(%rbp), %rax
jae 0x6b6e8
movq -0x38(%rbp), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xb0(%rbp)
jmp 0x6b6f6
movq -0x90(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdx
addq $0x1, %rdx
movq -0x38(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rdx, 0x8(%rax,%rcx,8)
movq -0x38(%rbp), %rsi
movq -0x68(%rbp), %rax
addq $0x1, %rax
shlq $0x3, %rax
addq %rax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x3ab40
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5e660
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x6b610
movq -0x70(%rbp), %rax
cmpq -0x20(%rbp), %rax
jbe 0x6b786
movq -0x38(%rbp), %rax
movq %rax, -0xb8(%rbp)
cmpq $0x0, %rax
je 0x6b77d
movq -0xb8(%rbp), %rdi
callq 0x8710
movq -0x20(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x6b7dc
jmp 0x6b788
leaq -0x50(%rbp), %rdi
callq 0x5e660
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x6b5b9
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x6b7d2
movq -0xc0(%rbp), %rdi
callq 0x8710
movq -0x98(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)