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

```asm
<transpose>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rdi,%r15
  mov    %esi,%r14d
  mov    %esi,0x24(%rsp)
  lea    (%rsi,%rsi,1),%edi
  mov    $0x0,%eax
  call   <allocate@plt>
  movslq %eax,%rbx
  test   %r14d,%r14d
  jle    L131
  mov    %eax,%ebp
  mov    %r15,%rcx
  lea    -0x1(%r14),%eax
  lea    0x8(%r15,%rax,8),%rsi
  jmp    L160
L52:
  add    $0x8,%rcx
  cmp    %rsi,%rcx
  je     L151
L160:
  mov    (%rcx),%rdx
  test   %rdx,%rdx
  je     L52
  movzwl (%rdx),%eax
  test   %ax,%ax
  js     L52
L77:
  add    $0x2,%rdx
  movswq %ax,%rax
  addw   $0x1,(%rbx,%rax,2)
  movzwl (%rdx),%eax
  test   %ax,%ax
  jns    L77
  jmp    L52
L112:
  add    $0x2,%rbp
  add    $0x8,%r14
  cmp    %rbp,0x8(%rsp)
  je     L32
L92:
  movzwl 0x0(%rbp),%r13d
  movswl %r13w,%eax
  test   %eax,%eax
  jle    L112
  lea    0x2(%rax,%rax,1),%edi
  mov    $0x0,%eax
  call   <allocate@plt>
  cltq
  mov    %rax,(%r14)
  mov    0x18(%rsp),%rdx
  sub    0x10(%rsp),%rdx
  mov    %rax,(%rdx,%r14,1)
  movswq %r13w,%r13
  movw   $0xffff,(%rax,%r13,2)
  jmp    L112
L15:
  add    $0x1,%rsi
  cmp    %rsi,%r8
  je     L44
L87:
  mov    (%r15,%rsi,8),%rdx
  test   %rdx,%rdx
  je     L15
  movzwl (%rdx),%eax
  test   %ax,%ax
  js     L15
L115:
  add    $0x2,%rdx
  movswq %ax,%rax
  lea    (%r12,%rax,8),%rcx
  mov    (%rcx),%rax
  lea    0x2(%rax),%rdi
  mov    %rdi,(%rcx)
  mov    %si,(%rax)
  movzwl (%rdx),%eax
  test   %ax,%ax
  jns    L115
  jmp    L15
L32:
  mov    %rbx,%rdi
  call   <free@plt>
  mov    0x24(%rsp),%r8d
  mov    $0x0,%esi
  jmp    L87
L151:
  mov    0x24(%rsp),%r13d
  lea    0x0(,%r13,8),%r12d
  mov    %r12d,%edi
  mov    $0x0,%eax
  call   <allocate@plt>
  movslq %eax,%r14
  mov    %r14,0x28(%rsp)
  mov    %r12d,%edi
  mov    $0x0,%eax
  call   <allocate@plt>
  movslq %eax,%r12
  movslq %ebp,%rbp
  mov    %r14,0x10(%rsp)
  mov    %r13d,%edx
  lea    0x0(%rbp,%rdx,2),%rsi
  mov    %rsi,0x8(%rsp)
  mov    %r12,0x18(%rsp)
  jmp    L92
L131:
  mov    0x24(%rsp),%ebp
  shl    $0x3,%ebp
  mov    %ebp,%edi
  mov    $0x0,%eax
  call   <allocate@plt>
  cltq
  mov    %rax,0x28(%rsp)
  mov    %ebp,%edi
  mov    $0x0,%eax
  call   <allocate@plt>
  movslq %eax,%r12
  mov    %rbx,%rdi
  call   <free@plt>
L44:
  mov    %r12,%rdi
  call   <free@plt>
  mov    0x28(%rsp),%rax
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

assistant: ```c
short **transpose(short int **R, int n) {
  register short **new_R;
  register short **temp_R;
  register short *nedges;
  register short *sp;
  register int i;
  register int k;
  nedges = ((short *)allocate((unsigned)((n) * sizeof(short))));
  for (i = 0; i < n; i++) {
    sp = R[i];
    if (sp) {
      while (*sp >= 0)
        nedges[*sp++]++;
    }
  }
  new_R = ((short **)allocate((unsigned)((n) * sizeof(short *))));
  temp_R = ((short **)allocate((unsigned)((n) * sizeof(short *))));
  for (i = 0; i < n; i++) {
    k = nedges[i];
    if (k > 0) {
      sp = ((short *)allocate((unsigned)((k + 1) * sizeof(short))));
      new_R[i] = sp;
      temp_R[i] = sp;
      sp[k] = -1;
    }
  }
  (free((char *)(nedges)));
  for (i = 0; i < n; i++) {
    sp = R[i];
    if (sp) {
      while (*sp >= 0)
        *temp_R[*sp++]++ = i;
    }
  }
  (free((char *)(temp_R)));
  return (new_R);
}
```