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

```asm
<permute>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %esi,-0x3c(%rbp)
  mov    %rdx,-0x48(%rbp)
  mov    %rcx,-0x50(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x3c(%rbp),%eax
  lea    0x7(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0x3,%eax
  add    $0x1,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  jne    L175
  lea    D4(%rip),%rax
  mov    %rax,%rsi
  mov    $0xffffffff,%edi
  call   <fastpm_raise@plt>
L175:
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x48(%rbp),%rax
  lea    0x8(%rax),%rdx
  mov    $0x10,%eax
  sub    $0x1,%rax
  add    %rdx,%rax
  mov    $0x10,%edi
  mov    $0x0,%edx
  div    %rdi
  imul   $0x10,%rax,%rax
  mov    %rax,%rcx
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,%rdx
  sub    %rcx,%rdx
L14:
  cmp    %rdx,%rsp
  je     L48
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L14
L48:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  mov    %rax,%rdx
  and    $0xfff,%edx
  test   %rdx,%rdx
  je     L67
  and    $0xfff,%eax
  sub    $0x8,%rax
  add    %rsp,%rax
  orq    $0x0,(%rax)
L67:
  mov    %rsp,%rax
  add    $0xf,%rax
  shr    $0x4,%rax
  shl    $0x4,%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x3c(%rbp),%eax
  lea    0x7(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0x3,%eax
  lea    0x1(%rax),%edx
  mov    -0x20(%rbp),%rax
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  movl   $0x0,-0x28(%rbp)
  jmp    L95
L82:
  mov    -0x28(%rbp),%eax
  sar    $0x3,%eax
  movslq %eax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  movzbl %al,%edx
  mov    -0x28(%rbp),%eax
  and    $0x7,%eax
  mov    %eax,%ecx
  sar    %cl,%edx
  mov    %edx,%eax
  and    $0x1,%eax
  test   %eax,%eax
  jne    L51
  mov    -0x28(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jge    L32
  cmpl   $0x0,-0x28(%rbp)
  jns    L52
L32:
  mov    $0x0,%eax
  call   <abort@plt>
L52:
  mov    -0x28(%rbp),%eax
  cltq
  imul   -0x48(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x18(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x48(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x28(%rbp),%eax
  mov    %eax,-0x24(%rbp)
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  mov    %eax,-0x2c(%rbp)
  jmp    L31
L130:
  mov    -0x2c(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jge    L141
  cmpl   $0x0,-0x2c(%rbp)
  jns    L100
L141:
  mov    $0x0,%eax
  call   <abort@plt>
L100:
  mov    -0x24(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jge    L38
  cmpl   $0x0,-0x24(%rbp)
  jns    L164
L38:
  mov    $0x0,%eax
  call   <abort@plt>
L164:
  mov    -0x2c(%rbp),%eax
  cltq
  imul   -0x48(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x18(%rbp),%rax
  lea    (%rdx,%rax,1),%rsi
  mov    -0x24(%rbp),%eax
  cltq
  imul   -0x48(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x18(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdx
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    -0x24(%rbp),%eax
  sar    $0x3,%eax
  movslq %eax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  mov    %eax,%esi
  mov    -0x24(%rbp),%eax
  and    $0x7,%eax
  mov    $0x1,%edx
  mov    %eax,%ecx
  shl    %cl,%edx
  mov    %edx,%eax
  or     %eax,%esi
  mov    %esi,%ecx
  mov    -0x24(%rbp),%eax
  sar    $0x3,%eax
  movslq %eax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    %ecx,%edx
  mov    %dl,(%rax)
  mov    -0x2c(%rbp),%eax
  mov    %eax,-0x24(%rbp)
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  mov    %eax,-0x2c(%rbp)
L31:
  mov    -0x2c(%rbp),%eax
  cmp    -0x28(%rbp),%eax
  jne    L130
  mov    -0x24(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jge    L150
  cmpl   $0x0,-0x24(%rbp)
  jns    L21
L150:
  mov    $0x0,%eax
  call   <abort@plt>
L21:
  mov    -0x24(%rbp),%eax
  cltq
  imul   -0x48(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x18(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x48(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    -0x24(%rbp),%eax
  sar    $0x3,%eax
  movslq %eax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  mov    %eax,%esi
  mov    -0x24(%rbp),%eax
  and    $0x7,%eax
  mov    $0x1,%edx
  mov    %eax,%ecx
  shl    %cl,%edx
  mov    %edx,%eax
  or     %eax,%esi
  mov    %esi,%ecx
  mov    -0x24(%rbp),%eax
  sar    $0x3,%eax
  movslq %eax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    %ecx,%edx
  mov    %dl,(%rax)
  jmp    L81
L51:
  nop
L81:
  addl   $0x1,-0x28(%rbp)
L95:
  mov    -0x28(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jl     L82
  mov    -0x20(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  nop
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L124
  call   <__stack_chk_fail@plt>
L124:
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: tag: D4
type_infered: string

tool: D4: no memory for 'done'


assistant: ```c
void permute(void *data, int np, size_t elsize, int *ind) {
  unsigned char *done = malloc(np / 8 + 1);
  if (!done) {
    fastpm_raise(-1, "no memory for 'done'\n");
  }
  char *q = data;
  char *temp1 = alloca(elsize);
  int j, i;
  memset(done, 0, np / 8 + 1);
  for (i = 0; i < np; i++) {
    if (done[i >> 3] & (1 << (i & 7)))
      continue;
    if (i >= np || i < 0) {
      abort();
    }
    memcpy(temp1, &q[i * elsize], elsize);
    int ii = i;
    for (j = ind[ii]; j != i; ii = j, j = ind[j]) {
      if (j >= np || j < 0) {
        abort();
      }
      if (ii >= np || ii < 0) {
        abort();
      }
      memcpy(&q[ii * elsize], &q[j * elsize], elsize);
      ;
      done[ii >> 3] |= 1 << (ii & 7);
    }
    if (ii >= np || ii < 0) {
      abort();
    }
    memcpy(&q[ii * elsize], temp1, elsize);
    done[ii >> 3] |= 1 << (ii & 7);
  }
  free(done);
}
```