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

```asm
<generate_string_from_table>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,%rbp
  mov    %esi,%r13d
  mov    %rdx,0x10(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  movq   $0x0,0x30(%rsp)
  lea    -0x1(%rsi),%eax
  cmpq   $0x0,(%rdi,%rax,8)
  je     L20
  lea    -0x1(%rsi,%rsi,1),%eax
  mov    $0x1,%r14d
L129:
  add    $0x1,%r14d
  mov    %eax,%edx
  add    %r13d,%eax
  cmpq   $0x0,0x0(%rbp,%rdx,8)
  jne    L129
L181:
  mov    $0x0,%eax
  call   <rand@plt>
  mov    $0x0,%edx
  div    %r14d
  mov    %edx,0x20(%rsp)
  imul   %r13d,%edx
  lea    0x0(%rbp,%rdx,8),%rbx
  mov    (%rbx),%rdi
  call   <wcslen@plt>
  add    $0x1,%rax
  cmp    0x10(%rsp),%rax
  jbe    L197
L37:
  mov    0x30(%rsp),%rax
  mov    0x38(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L155
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L20:
  mov    $0x1,%r14d
  jmp    L181
L197:
  lea    0x30(%rsp),%rdi
  mov    (%rbx),%rsi
  call   <alloc_wcscat@plt>
  mov    %rax,(%rsp)
  lea    0x30(%rsp),%rax
  mov    %rax,0x18(%rsp)
L36:
  cmp    $0x1,%r13d
  jbe    L92
  mov    0x20(%rsp),%eax
  imul   %r13d,%eax
  lea    0x1(%rax),%ebx
  lea    (%rax,%r13,1),%r15d
L30:
  mov    %ebx,%eax
  lea    0x0(%rbp,%rax,8),%r12
  mov    (%r12),%rdi
  test   %rdi,%rdi
  je     L37
  call   <wcslen@plt>
  mov    (%rsp),%rsi
  lea    0x1(%rsi,%rax,1),%rax
  cmp    0x10(%rsp),%rax
  ja     L37
  mov    (%r12),%rsi
  mov    0x18(%rsp),%rdi
  call   <alloc_wcscat@plt>
  mov    %rax,(%rsp)
  add    $0x1,%ebx
  cmp    %ebx,%r15d
  jne    L30
L92:
  mov    $0x0,%eax
  call   <rand@plt>
  mov    $0x0,%edx
  div    %r14d
  mov    %edx,0x24(%rsp)
  mov    0x20(%rsp),%eax
  add    $0x1,%eax
  imul   %r13d,%eax
  lea    -0x1(%rax),%eax
  lea    0x0(%rbp,%rax,8),%rax
  mov    %rax,0x28(%rsp)
  mov    %edx,%r12d
  jmp    L176
L184:
  add    $0x1,%ebx
  cmp    %r15d,%ebx
  je     L160
L91:
  mov    %ebx,%eax
  mov    0x0(%rbp,%rax,8),%rdi
  test   %rdi,%rdi
  je     L184
  call   <wcslen@plt>
  add    %rax,0x8(%rsp)
  jmp    L184
L17:
  movq   $0x0,0x8(%rsp)
L160:
  mov    %r12d,%eax
  imul   %r13d,%eax
  mov    0x0(%rbp,%rax,8),%rsi
  mov    0x28(%rsp),%rax
  mov    (%rax),%rdi
  call   <wcscmp@plt>
  test   %rax,%rax
  jne    L176
  mov    0x8(%rsp),%rax
  mov    (%rsp),%rsi
  lea    0x1(%rax,%rsi,1),%rax
  cmp    0x10(%rsp),%rax
  jb     L71
L176:
  add    $0x1,%r12d
  cmp    %r14d,%r12d
  mov    $0x0,%eax
  cmove  %eax,%r12d
  cmp    0x24(%rsp),%r12d
  je     L37
  cmp    0x20(%rsp),%r12d
  je     L176
  cmp    $0x1,%r13d
  jbe    L17
  mov    %r12d,%r15d
  imul   %r13d,%r15d
  lea    0x1(%r15),%ebx
  add    %r13d,%r15d
  movq   $0x0,0x8(%rsp)
  jmp    L91
L71:
  mov    %r12d,0x20(%rsp)
  jmp    L36
L155:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
wchar_t *generate_string_from_table(wchar_t **markov_table, unsigned int n, size_t max_length) {
  size_t new_str_length = 0;
  wchar_t *new_str = NULL;
  unsigned int table_num;
  for (table_num = 1; markov_table[table_num * n - 1] != NULL; table_num++)
    ;
  unsigned int current_index = (unsigned int)rand() % table_num;
  if (new_str_length + wcslen(markov_table[current_index * n]) + 1 > max_length)
    goto end;
  new_str_length = alloc_wcscat(&new_str, markov_table[current_index * n]);
  char not_found = 0;
  while (not_found == 0) {
    not_found = 1;
    for (unsigned int i = 1; i < n; i++) {
      if (markov_table[current_index * n + i] == NULL)
        goto end;
      if (new_str_length + wcslen(markov_table[current_index * n + i]) + 1 > max_length)
        goto end;
      new_str_length = alloc_wcscat(&new_str, markov_table[current_index * n + i]);
    }
    unsigned int search_start_point = (unsigned int)rand() % table_num;
    for (unsigned int i = search_start_point;;) {
      i++;
      if (i == table_num)
        i = 0;
      if (i == search_start_point)
        break;
      if (i == current_index)
        continue;
      size_t searching_str_length = 0;
      for (unsigned int j = 1; j < n; j++) {
        if (markov_table[i * n + j] != NULL)
          searching_str_length += wcslen(markov_table[i * n + j]);
      }
      if (wcscmp(markov_table[current_index * n + n - 1], markov_table[i * n]) == 0 && (new_str_length + searching_str_length + 1 < max_length)) {
        current_index = i;
        not_found = 0;
        break;
      }
    }
  }
end:
  return new_str;
}
```