user: Translate the below assembly code into C programming language:

```asm
<wcsnrtombs>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  mov    %rdx,%r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x148,%rsp
  mov    (%rsi),%rdx
  mov    %rdi,0x8(%rsp)
  mov    %rsi,0x10(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x138(%rsp)
  xor    %eax,%eax
  mov    %rdx,0x28(%rsp)
  test   %rdi,%rdi
  je     L229
  test   %rcx,%rcx
  mov    %rcx,%r12
  mov    %rdi,%r14
  setne  %cl
L37:
  test   %rdx,%rdx
  setne  %r15b
  xor    %ebx,%ebx
  and    %cl,%r15b
  mov    %r15b,0x1f(%rsp)
  je     L168
  cmp    $0x20,%r13
  ja     L31
  cmp    %r12,%r13
  jb     L25
L31:
  lea    0x30(%rsp),%rax
  lea    0x28(%rsp),%rbp
  mov    %rax,(%rsp)
  nopw   0x0(%rax,%rax,1)
L225:
  cmp    %r12,%r13
  mov    %r12,%rdx
  mov    %rbp,%rsi
  mov    %r14,%rdi
  cmovbe %r13,%rdx
  xor    %ecx,%ecx
  sub    %rdx,%r13
  call   <wcsrtombs@plt>
  mov    %rax,%r15
  cmp    $0xffffffffffffffff,%rax
  je     L198
  cmp    (%rsp),%r14
  je     L136
  add    %rax,%r14
  sub    %rax,%r12
L136:
  add    %r15,%rbx
  mov    0x28(%rsp),%rdx
  test   %r12,%r12
  setne  %al
  mov    %eax,%ecx
  test   %rdx,%rdx
  je     L89
  test   %al,%al
  je     L168
  cmp    $0x20,%r13
  ja     L225
  cmp    %r13,%r12
  jbe    L225
L25:
  movzbl 0x1f(%rsp),%ecx
L106:
  test   %r13,%r13
  je     L89
  test   %cl,%cl
  je     L89
  mov    0x28(%rsp),%rcx
  mov    %rbx,%r15
  add    %rbx,%r13
  jmp    L7
  nopw   0x0(%rax,%rax,1)
L189:
  mov    0x28(%rsp),%rbx
  add    $0x1,%r15
  add    %rax,%r14
  sub    %rax,%r12
  lea    0x4(%rbx),%rcx
  mov    %rcx,0x28(%rsp)
  cmp    %r15,%r13
  je     L198
  test   %r12,%r12
  je     L198
L7:
  mov    (%rcx),%esi
  xor    %edx,%edx
  mov    %r14,%rdi
  call   <wcrtomb@plt>
  lea    0x1(%rax),%rdx
  cmp    $0x1,%rdx
  ja     L189
  test   %rax,%rax
  jne    L173
  movq   $0x0,0x28(%rsp)
L198:
  cmpq   $0x0,0x8(%rsp)
  je     L19
  mov    0x28(%rsp),%rax
  mov    0x10(%rsp),%rbx
  mov    %rax,(%rbx)
L19:
  mov    0x138(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L113
  add    $0x148,%rsp
  mov    %r15,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L229:
  mov    $0x1,%ecx
  lea    0x30(%rsp),%r14
  mov    $0x100,%r12d
  jmp    L37
  nopl   (%rax)
L168:
  test   %rdx,%rdx
  jne    L106
L89:
  mov    %rbx,%r15
  jmp    L198
  xchg   %ax,%ax
L173:
  mov    $0xffffffffffffffff,%r15
  jmp    L198
L113:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
size_t wcsnrtombs(char *dst, const wchar_t **wcs, size_t wn, size_t n, mbstate_t *st) {
  size_t l, cnt = 0, n2;
  char *s, buf[256];
  const wchar_t *ws = *wcs;
  if (!dst)
    s = buf, n = sizeof buf;
  else
    s = dst;
  while (ws && n && ((n2 = wn) >= n || n2 > 32)) {
    if (n2 >= n)
      n2 = n;
    wn -= n2;
    l = wcsrtombs(s, &ws, n2, 0);
    if (!(l + 1)) {
      cnt = l;
      n = 0;
      break;
    }
    if (s != buf) {
      s += l;
      n -= l;
    }
    cnt += l;
  }
  if (ws)
    while (n && wn) {
      l = wcrtomb(s, *ws, 0);
      if ((l + 1) <= 1) {
        if (!l)
          ws = 0;
        else
          cnt = l;
        break;
      }
      ws++;
      wn--;
      s += l;
      n -= l;
      cnt++;
    }
  if (dst)
    *wcs = ws;
  return cnt;
}
```