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

```asm
<refined_soundex>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  mov    %rdi,%r15
  xor    %edi,%edi
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  test   %r15,%r15
  setne  %dil
  call   <assert@plt>
  mov    %r15,%rdi
  call   <strlen@plt>
  mov    %rsp,%rcx
  mov    %rax,%r12
  lea    0x10(%rax),%rax
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L55
L34:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L34
L55:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L33
L18:
  lea    0xf(%r12),%rax
  mov    %rsp,%rcx
  mov    %rsp,-0x48(%rbp)
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L107
L58:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L58
L107:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L148
L140:
  movsbl (%r15),%edi
  mov    %rsp,%r13
  call   <toupper@plt>
  mov    %eax,%ebx
  mov    -0x48(%rbp),%rax
  mov    %bl,(%rax)
  test   %r12,%r12
  je     L129
  xor    %r14d,%r14d
  xor    %eax,%eax
  xor    %ebx,%ebx
  nop
L49:
  movsbl (%r15,%rax,1),%edi
  call   <encode_char@plt>
  mov    %al,0x0(%r13,%rbx,1)
  lea    0x1(%r14),%ebx
  mov    %rbx,%r14
  mov    %rbx,%rax
  cmp    %r12,%rbx
  jb     L49
  xor    %ecx,%ecx
  xor    %eax,%eax
  mov    $0x1,%ebx
  xor    %edx,%edx
  nopl   0x0(%rax)
L136:
  mov    %eax,%esi
  movzbl 0x0(%r13,%rdx,1),%eax
  cmp    %sil,%al
  je     L24
  mov    -0x48(%rbp),%rsi
  mov    %ebx,%edx
  add    $0x1,%ebx
  mov    %al,(%rsi,%rdx,1)
L24:
  lea    0x1(%rcx),%edx
  mov    %rdx,%rcx
  cmp    %r12,%rdx
  jb     L136
  mov    %ebx,%edi
  mov    %ebx,%r12d
  call   <malloc@plt>
  mov    %rax,%r8
  test   %ebx,%ebx
  je     L147
  mov    -0x48(%rbp),%rsi
  mov    %r12,%rdx
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    %rax,%r8
L50:
  movb   $0x0,(%r8,%r12,1)
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L19
  lea    -0x28(%rbp),%rsp
  mov    %r8,%rax
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
  nopl   (%rax)
L33:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L18
  nopl   0x0(%rax,%rax,1)
L147:
  xor    %r12d,%r12d
  jmp    L50
L129:
  mov    $0x1,%edi
  mov    $0x1,%r12d
  call   <malloc@plt>
  mov    %bl,(%rax)
  mov    %rax,%r8
  jmp    L50
L148:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L140
L19:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
char *refined_soundex(const char *str) {
  assert(str != NULL);
  size_t str_len = strlen(str);
  char code[str_len + 1];
  char buf[str_len];
  code[0] = toupper(str[0]);
  unsigned d = 1;
  for (unsigned i = 0; i < str_len; i++)
    buf[i] = encode_char(str[i]);
  char prev = '\0';
  for (unsigned i = 0; i < str_len; i++) {
    if (!((buf[i]) == (prev))) {
      code[d] = buf[i];
      d++;
      prev = buf[i];
    }
  }
  char *result = malloc(d * sizeof(char));
  for (unsigned i = 0; i < d; i++) {
    result[i] = code[i];
  }
  result[d] = '\0';
  return result;
}
```