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

```asm
<permute>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  mov    %rdx,%r15
  push   %r14
  push   %r13
  push   %r12
  lea    0x7(%rsi),%r12d
  push   %rbx
  sub    $0x68,%rsp
  mov    %rdi,-0x70(%rbp)
  mov    %esi,-0x44(%rbp)
  mov    %rcx,-0x60(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  test   %esi,%esi
  cmovns %esi,%r12d
  sar    $0x3,%r12d
  add    $0x1,%r12d
  mov    %r12d,%edi
  call   <malloc@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L64
L120:
  lea    0x17(%r15),%rax
  mov    %rsp,%rcx
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L48
L22:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L22
L48:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L41
L16:
  lea    0xf(%rsp),%rax
  mov    %r12d,%edx
  xor    %esi,%esi
  mov    %r14,%rdi
  and    $0xfffffffffffffff0,%rax
  mov    %r15,%r13
  mov    %rax,-0x88(%rbp)
  call   <memset@plt>
  mov    -0x70(%rbp),%rax
  movslq -0x44(%rbp),%rbx
  movq   $0x0,-0x58(%rbp)
  mov    %rax,-0x78(%rbp)
  mov    %rbx,-0x80(%rbp)
  test   %ebx,%ebx
  jg     L0
  jmp    L67
  nopl   0x0(%rax)
L205:
  addq   $0x1,-0x58(%rbp)
  mov    -0x58(%rbp),%rax
  add    %r13,-0x78(%rbp)
  cmp    %rax,-0x80(%rbp)
  je     L67
L0:
  mov    -0x58(%rbp),%rax
  mov    %eax,%r11d
  mov    %eax,%ecx
  mov    %eax,%r12d
  sar    $0x3,%r11d
  and    $0x7,%ecx
  movslq %r11d,%r11
  add    %r14,%r11
  movzbl (%r11),%eax
  bt     %ecx,%eax
  jb     L205
  mov    -0x78(%rbp),%rsi
  mov    -0x88(%rbp),%rdi
  mov    %r13,%rdx
  mov    %ecx,-0x48(%rbp)
  mov    %r11,-0x50(%rbp)
  mov    %rsi,%rbx
  call   <memcpy@plt>
  mov    -0x58(%rbp),%rax
  mov    -0x60(%rbp),%rdi
  mov    -0x50(%rbp),%r11
  mov    -0x48(%rbp),%ecx
  mov    (%rdi,%rax,4),%r15d
  mov    %eax,-0x64(%rbp)
  cmp    %eax,%r15d
  je     L215
  mov    %r13,%rax
  mov    %r12d,%r13d
  mov    %rax,%r12
  jmp    L196
L61:
  cmp    %r13d,-0x44(%rbp)
  jle    L140
L92:
  test   %r13d,%r13d
  js     L140
L184:
  movslq %r15d,%r9
  movslq %r13d,%rdi
  mov    -0x70(%rbp),%rax
  mov    %r12,%rdx
  mov    %r9,%rsi
  imul   %r12,%rdi
  mov    %r9,-0x50(%rbp)
  imul   %r12,%rsi
  add    %rax,%rdi
  lea    (%rax,%rsi,1),%rbx
  mov    %rbx,%rsi
  call   <memcpy@plt>
  mov    %r13d,%eax
  mov    %r13d,%ecx
  mov    $0x1,%edx
  sar    $0x3,%eax
  and    $0x7,%ecx
  mov    -0x50(%rbp),%r9
  mov    %r15d,%r13d
  cltq
  shl    %cl,%edx
  or     %dl,(%r14,%rax,1)
  mov    -0x60(%rbp),%rax
  mov    (%rax,%r9,4),%eax
  cmp    -0x64(%rbp),%eax
  je     L179
  mov    %eax,%r15d
L196:
  cmp    %r15d,-0x44(%rbp)
  mov    %r15d,%eax
  setle  %bl
  shr    $0x1f,%eax
  or     %al,%bl
  mov    %bl,-0x48(%rbp)
  je     L61
  xor    %eax,%eax
  call   <abort@plt>
  cmp    %r13d,-0x44(%rbp)
  jg     L92
  nopw   0x0(%rax,%rax,1)
L140:
  xor    %eax,%eax
  call   <abort@plt>
  jmp    L184
  nopl   0x0(%rax)
L179:
  mov    %r15d,%r11d
  mov    %r15d,%ecx
  mov    %r12,%r13
  sar    $0x3,%r11d
  and    $0x7,%ecx
  movslq %r11d,%r11
  add    %r14,%r11
L134:
  cmpb   $0x0,-0x48(%rbp)
  jne    L19
L3:
  mov    -0x88(%rbp),%rsi
  mov    %r13,%rdx
  mov    %rbx,%rdi
  mov    %ecx,-0x48(%rbp)
  mov    %r11,-0x50(%rbp)
  call   <memcpy@plt>
  mov    -0x48(%rbp),%ecx
  mov    -0x50(%rbp),%r11
  mov    $0x1,%eax
  shl    %cl,%eax
  or     %al,(%r11)
  jmp    L205
  nopl   0x0(%rax,%rax,1)
L67:
  mov    %r14,%rdi
  call   <free@plt>
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L182
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
  cs nopw 0x0(%rax,%rax,1)
L19:
  xor    %eax,%eax
  mov    %ecx,-0x48(%rbp)
  mov    %r11,-0x50(%rbp)
  call   <abort@plt>
  mov    -0x48(%rbp),%ecx
  mov    -0x50(%rbp),%r11
  jmp    L3
  nopw   0x0(%rax,%rax,1)
L215:
  cmp    %r15d,-0x44(%rbp)
  setle  -0x48(%rbp)
  jmp    L134
L41:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L16
L64:
  lea    D6(%rip),%rsi
  mov    $0xffffffff,%edi
  call   <fastpm_raise@plt>
  jmp    L120
L182:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: label: D6
type_guessed: string

tool: D6: 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);
}
```