user: Converte this assembly snippet into its equivalent C code:

```asm
<wg_split>:
  endbr64
  xor    %eax,%eax
  test   %ecx,%ecx
  je     L89
  push   %r15
  mov    %rsi,%r15
  push   %r14
  mov    %rdi,%r14
  push   %r13
  lea    -0x1(%rcx),%r13d
  push   %r12
  xor    %r12d,%r12d
  push   %rbp
  mov    %rdx,%rbp
  push   %rbx
  sub    $0x8,%rsp
  movzbl (%rdx),%ebx
  nop
L278:
  cmp    %r13d,%r12d
  jge    L169
L112:
  test   %bl,%bl
  je     L263
  cmp    $0x2,%eax
  je     L99
  cmp    $0x3,%eax
  je     L48
  test   %eax,%eax
  je     L206
  cmp    %r13d,%r12d
  jl     L112
L169:
  test   %bl,%bl
  je     L263
  lea    0x1(%r12),%eax
  movslq %r12d,%r12
  mov    %r15,(%r14,%r12,8)
  movzbl 0x0(%rbp),%edx
  test   %dl,%dl
  je     L138
  nopl   0x0(%rax)
L23:
  add    $0x1,%rbp
  mov    %dl,(%r15)
  add    $0x1,%r15
  movzbl 0x0(%rbp),%edx
  test   %dl,%dl
  jne    L23
L138:
  movb   $0x0,(%r15)
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  xchg   %ax,%ax
L107:
  add    $0x1,%rbp
  mov    %bl,-0x1(%r15)
  movzbl 0x0(%rbp),%ebx
  test   %bl,%bl
  je     L83
L99:
  movsbl %bl,%edi
  call   <isspace@plt>
  test   %eax,%eax
  jne    L218
L165:
  cmp    $0x27,%bl
  je     L7
  add    $0x1,%r15
  cmp    $0x5c,%bl
  jne    L107
  movzbl 0x1(%rbp),%eax
  test   %al,%al
  je     L107
  mov    %eax,%ebx
  add    $0x2,%rbp
  mov    %bl,-0x1(%r15)
  movzbl 0x0(%rbp),%ebx
  test   %bl,%bl
  jne    L99
  nopl   0x0(%rax,%rax,1)
L83:
  mov    $0x2,%eax
  jmp    L278
  nopw   0x0(%rax,%rax,1)
L44:
  movzbl 0x1(%rbp),%ebx
  add    $0x1,%rbp
L206:
  movsbl %bl,%edi
  call   <isspace@plt>
  test   %eax,%eax
  jne    L44
  movslq %r12d,%rax
  add    $0x1,%r12d
  mov    %r15,(%r14,%rax,8)
  movzbl 0x0(%rbp),%ebx
  test   %bl,%bl
  je     L83
  movsbl %bl,%edi
  call   <isspace@plt>
  test   %eax,%eax
  je     L165
  nopl   0x0(%rax,%rax,1)
L218:
  movb   $0x0,(%r15)
  add    $0x1,%rbp
  movzbl 0x0(%rbp),%ebx
  add    $0x1,%r15
  xor    %eax,%eax
  jmp    L278
  nop
L17:
  add    $0x1,%rbp
L74:
  mov    %bl,-0x1(%r15)
  movzbl 0x0(%rbp),%ebx
  test   %bl,%bl
  je     L83
L48:
  cmp    $0x27,%bl
  je     L77
  add    $0x1,%r15
  cmp    $0x5c,%bl
  jne    L17
  movzbl 0x1(%rbp),%eax
  test   %al,%al
  je     L17
  add    $0x2,%rbp
  mov    %eax,%ebx
  jmp    L74
  xchg   %ax,%ax
L7:
  movzbl 0x1(%rbp),%ebx
  mov    $0x3,%eax
  add    $0x1,%rbp
  jmp    L278
  nopw   0x0(%rax,%rax,1)
L77:
  movzbl 0x1(%rbp),%ebx
  mov    $0x2,%eax
  add    $0x1,%rbp
  jmp    L278
L89:
  ret
L263:
  movb   $0x0,(%r15)
  add    $0x8,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  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;
}
```