user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<restructure_array>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  lea    -0x5000(%rsp),%r11
L65:
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  cmp    %r11,%rsp
  jne    L65
  sub    $0xe18,%rsp
  mov    %rdi,%rbx
  mov    %rsi,0x30(%rsp)
  mov    %rdx,%r14
  mov    %rdx,0x18(%rsp)
  mov    %rcx,%rdi
  mov    %rcx,0x8(%rsp)
  mov    %r8,%rbp
  mov    %r9,%r13
  mov    %fs:0x28,%rax
  mov    %rax,0x5e08(%rsp)
  xor    %eax,%eax
  call   <malloc@plt>
  mov    %rax,0x38(%rsp)
  test   %rax,%rax
  je     L135
  test   %rbx,%rbx
  je     L13
  mov    $0x0,%eax
  mov    %r14,%rsi
L85:
  movslq 0x0(%rbp,%rax,4),%rdx
  mov    (%rsi,%rax,8),%rcx
  mov    %rcx,0x3ec0(%rsp,%rdx,8)
  add    $0x1,%rax
  cmp    %rax,%rbx
  jne    L85
  lea    0x3ec0(%rsp),%rdx
  lea    (%rdx,%rax,8),%rax
  mov    $0x1,%ecx
L225:
  imul   (%rdx),%rcx
  add    $0x8,%rdx
  cmp    %rdx,%rax
  jne    L225
  mov    %rcx,%r14
  mov    %rcx,0x28(%rsp)
  lea    0x7(%rcx),%rdi
  shr    $0x3,%rdi
  mov    $0x1,%esi
  call   <calloc@plt>
  mov    %rax,0x10(%rsp)
  test   %rax,%rax
  je     L142
  test   %r14,%r14
  je     L217
L133:
  mov    0x30(%rsp),%rax
  mov    %rax,0x20(%rsp)
  mov    $0x0,%r15d
  jmp    L164
L142:
  mov    0x38(%rsp),%rdi
  call   <free@plt>
  jmp    L135
L172:
  movslq 0x0(%rbp,%rax,4),%rdx
  mov    (%r12,%rax,8),%rcx
  mov    %rcx,0x40(%rsp,%rdx,8)
L105:
  add    $0x1,%rax
  cmp    %rax,%rbx
  je     L227
L31:
  cmpl   $0x0,0x0(%r13,%rax,4)
  jns    L172
  movslq 0x0(%rbp,%rax,4),%rcx
  mov    0x3ec0(%rsp,%rcx,8),%rdx
  sub    (%r12,%rax,8),%rdx
  sub    $0x1,%rdx
  mov    %rdx,0x40(%rsp,%rcx,8)
  jmp    L105
L227:
  lea    0x40(%rsp),%rdx
  lea    0x3ec0(%rsp),%rsi
  mov    %rbx,%rdi
  call   <index_to_offset@plt>
  mov    %rax,%r14
  cmp    %r15,%rax
  jne    L77
L24:
  mov    (%rsp),%rdi
  mov    0x8(%rsp),%rdx
  imul   %rdx,%rdi
  add    0x30(%rsp),%rdi
  mov    0x38(%rsp),%rsi
  call   <memcpy@plt>
L67:
  add    $0x1,%r15
  mov    0x8(%rsp),%rdi
  add    %rdi,0x20(%rsp)
  cmp    0x28(%rsp),%r15
  jae    L217
L164:
  mov    %r15,%r12
  shr    $0x3,%r12
  add    0x10(%rsp),%r12
  mov    %r15d,%r14d
  and    $0x7,%r14d
  movzbl (%r12),%eax
  bt     %r14d,%eax
  jb     L67
  mov    0x8(%rsp),%rdx
  mov    0x20(%rsp),%rsi
  mov    0x38(%rsp),%rdi
  call   <memcpy@plt>
  mov    $0x1,%eax
  mov    %r14d,%ecx
  shl    %cl,%eax
  or     %al,(%r12)
  cmp    $0xffffffffffffffff,%r15
  je     L1
  mov    %r15,(%rsp)
  lea    0x1f80(%rsp),%r12
  jmp    L169
L77:
  shr    $0x3,%rax
  mov    %r14d,%ecx
  and    $0x7,%ecx
  mov    $0x1,%edx
  shl    %cl,%edx
  mov    0x10(%rsp),%rdi
  or     %dl,(%rdi,%rax,1)
  mov    0x8(%rsp),%rax
  mov    %rax,%rsi
  imul   %r14,%rsi
  mov    0x30(%rsp),%rcx
  add    %rcx,%rsi
  mov    (%rsp),%rdi
  imul   %rax,%rdi
  add    %rcx,%rdi
  mov    %rax,%rdx
  call   <memcpy@plt>
  mov    %r14,(%rsp)
L169:
  mov    %r12,%rcx
  mov    (%rsp),%rdx
  mov    0x18(%rsp),%rsi
  mov    %rbx,%rdi
  call   <offset_to_index@plt>
  test   %rbx,%rbx
  je     L227
  mov    $0x0,%eax
  jmp    L31
L1:
  mov    %r15,(%rsp)
  jmp    L24
L217:
  mov    0x10(%rsp),%rdi
  call   <free@plt>
  mov    0x38(%rsp),%rdi
  call   <free@plt>
L135:
  mov    0x5e08(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L82
  add    $0x5e18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L13:
  mov    $0x1,%esi
  mov    $0x1,%edi
  call   <calloc@plt>
  mov    %rax,0x10(%rsp)
  test   %rax,%rax
  je     L142
  movq   $0x1,0x28(%rsp)
  jmp    L133
L82:
  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);
}
```