user: What is the c source code of the assembly code below?

```asm
<restructure_array>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  lea    -0x5000(%rsp),%r11
L171:
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  cmp    %r11,%rsp
  jne    L171
  sub    $0xe28,%rsp
  mov    %rsi,0x40(%rsp)
  mov    %rdi,%rbx
  mov    %rcx,%rdi
  mov    %rdx,%rbp
  mov    %rdx,0x20(%rsp)
  mov    %r8,%r15
  mov    %r9,%r14
  mov    %rcx,(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x5e18(%rsp)
  xor    %eax,%eax
  call   <malloc@plt>
  mov    %rax,0x48(%rsp)
  test   %rax,%rax
  je     L64
  test   %rbx,%rbx
  je     L146
  xor    %eax,%eax
  mov    %rbp,%rsi
  nop
L137:
  movslq (%r15,%rax,4),%rdx
  mov    (%rsi,%rax,8),%rcx
  add    $0x1,%rax
  mov    %rcx,0x3ed0(%rsp,%rdx,8)
  cmp    %rax,%rbx
  jne    L137
  lea    0x3ed0(%rsp),%rax
  mov    $0x1,%ecx
  lea    (%rax,%rbx,8),%rdx
  nopw   0x0(%rax,%rax,1)
L39:
  imul   (%rax),%rcx
  add    $0x8,%rax
  cmp    %rdx,%rax
  jne    L39
  lea    0x7(%rcx),%rdi
  mov    $0x1,%esi
  mov    %rcx,0x38(%rsp)
  mov    %rcx,%rbp
  shr    $0x3,%rdi
  call   <calloc@plt>
  mov    %rax,0x8(%rsp)
  test   %rax,%rax
  je     L104
  test   %rbp,%rbp
  je     L154
L69:
  mov    0x40(%rsp),%rax
  xor    %ebp,%ebp
  mov    %r14,%r13
  mov    %rax,0x28(%rsp)
  jmp    L151
  nop
L107:
  mov    (%rsp),%rdi
  add    $0x1,%rbp
  add    %rdi,0x28(%rsp)
  cmp    0x38(%rsp),%rbp
  jae    L154
L151:
  mov    %rbp,%r12
  mov    %ebp,%r14d
  shr    $0x3,%r12
  add    0x8(%rsp),%r12
  and    $0x7,%r14d
  movzbl (%r12),%eax
  bt     %r14d,%eax
  jb     L107
  mov    0x28(%rsp),%rsi
  mov    (%rsp),%rdx
  mov    0x48(%rsp),%rdi
  call   <memcpy@plt>
  lea    0x50(%rsp),%rsi
  mov    %r14d,%ecx
  mov    $0x1,%eax
  mov    %rsi,0x18(%rsp)
  shl    %cl,%eax
  lea    0x1f90(%rsp),%r14
  or     %al,(%r12)
  lea    0x3ed0(%rsp),%rax
  mov    %rbp,%r12
  mov    %rbp,0x10(%rsp)
  mov    %r13,%rbp
  mov    %r14,%r13
  mov    %r15,%r14
  mov    %rax,%r15
L86:
  mov    0x20(%rsp),%rsi
  mov    %r13,%rcx
  mov    %r12,%rdx
  mov    %rbx,%rdi
  call   <offset_to_index@plt>
  xor    %eax,%eax
  test   %rbx,%rbx
  je     L93
  nop
L34:
  mov    0x0(%rbp,%rax,4),%esi
  movslq (%r14,%rax,4),%rdx
  mov    0x0(%r13,%rax,8),%rcx
  test   %esi,%esi
  js     L23
  add    $0x1,%rax
  mov    %rcx,0x50(%rsp,%rdx,8)
  cmp    %rax,%rbx
  jne    L34
L93:
  mov    0x18(%rsp),%rdx
  mov    %r15,%rsi
  mov    %rbx,%rdi
  call   <index_to_offset@plt>
  mov    %rax,%r11
  cmp    0x10(%rsp),%rax
  jne    L170
  mov    (%rsp),%rdx
  mov    0x40(%rsp),%rax
  mov    %rbp,%r13
  mov    %r14,%r15
  mov    0x48(%rsp),%rsi
  mov    0x10(%rsp),%rbp
  imul   %rdx,%r12
  lea    (%rax,%r12,1),%rdi
  call   <memcpy@plt>
  jmp    L107
  nopl   0x0(%rax)
L23:
  not    %rcx
  add    $0x1,%rax
  add    0x3ed0(%rsp,%rdx,8),%rcx
  mov    %rcx,0x50(%rsp,%rdx,8)
  cmp    %rbx,%rax
  jne    L34
  jmp    L93
  nopw   0x0(%rax,%rax,1)
L170:
  mov    0x8(%rsp),%rdi
  mov    %r11d,%ecx
  shr    $0x3,%rax
  mov    $0x1,%edx
  and    $0x7,%ecx
  mov    %r11,0x30(%rsp)
  shl    %cl,%edx
  or     %dl,(%rdi,%rax,1)
  mov    (%rsp),%rdx
  mov    0x40(%rsp),%rax
  mov    %rdx,%rsi
  imul   %rdx,%r12
  imul   %r11,%rsi
  lea    (%rax,%r12,1),%rdi
  add    %rax,%rsi
  call   <memcpy@plt>
  mov    0x30(%rsp),%r12
  jmp    L86
  nopl   0x0(%rax,%rax,1)
L154:
  mov    0x8(%rsp),%rdi
  call   <free@plt>
L104:
  mov    0x48(%rsp),%rdi
  call   <free@plt>
L64:
  mov    0x5e18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L31
  add    $0x5e28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L146:
  mov    $0x1,%esi
  mov    $0x1,%edi
  call   <calloc@plt>
  mov    %rax,0x8(%rsp)
  test   %rax,%rax
  je     L104
  movq   $0x1,0x38(%rsp)
  jmp    L69
L31:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void restructure_array(size_t ndims, unsigned char *array, const size_t *lengths_perm, size_t el_size, const int *map, const int *dir) {
  size_t index[1000];
  size_t index_perm[1000];
  size_t lengths[1000];
  unsigned char *temp;
  size_t offset_start;
  size_t offset_next;
  size_t offset;
  unsigned char *bitmap;
  size_t total;
  size_t i;
  if ((temp = malloc(el_size)) == NULL) {
    return;
  }
  for (i = 0; i < ndims; i++) {
    lengths[map[i]] = lengths_perm[i];
  }
  total = 1;
  for (i = 0; i < ndims; i++) {
    total *= lengths[i];
  }
  bitmap = calloc((total + 8 - 1) / 8, 1);
  if (bitmap == NULL) {
    free(temp);
    return;
  }
  for (offset_start = 0; offset_start < total; offset_start++) {
    if (!(bitmap[(offset_start) / 8] & (1 << ((offset_start) % 8)))) {
      offset_next = -1;
      memcpy(temp, array + (offset_start * el_size), el_size);
      (bitmap[(offset_start) / 8] |= (1 << ((offset_start) % 8)));
      offset = offset_start;
      while (offset_next != offset_start) {
        offset_to_index(ndims, lengths_perm, offset, index_perm);
        for (i = 0; i < ndims; i++) {
          if (dir[i] < 0) {
            index[map[i]] = lengths[map[i]] - index_perm[i] - 1;
          } else {
            index[map[i]] = index_perm[i];
          }
        }
        offset_next = index_to_offset(ndims, lengths, index);
        if (offset_next != offset_start) {
          (bitmap[(offset_next) / 8] |= (1 << ((offset_next) % 8)));
          memcpy(array + (offset * el_size), array + (offset_next * el_size), el_size);
          offset = offset_next;
        }
      }
      memcpy(array + (offset * el_size), temp, el_size);
    }
  }
  free(bitmap);
  free(temp);
}
```