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

```asm
<SortArray>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %esi,-0x2c(%rbp)
  mov    %rdx,-0x38(%rbp)
  mov    %rcx,-0x40(%rbp)
  mov    %r8d,-0x30(%rbp)
  mov    -0x30(%rbp),%eax
  add    $0x1,%eax
  mov    $0x4,%esi
  mov    %eax,%edi
  call   <calloc@plt>
  mov    %rax,-0x10(%rbp)
  movl   $0x0,-0x14(%rbp)
  jmp    L63
L18:
  mov    -0x14(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x40(%rbp),%rax
  add    %rdx,%rax
  mov    -0x14(%rbp),%edx
  movslq %edx,%rdx
  lea    0x0(,%rdx,4),%rcx
  mov    -0x10(%rbp),%rdx
  add    %rcx,%rdx
  mov    (%rax),%eax
  mov    %eax,(%rdx)
  addl   $0x1,-0x14(%rbp)
L63:
  mov    -0x14(%rbp),%eax
  cmp    -0x30(%rbp),%eax
  jle    L18
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x40(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cmp    %eax,-0x2c(%rbp)
  sete   %al
  movzbl %al,%eax
  mov    %eax,%edi
  call   <assert@plt>
  mov    -0x2c(%rbp),%eax
  mov    $0x4,%esi
  mov    %eax,%edi
  call   <calloc@plt>
  mov    %rax,-0x8(%rbp)
  movl   $0x0,-0x14(%rbp)
  jmp    L16
L13:
  mov    -0x28(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0x14(%rbp),%eax
  cltq
  shl    $0x2,%rax
  lea    (%rdx,%rax,1),%rsi
  mov    -0x14(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x40(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%edx
  lea    0x1(%rdx),%ecx
  mov    %ecx,(%rax)
  movslq %edx,%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x8(%rbp),%rax
  add    %rax,%rdx
  mov    (%rsi),%eax
  mov    %eax,(%rdx)
  addl   $0x1,-0x14(%rbp)
L16:
  mov    -0x14(%rbp),%eax
  cmp    -0x2c(%rbp),%eax
  jl     L13
  mov    -0x28(%rbp),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  je     L2
  mov    -0x28(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,%rdi
  call   <free@plt>
L2:
  mov    -0x28(%rbp),%rax
  mov    -0x8(%rbp),%rdx
  mov    %rdx,(%rax)
  mov    -0x30(%rbp),%edx
  mov    -0x40(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <EndIndex2BeginIndex@plt>
  movl   $0x0,-0x14(%rbp)
  jmp    L37
L46:
  mov    -0x14(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%edx
  mov    -0x14(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rcx
  mov    -0x40(%rbp),%rax
  add    %rcx,%rax
  mov    (%rax),%eax
  cmp    %eax,%edx
  sete   %al
  movzbl %al,%eax
  mov    %eax,%edi
  call   <assert@plt>
  addl   $0x1,-0x14(%rbp)
L37:
  mov    -0x14(%rbp),%eax
  cmp    -0x30(%rbp),%eax
  jle    L46
  nop
  nop
  leave
  ret
```

assistant: ```c
void SortArray(int **a, int na, int *key, int *index, int ni) {
  int i;
  int *newa;
  int *aux;
  aux = (int *)calloc(ni + 1, sizeof(int));
  for (i = 0; i <= ni; i++)
    aux[i] = index[i];
  assert(index[ni] == na);
  newa = (int *)calloc(na, sizeof(int));
  for (i = 0; i < na; i++)
    newa[index[key[i]]++] = (*a)[i];
  if (*a != NULL)
    free(*a);
  *a = newa;
  EndIndex2BeginIndex(index, ni);
  for (i = 0; i <= ni; i++)
    assert(aux[i] == index[i]);
}
```