user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<wcsrtombs>:
  endbr64
  push   %r15
  push   %r14
  mov    %rsi,%r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  test   %rdi,%rdi
  je     L39
  mov    %rdi,%rbx
  mov    %rdx,%r12
  cmp    $0x3,%rdx
  jbe    L27
  mov    (%rsi),%rax
  mov    %rdx,%rbp
  jmp    L47
  cs nopw 0x0(%rax,%rax,1)
L65:
  add    $0x4,%rax
  sub    $0x1,%rbp
  mov    %sil,(%rbx)
  add    $0x1,%rbx
  mov    %rax,(%r14)
  cmp    $0x3,%rbp
  jbe    L23
L47:
  mov    (%rax),%esi
  test   %esi,%esi
  je     L50
  cmp    $0x7f,%esi
  jbe    L65
  xor    %edx,%edx
  mov    %rbx,%rdi
  call   <wcrtomb@plt>
  cmp    $0xffffffffffffffff,%rax
  je     L126
  add    %rax,%rbx
  sub    %rax,%rbp
  mov    (%r14),%rax
  add    $0x4,%rax
  mov    %rax,(%r14)
  cmp    $0x3,%rbp
  ja     L47
L23:
  test   %rbp,%rbp
  je     L136
  mov    (%r14),%rax
  lea    0x4(%rsp),%r13
  jmp    L90
L219:
  add    $0x4,%rax
  sub    $0x1,%rbp
  mov    %sil,(%rbx)
  add    $0x1,%rbx
  mov    %rax,(%r14)
  test   %rbp,%rbp
  je     L136
L90:
  mov    (%rax),%esi
  test   %esi,%esi
  je     L50
  cmp    $0x7f,%esi
  jbe    L219
  xor    %edx,%edx
  mov    %r13,%rdi
  call   <wcrtomb@plt>
  mov    %rax,%r15
  cmp    $0xffffffffffffffff,%rax
  je     L126
  cmp    %rbp,%rax
  ja     L30
  mov    (%r14),%rax
  mov    %rbx,%rdi
  xor    %edx,%edx
  sub    %r15,%rbp
  add    %r15,%rbx
  mov    (%rax),%esi
  call   <wcrtomb@plt>
  mov    (%r14),%rax
  add    $0x4,%rax
  mov    %rax,(%r14)
  test   %rbp,%rbp
  jne    L90
  nopw   0x0(%rax,%rax,1)
L136:
  movq   $0x0,(%r14)
L14:
  mov    0x8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L132
  add    $0x18,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L39:
  mov    (%rsi),%rbx
  xor    %r12d,%r12d
  mov    (%rbx),%esi
  test   %esi,%esi
  je     L14
  lea    0x4(%rsp),%rbp
  jmp    L170
  nopl   0x0(%rax,%rax,1)
L108:
  add    $0x1,%r12
L225:
  mov    0x4(%rbx),%esi
  add    $0x4,%rbx
  test   %esi,%esi
  je     L14
L170:
  cmp    $0x7f,%esi
  jbe    L108
  xor    %edx,%edx
  mov    %rbp,%rdi
  call   <wcrtomb@plt>
  cmp    $0xffffffffffffffff,%rax
  je     L126
  add    %rax,%r12
  jmp    L225
  nopl   0x0(%rax)
L126:
  mov    $0xffffffffffffffff,%r12
  jmp    L14
  nopl   0x0(%rax)
L50:
  movb   $0x0,(%rbx)
  sub    %rbp,%r12
  jmp    L136
L30:
  sub    %rbp,%r12
  jmp    L14
L27:
  mov    %rdx,%rbp
  jmp    L23
L132:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
size_t wcsrtombs(char *restrict s, const wchar_t **restrict ws, size_t n, mbstate_t *restrict st) {
  const wchar_t *ws2;
  char buf[4];
  size_t N = n, l;
  if (!s) {
    for (n = 0, ws2 = *ws; *ws2; ws2++) {
      if (*ws2 >= 0x80u) {
        l = wcrtomb(buf, *ws2, 0);
        if (!(l + 1))
          return -1;
        n += l;
      } else
        n++;
    }
    return n;
  }
  while (n >= 4 && **ws) {
    if (**ws >= 0x80u) {
      l = wcrtomb(s, **ws, 0);
      if (!(l + 1))
        return -1;
      s += l;
      n -= l;
    } else {
      *s++ = **ws;
      n--;
    }
    (*ws)++;
  }
  while (n && **ws) {
    if (**ws >= 0x80u) {
      l = wcrtomb(buf, **ws, 0);
      if (!(l + 1))
        return -1;
      if (l > n)
        return N - n;
      wcrtomb(s, **ws, 0);
      s += l;
      n -= l;
    } else {
      *s++ = **ws;
      n--;
    }
    (*ws)++;
  }
  if (n)
    *s = 0;
  *ws = 0;
  return N - n;
}
```