// File: /workspace/github_cpp_makefile_star2_O1/dsharlet[P]array/include/array/array.h
// Function: decltype(make_shape_from_tuple((decltype(array_to_tuple(internal::declval<std::array<nda::dim<-9l, -9l, -9l>, nda::shape<nda::dim<0l, 4l, -9l>, nda::dim<0l, 5l, -9l>, nda::dim<0l, 6l, -9l>>::rank()>>())))())) nda::internal::dynamic_optimize_shape<nda::shape<nda::dim<0l, 4l, -9l>, nda::dim<0l, 5l, -9l>, nda::dim<0l, 6l, -9l>>>(nda::shape<nda::dim<0l, 4l, -9l>, nda::dim<0l, 5l, -9l>, nda::dim<0l, 6l, -9l>> const&)
NDARRAY_HOST_DEVICE shape_of_rank<Shape::rank()> dynamic_optimize_shape(const Shape& shape) {
  auto dims = internal::tuple_to_array<dim<>>(shape.dims());

  // Sort the dims by stride.
  bubble_sort(dims.begin(), dims.end());

  // Find dimensions that are contiguous and fuse them.
  size_t rank = dims.size();
  for (size_t i = 0; i + 1 < rank;) {
    if (can_fuse(dims[i], dims[i + 1])) {
      dims[i] = fuse(dims[i], dims[i + 1]);
      for (size_t j = i + 1; j + 1 < rank; j++) {
        dims[j] = dims[j + 1];
      }
      rank--;
    } else {
      i++;
    }
  }

  // Unfortunately, we can't make the rank of the resulting shape smaller. Fill
  // the end of the array with size 1 dimensions.
  for (size_t i = rank; i < dims.size(); i++) {
    dims[i] = dim<>(0, 1, 0);
  }

  return shape_of_rank<Shape::rank()>(array_to_tuple(dims));
}

// Assembly:
subq $0x18, %rsp
movq %rdi, %rax
xorl %edx, %edx
leaq -0x60(%rsp), %rcx
movq %rdx, -0x18(%rcx)
movq $0x4, -0x10(%rcx)
movabsq $-0x8000000000000000, %rdi # imm = 0x8000000000000000
movq %rdi, -0x8(%rcx)
movq 0x28(%rsi), %r8
movq %r8, -0x8(%rcx)
movq %rdx, (%rcx)
movq $0x5, 0x8(%rcx)
movq %rdi, 0x10(%rcx)
movq 0x18(%rsi), %r8
movq %r8, 0x10(%rcx)
movq %rdx, 0x18(%rcx)
movq $0x6, 0x20(%rcx)
movq %rdi, 0x28(%rcx)
movq 0x8(%rsi), %rsi
movq %rsi, 0x28(%rcx)
leaq (%rsp,%rdx), %rsi
addq $-0x78, %rsi
movq %rdx, %rdi
movq -0x68(%rsp,%rdi), %r8
cmpq -0x68(%rsp,%rdx), %r8
jge 0x403ec
leaq (%rsp,%rdi), %r8
addq $-0x78, %r8
movq 0x10(%rsi), %r9
movq %r9, -0x20(%rsp)
movups (%rsi), %xmm0
movaps %xmm0, -0x30(%rsp)
movq 0x10(%r8), %r9
movq %r9, 0x10(%rsi)
movups (%r8), %xmm0
movups %xmm0, (%rsi)
movq -0x20(%rsp), %r9
movq %r9, 0x10(%r8)
movaps -0x30(%rsp), %xmm0
movups %xmm0, (%r8)
addq $0x18, %rdi
cmpq $0x48, %rdi
jne 0x403a6
addq $0x18, %rdx
cmpq $0x48, %rdx
jne 0x4039b
movl $0x3, %edx
movl $0x1, %edi
xorl %esi, %esi
leaq (%rsi,%rsi,2), %r9
leaq (%rdi,%rdi,2), %r8
movq -0x70(%rsp,%r9,8), %r10
movq -0x68(%rsp,%r9,8), %r11
imulq %r10, %r11
cmpq -0x68(%rsp,%r8,8), %r11
jne 0x4047a
leaq (%rsp,%r8,8), %r8
addq $-0x78, %r8
movq (%r8), %r11
imulq %r10, %r11
imulq 0x8(%r8), %r10
leaq (%rsp,%r9,8), %r9
addq $-0x78, %r9
addq %r11, (%r9)
movq %r10, 0x8(%r9)
leaq 0x1(%rdi), %r9
cmpq %rdx, %r9
jae 0x40475
notq %rdi
addq %rdx, %rdi
movq 0x28(%r8), %r9
movq %r9, 0x10(%r8)
movups 0x18(%r8), %xmm0
movups %xmm0, (%r8)
addq $0x18, %r8
decq %rdi
jne 0x4045b
decq %rdx
jmp 0x4047d
movq %rdi, %rsi
leaq 0x1(%rsi), %rdi
cmpq %rdx, %rdi
jb 0x4040c
cmpq $0x2, %rdx
ja 0x404b6
leaq (%rdx,%rdx,2), %rsi
addq $-0x3, %rdx
leaq (%rsp,%rsi,8), %rsi
addq $-0x68, %rsi
xorl %edi, %edi
movq %rdi, -0x10(%rsi)
movq $0x1, -0x8(%rsi)
movq %rdi, (%rsi)
addq $0x18, %rsi
incq %rdx
jne 0x4049e
movq 0x28(%rcx), %rdx
leaq -0x30(%rsp), %rsi
movq %rdx, 0x10(%rsi)
movups 0x18(%rcx), %xmm0
movaps %xmm0, (%rsi)
movups (%rcx), %xmm0
movups %xmm0, 0x18(%rsi)
movq 0x10(%rcx), %rcx
movq %rcx, 0x28(%rsi)
movups -0x78(%rsp), %xmm0
movaps %xmm0, 0x30(%rsi)
movq -0x68(%rsp), %rcx
movq %rcx, 0x40(%rsi)
movl $0x9, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x18, %rsp
retq
nop