user: 请将以下的汇编代码转换成C语言代码：

```asm
<restructure_array>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  lea    -0x5000(%rsp),%r11
L29:
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  cmp    %r11,%rsp
  jne    L29
  sub    $0xe40,%rsp
  mov    %rdi,-0x5e18(%rbp)
  mov    %rsi,-0x5e20(%rbp)
  mov    %rdx,-0x5e28(%rbp)
  mov    %rcx,-0x5e30(%rbp)
  mov    %r8,-0x5e38(%rbp)
  mov    %r9,-0x5e40(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x5e30(%rbp),%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x5de0(%rbp)
  cmpq   $0x0,-0x5de0(%rbp)
  je     L77
  movq   $0x0,-0x5de8(%rbp)
  jmp    L157
L176:
  mov    -0x5de8(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x5e28(%rbp),%rax
  add    %rax,%rdx
  mov    -0x5de8(%rbp),%rax
  lea    0x0(,%rax,4),%rcx
  mov    -0x5e38(%rbp),%rax
  add    %rcx,%rax
  mov    (%rax),%eax
  mov    (%rdx),%rdx
  cltq
  mov    %rdx,-0x1f50(%rbp,%rax,8)
  addq   $0x1,-0x5de8(%rbp)
L157:
  mov    -0x5de8(%rbp),%rax
  cmp    -0x5e18(%rbp),%rax
  jb     L176
  movq   $0x1,-0x5df0(%rbp)
  movq   $0x0,-0x5de8(%rbp)
  jmp    L140
L121:
  mov    -0x5de8(%rbp),%rax
  mov    -0x1f50(%rbp,%rax,8),%rax
  mov    -0x5df0(%rbp),%rdx
  imul   %rdx,%rax
  mov    %rax,-0x5df0(%rbp)
  addq   $0x1,-0x5de8(%rbp)
L140:
  mov    -0x5de8(%rbp),%rax
  cmp    -0x5e18(%rbp),%rax
  jb     L121
  mov    -0x5df0(%rbp),%rax
  add    $0x7,%rax
  shr    $0x3,%rax
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <calloc@plt>
  mov    %rax,-0x5dd8(%rbp)
  cmpq   $0x0,-0x5dd8(%rbp)
  jne    L153
  mov    -0x5de0(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  jmp    L170
L153:
  movq   $0x0,-0x5e08(%rbp)
  jmp    L14
L48:
  mov    -0x5e08(%rbp),%rax
  shr    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x5dd8(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  movzbl %al,%edx
  mov    -0x5e08(%rbp),%rax
  and    $0x7,%eax
  mov    %eax,%ecx
  sar    %cl,%edx
  mov    %edx,%eax
  and    $0x1,%eax
  test   %eax,%eax
  jne    L7
  movq   $0xffffffffffffffff,-0x5e00(%rbp)
  mov    -0x5e08(%rbp),%rax
  imul   -0x5e30(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x5e20(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x5e30(%rbp),%rdx
  mov    -0x5de0(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x5e08(%rbp),%rax
  shr    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x5dd8(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  mov    %eax,%edi
  mov    -0x5e08(%rbp),%rax
  and    $0x7,%eax
  mov    $0x1,%esi
  mov    %eax,%ecx
  shl    %cl,%esi
  mov    %esi,%eax
  or     %eax,%edi
  mov    %edi,%ecx
  mov    -0x5dd8(%rbp),%rax
  add    %rdx,%rax
  mov    %ecx,%edx
  mov    %dl,(%rax)
  mov    -0x5e08(%rbp),%rax
  mov    %rax,-0x5df8(%rbp)
  jmp    L12
L8:
  lea    -0x3e90(%rbp),%rcx
  mov    -0x5df8(%rbp),%rdx
  mov    -0x5e28(%rbp),%rsi
  mov    -0x5e18(%rbp),%rax
  mov    %rax,%rdi
  call   <offset_to_index@plt>
  movq   $0x0,-0x5de8(%rbp)
  jmp    L196
L4:
  mov    -0x5de8(%rbp),%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x5e40(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  test   %eax,%eax
  jns    L73
  mov    -0x5de8(%rbp),%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x5e38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltq
  mov    -0x1f50(%rbp,%rax,8),%rdx
  mov    -0x5de8(%rbp),%rax
  mov    -0x3e90(%rbp,%rax,8),%rax
  sub    %rax,%rdx
  mov    -0x5de8(%rbp),%rax
  lea    0x0(,%rax,4),%rcx
  mov    -0x5e38(%rbp),%rax
  add    %rcx,%rax
  mov    (%rax),%eax
  sub    $0x1,%rdx
  cltq
  mov    %rdx,-0x5dd0(%rbp,%rax,8)
  jmp    L156
L73:
  mov    -0x5de8(%rbp),%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x5e38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%ecx
  mov    -0x5de8(%rbp),%rax
  mov    -0x3e90(%rbp,%rax,8),%rdx
  movslq %ecx,%rax
  mov    %rdx,-0x5dd0(%rbp,%rax,8)
L156:
  addq   $0x1,-0x5de8(%rbp)
L196:
  mov    -0x5de8(%rbp),%rax
  cmp    -0x5e18(%rbp),%rax
  jb     L4
  lea    -0x5dd0(%rbp),%rdx
  lea    -0x1f50(%rbp),%rcx
  mov    -0x5e18(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <index_to_offset@plt>
  mov    %rax,-0x5e00(%rbp)
  mov    -0x5e00(%rbp),%rax
  cmp    -0x5e08(%rbp),%rax
  je     L12
  mov    -0x5e00(%rbp),%rax
  shr    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x5dd8(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  mov    %eax,%edi
  mov    -0x5e00(%rbp),%rax
  and    $0x7,%eax
  mov    $0x1,%esi
  mov    %eax,%ecx
  shl    %cl,%esi
  mov    %esi,%eax
  or     %eax,%edi
  mov    %edi,%ecx
  mov    -0x5dd8(%rbp),%rax
  add    %rdx,%rax
  mov    %ecx,%edx
  mov    %dl,(%rax)
  mov    -0x5e00(%rbp),%rax
  imul   -0x5e30(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x5e20(%rbp),%rax
  lea    (%rdx,%rax,1),%rsi
  mov    -0x5df8(%rbp),%rax
  imul   -0x5e30(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x5e20(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x5e30(%rbp),%rax
  mov    %rax,%rdx
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    -0x5e00(%rbp),%rax
  mov    %rax,-0x5df8(%rbp)
L12:
  mov    -0x5e00(%rbp),%rax
  cmp    -0x5e08(%rbp),%rax
  jne    L8
  mov    -0x5df8(%rbp),%rax
  imul   -0x5e30(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x5e20(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x5e30(%rbp),%rdx
  mov    -0x5de0(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <memcpy@plt>
L7:
  addq   $0x1,-0x5e08(%rbp)
L14:
  mov    -0x5e08(%rbp),%rax
  cmp    -0x5df0(%rbp),%rax
  jb     L48
  mov    -0x5dd8(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x5de0(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  jmp    L170
L77:
  nop
L170:
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L2
  call   <__stack_chk_fail@plt>
L2:
  leave
  ret
```

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