user: Translate the below assembly code into C programming language:

```asm
<restructure_array>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  lea    -0x5000(%rsp),%r11
L161:
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  cmp    %r11,%rsp
  jne    L161
  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     L148
  test   %rbx,%rbx
  je     L97
  xor    %eax,%eax
  mov    %rbp,%rsi
  nop
L170:
  movslq (%r15,%rax,4),%rdx
  mov    (%rsi,%rax,8),%rcx
  add    $0x1,%rax
  mov    %rcx,0x3ed0(%rsp,%rdx,8)
  cmp    %rax,%rbx
  jne    L170
  lea    0x3ed0(%rsp),%rax
  mov    $0x1,%ecx
  lea    (%rax,%rbx,8),%rdx
  nopw   0x0(%rax,%rax,1)
L180:
  imul   (%rax),%rcx
  add    $0x8,%rax
  cmp    %rdx,%rax
  jne    L180
  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     L59
  test   %rbp,%rbp
  je     L150
L6:
  mov    0x40(%rsp),%rax
  xor    %ebp,%ebp
  mov    %r14,%r13
  mov    %rax,0x28(%rsp)
  jmp    L32
  nop
L46:
  mov    (%rsp),%rdi
  add    $0x1,%rbp
  add    %rdi,0x28(%rsp)
  cmp    0x38(%rsp),%rbp
  jae    L150
L32:
  mov    %rbp,%r12
  mov    %ebp,%r14d
  shr    $0x3,%r12
  add    0x8(%rsp),%r12
  and    $0x7,%r14d
  movzbl (%r12),%eax
  bt     %r14d,%eax
  jb     L46
  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
L76:
  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     L175
  nop
L105:
  mov    0x0(%rbp,%rax,4),%esi
  mov    0x0(%r13,%rax,8),%rdx
  movslq (%r14,%rax,4),%rcx
  test   %esi,%esi
  jns    L84
  not    %rdx
  add    0x3ed0(%rsp,%rcx,8),%rdx
L84:
  add    $0x1,%rax
  mov    %rdx,0x50(%rsp,%rcx,8)
  cmp    %rax,%rbx
  jne    L105
L175:
  mov    0x18(%rsp),%rdx
  mov    %r15,%rsi
  mov    %rbx,%rdi
  call   <index_to_offset@plt>
  mov    %rax,%r11
  cmp    0x10(%rsp),%rax
  jne    L184
  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    L46
  nop
L184:
  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    L76
  nopl   0x0(%rax,%rax,1)
L150:
  mov    0x8(%rsp),%rdi
  call   <free@plt>
L59:
  mov    0x48(%rsp),%rdi
  call   <free@plt>
L148:
  mov    0x5e18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L179
  add    $0x5e28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L97:
  mov    $0x1,%esi
  mov    $0x1,%edi
  call   <calloc@plt>
  mov    %rax,0x8(%rsp)
  test   %rax,%rax
  je     L59
  movq   $0x1,0x38(%rsp)
  jmp    L6
L179:
  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);
}
```