user: 请从给定的汇编指令推导出C源代码:

```asm
<wg_split>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,0x8(%rsp)
  mov    $0x0,%eax
  test   %ecx,%ecx
  je     L225
  mov    %rsi,%r13
  mov    %rdx,%rbp
  lea    -0x1(%rcx),%eax
  mov    %eax,0x4(%rsp)
  mov    $0x0,%ecx
  mov    $0x0,%r15d
  jmp    L85
L131:
  lea    0x1(%r13),%rdx
  cmp    $0x3,%ecx
  je     L189
L85:
  cmp    0x4(%rsp),%r15d
  jge    L345
  movzbl 0x0(%rbp),%eax
  test   %al,%al
  je     L285
  cmp    $0x2,%ecx
  je     L302
  jg     L131
  test   %ecx,%ecx
  je     L293
  cmp    $0x1,%ecx
  jne    L85
L342:
  movslq %r15d,%rax
  mov    0x8(%rsp),%rsi
  mov    %r13,(%rsi,%rax,8)
  add    $0x1,%r15d
  movzbl 0x0(%rbp),%ebx
  test   %bl,%bl
  je     L219
L20:
  lea    0x1(%r13),%r12
  jmp    L343
L115:
  add    $0x1,%rbp
L293:
  movsbl 0x0(%rbp),%edi
  call   <isspace@plt>
  test   %eax,%eax
  jne    L115
  jmp    L342
L49:
  lea    0x1(%r14),%r13
  movb   $0x0,(%r14)
  add    $0x1,%rbp
  mov    $0x0,%ecx
  jmp    L85
L305:
  add    $0x1,%rbp
  mov    %r14,%r13
  mov    $0x3,%ecx
  jmp    L85
L320:
  add    $0x1,%rbp
  mov    %r12,%r13
L113:
  mov    %bl,-0x1(%r12)
  movzbl 0x0(%rbp),%ebx
  add    $0x1,%r12
  test   %bl,%bl
  je     L317
L343:
  lea    -0x1(%r12),%r14
  movsbl %bl,%edi
  call   <isspace@plt>
  test   %eax,%eax
  jne    L49
  cmp    $0x27,%bl
  je     L305
  cmp    $0x5c,%bl
  jne    L320
  movzbl 0x1(%rbp),%eax
  test   %al,%al
  je     L320
  add    $0x2,%rbp
  mov    %r12,%r13
  mov    %eax,%ebx
  jmp    L113
L317:
  mov    $0x2,%ecx
  jmp    L85
L296:
  add    $0x1,%rbp
  mov    $0x2,%ecx
  jmp    L85
L35:
  add    $0x1,%rbp
  mov    %rdx,%r13
L286:
  mov    %al,-0x1(%rdx)
  movzbl 0x0(%rbp),%eax
  add    $0x1,%rdx
  test   %al,%al
  je     L21
L189:
  lea    -0x1(%rdx),%r13
  cmp    $0x27,%al
  je     L296
  cmp    $0x5c,%al
  jne    L35
  movzbl 0x1(%rbp),%ecx
  test   %cl,%cl
  je     L35
  add    $0x2,%rbp
  mov    %rdx,%r13
  mov    %ecx,%eax
  jmp    L286
L21:
  mov    $0x2,%ecx
  jmp    L85
L219:
  mov    $0x2,%ecx
  jmp    L85
L345:
  cmpb   $0x0,0x0(%rbp)
  je     L285
  lea    0x1(%r15),%eax
  movslq %r15d,%r15
  mov    0x8(%rsp),%rsi
  mov    %r13,(%rsi,%r15,8)
  movzbl 0x0(%rbp),%edx
  test   %dl,%dl
  je     L312
L184:
  add    $0x1,%rbp
  add    $0x1,%r13
  mov    %dl,-0x1(%r13)
  movzbl 0x0(%rbp),%edx
  test   %dl,%dl
  jne    L184
L312:
  movb   $0x0,0x0(%r13)
L225:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L285:
  movb   $0x0,0x0(%r13)
  mov    %r15d,%eax
  jmp    L225
L302:
  movzbl 0x0(%rbp),%ebx
  jmp    L20
```

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;
}
```