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

```asm
<wg_split>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %rsi,-0x30(%rbp)
  mov    %rdx,-0x38(%rbp)
  mov    %ecx,-0x3c(%rbp)
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x30(%rbp),%rax
  mov    %rax,-0x8(%rbp)
  movl   $0x0,-0x18(%rbp)
  movl   $0x0,-0x14(%rbp)
  cmpl   $0x0,-0x3c(%rbp)
  jne    L54
  mov    $0x0,%eax
  jmp    L85
L54:
  subl   $0x1,-0x3c(%rbp)
  jmp    L204
L317:
  cmpl   $0x3,-0x14(%rbp)
  je     L205
  cmpl   $0x3,-0x14(%rbp)
  jg     L204
  cmpl   $0x2,-0x14(%rbp)
  je     L226
  cmpl   $0x2,-0x14(%rbp)
  jg     L204
  cmpl   $0x0,-0x14(%rbp)
  je     L109
  cmpl   $0x1,-0x14(%rbp)
  je     L29
  jmp    L204
L251:
  addq   $0x1,-0x10(%rbp)
L109:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <isspace@plt>
  test   %eax,%eax
  jne    L251
  movl   $0x1,-0x14(%rbp)
L29:
  mov    -0x18(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rax,%rdx
  mov    -0x8(%rbp),%rax
  mov    %rax,(%rdx)
  addl   $0x1,-0x18(%rbp)
  movl   $0x2,-0x14(%rbp)
  jmp    L226
L95:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <isspace@plt>
  test   %eax,%eax
  je     L280
  mov    -0x8(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x8(%rbp)
  movb   $0x0,(%rax)
  addq   $0x1,-0x10(%rbp)
  movl   $0x0,-0x14(%rbp)
  jmp    L209
L280:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x27,%al
  jne    L13
  addq   $0x1,-0x10(%rbp)
  movl   $0x3,-0x14(%rbp)
  jmp    L209
L13:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x5c,%al
  jne    L177
  mov    -0x10(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  test   %al,%al
  je     L177
  addq   $0x1,-0x10(%rbp)
  mov    -0x10(%rbp),%rdx
  lea    0x1(%rdx),%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x8(%rbp),%rax
  lea    0x1(%rax),%rcx
  mov    %rcx,-0x8(%rbp)
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
  jmp    L226
L177:
  mov    -0x10(%rbp),%rdx
  lea    0x1(%rdx),%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x8(%rbp),%rax
  lea    0x1(%rax),%rcx
  mov    %rcx,-0x8(%rbp)
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
L226:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L95
L209:
  jmp    L204
L86:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x27,%al
  jne    L96
  addq   $0x1,-0x10(%rbp)
  jmp    L195
L96:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x5c,%al
  jne    L323
  mov    -0x10(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  test   %al,%al
  je     L323
  addq   $0x1,-0x10(%rbp)
  mov    -0x10(%rbp),%rdx
  lea    0x1(%rdx),%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x8(%rbp),%rax
  lea    0x1(%rax),%rcx
  mov    %rcx,-0x8(%rbp)
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
  jmp    L205
L323:
  mov    -0x10(%rbp),%rdx
  lea    0x1(%rdx),%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x8(%rbp),%rax
  lea    0x1(%rax),%rcx
  mov    %rcx,-0x8(%rbp)
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
L205:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L86
L195:
  movl   $0x2,-0x14(%rbp)
  nop
L204:
  mov    -0x18(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jge    L328
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L317
L328:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L180
  mov    -0x8(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x18(%rbp),%eax
  jmp    L85
L180:
  mov    -0x18(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x18(%rbp)
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rax,%rdx
  mov    -0x8(%rbp),%rax
  mov    %rax,(%rdx)
  jmp    L316
L74:
  mov    -0x10(%rbp),%rdx
  lea    0x1(%rdx),%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x8(%rbp),%rax
  lea    0x1(%rax),%rcx
  mov    %rcx,-0x8(%rbp)
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
L316:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L74
  mov    -0x8(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x18(%rbp),%eax
L85:
  leave
  ret
```

assistant: ```c
unsigned int wg_split(char **result, char *dest, char *src, int maxsegments) {
  char *p = src;
  char *w = dest;
  int cnt = 0;
  int state = 0;
  if (maxsegments == 0) {
    return 0;
  }
  maxsegments--;
  while (cnt < maxsegments && *p) {
    switch (state) {
    case 0:
      while (isspace((int)*p)) {
        p++;
      }
      state = 1;
    case 1:
      result[cnt] = w;
      cnt++;
      state = 2;
    case 2:
      while (*p) {
        if (isspace((int)*p)) {
          *w++ = '\0';
          p++;
          state = 0;
          break;
        } else if (*p == '\'') {
          p++;
          state = 3;
          break;
        } else if (*p == '\\' && p[1]) {
          p++;
          *w++ = *p++;
        } else {
          *w++ = *p++;
        }
      }
      break;
    case 3:
      while (*p) {
        if (*p == '\'') {
          p++;
          break;
        } else if (*p == '\\' && p[1]) {
          p++;
          *w++ = *p++;
        } else {
          *w++ = *p++;
        }
      }
      state = 2;
      break;
    }
  }
  if (!*p) {
    *w = '\0';
    return cnt;
  }
  result[cnt++] = w;
  while (*p) {
    *w++ = *p++;
  }
  *w = '\0';
  return cnt;
}
```