user: Please show me the C implementation that matches the assembly code listed below:

```asm
<levenshtein>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rdi,%r14
  mov    %rsi,%r15
  call   <strlen@plt>
  mov    %eax,%ebx
  mov    %r15,%rdi
  call   <strlen@plt>
  mov    %eax,%ebp
  mov    %eax,0x1c(%rsp)
  lea    0x8(,%rax,8),%edi
  call   <malloc@plt>
  mov    %rax,%r12
  test   %ebx,%ebx
  je     L21
  mov    0x1c(%rsp),%r13d
  test   %ebp,%ebp
  je     L21
L9:
  movsbl (%r14),%edi
  call   <tolower@plt>
  mov    %rax,%rbp
  movsbl (%r15),%edi
  call   <tolower@plt>
  cmp    %rax,%rbp
  jne    L27
  add    $0x1,%r14
  add    $0x1,%r15
  sub    $0x1,%r13d
  sub    $0x1,%ebx
  je     L118
  test   %r13d,%r13d
  jne    L9
  mov    %r13d,0x1c(%rsp)
  jmp    L21
L27:
  mov    %r13d,0x1c(%rsp)
L21:
  test   %ebx,%ebx
  je     L195
  mov    0x1c(%rsp),%eax
  test   %eax,%eax
  je     L0
  cmp    $0xffffffff,%eax
  je     L71
  mov    %eax,%ecx
  mov    $0x0,%eax
L54:
  mov    %eax,(%r12,%rax,4)
  mov    %rax,%rdx
  add    $0x1,%rax
  cmp    %rdx,%rcx
  jne    L54
L71:
  mov    0x1c(%rsp),%eax
  lea    (%r12,%rax,4),%rax
  mov    %rax,0x20(%rsp)
  mov    %ebx,%eax
  mov    %rax,0x28(%rsp)
  mov    $0x0,%eax
  mov    %r14,%rbx
  mov    %rax,%r14
  jmp    L101
L118:
  mov    %r13d,0x1c(%rsp)
  jmp    L21
L13:
  mov    $0x1,%edx
L62:
  mov    0x4(%r12,%rbp,4),%eax
  add    $0x1,%eax
  lea    0x1(%r13),%ecx
  cmp    %ecx,%eax
  cmova  %ecx,%eax
  add    (%r12,%rbp,4),%edx
  cmp    %edx,%eax
  cmova  %edx,%eax
  mov    %r13d,(%r12,%rbp,4)
  add    $0x1,%rbp
  cmp    %rbp,0x8(%rsp)
  je     L156
  mov    %eax,%r13d
L4:
  movsbl (%rbx,%r14,1),%edi
  call   <tolower@plt>
  mov    %rax,(%rsp)
  movsbl (%r15,%rbp,1),%edi
  call   <tolower@plt>
  mov    $0x0,%edx
  cmp    %rax,(%rsp)
  je     L62
  mov    %ebp,(%rsp)
  mov    0x18(%rsp),%eax
  test   %eax,%eax
  je     L13
  test   %ebp,%ebp
  je     L13
  lea    -0x1(%rax),%eax
  movsbl (%rbx,%rax,1),%edi
  call   <tolower@plt>
  mov    %rax,0x10(%rsp)
  movsbl (%r15,%rbp,1),%edi
  call   <tolower@plt>
  mov    $0x1,%edx
  cmp    %rax,0x10(%rsp)
  jne    L62
  movsbl (%rbx,%r14,1),%edi
  call   <tolower@plt>
  mov    %rax,0x10(%rsp)
  mov    (%rsp),%ecx
  lea    -0x1(%rcx),%eax
  movsbl (%r15,%rax,1),%edi
  call   <tolower@plt>
  cmp    %rax,0x10(%rsp)
  setne  %dl
  movzbl %dl,%edx
  jmp    L62
L156:
  mov    0x20(%rsp),%rcx
  mov    %eax,(%rcx)
  add    $0x1,%r14
  cmp    %r14,0x28(%rsp)
  je     L187
L101:
  mov    %r14d,0x18(%rsp)
  lea    0x1(%r14),%r13d
  mov    0x1c(%rsp),%eax
  mov    %rax,0x8(%rsp)
  mov    $0x0,%ebp
  jmp    L4
L187:
  mov    %eax,%ebx
  mov    %r12,%rdi
  call   <free@plt>
  mov    %ebx,0x1c(%rsp)
L195:
  mov    0x1c(%rsp),%eax
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L0:
  mov    %ebx,0x1c(%rsp)
  jmp    L195
```

assistant: ```c
unsigned int levenshtein(char *word1, char *word2) {
  unsigned int len1 = strlen(word1), len2 = strlen(word2);
  unsigned int *v = malloc((len2 + 1) * sizeof(unsigned int *));
  unsigned int i, j, current, next, cost;
  while (len1 > 0 && len2 > 0 && (tolower(word1[0]) == tolower(word2[0])))
    word1++, word2++, len1--, len2--;
  if (!len1)
    return len2;
  if (!len2)
    return len1;
  for (j = 0; j < len2 + 1; j++)
    v[j] = j;
  for (i = 0; i < len1; i++) {
    current = i + 1;
    for (j = 0; j < len2; j++) {
      cost = !((tolower(word1[i]) == tolower(word2[j])) || (i && j && (tolower(word1[i - 1]) == tolower(word2[j])) && (tolower(word1[i]) == tolower(word2[j - 1]))));
      next = ((((v[j + 1] + 1) < (current + 1) ? (v[j + 1] + 1) : (current + 1))) < (v[j] + cost) ? (((v[j + 1] + 1) < (current + 1) ? (v[j + 1] + 1) : (current + 1))) : (v[j] + cost));
      v[j] = current;
      current = next;
    }
    v[len2] = next;
  }
  free(v);
  return next;
}
```