// File: /workspace/github_cpp_makefile_star2_O2/dsharlet[P]array/test/shape.cpp
// Function: nda::test_shape_optimize_body()
TEST(shape_optimize) {
  dim<> dummy_dim(0, 1, 0);

  shape_of_rank<3> a({0, 5, 21}, {0, 7, 3}, {5, 3, 1});
  shape_of_rank<3> a_optimized({5, 105, 1}, dummy_dim, dummy_dim);
  assert_shapes_eq(internal::dynamic_optimize_shape(a), a_optimized);

  shape_of_rank<3> b({0, 5, 42}, {3, 7, 6}, {0, 3, 2});
  shape_of_rank<3> b_optimized({9, 105, 2}, dummy_dim, dummy_dim);
  assert_shapes_eq(internal::dynamic_optimize_shape(b), b_optimized);

  shape_of_rank<3> c({0, 5, 40}, {0, 7, 3}, {0, 2, 1});
  shape_of_rank<3> c_optimized({0, 2, 1}, {0, 7, 3}, {0, 5, 40});
  assert_shapes_eq(internal::dynamic_optimize_shape(c), c_optimized);

  shape_of_rank<3> d({0, 5, 28}, {0, 7, 4}, {0, 3, 1});
  shape_of_rank<3> d_optimized({0, 3, 1}, {0, 35, 4}, dummy_dim);
  assert_shapes_eq(internal::dynamic_optimize_shape(d), d_optimized);

  shape_of_rank<10> e(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
  e.resolve();
  shape_of_rank<10> e2 = reorder<9, 5, 3, 7, 2, 8, 4, 6, 0, 1>(e);
  shape_of_rank<10> e_optimized({0, 3628800, 1}, dummy_dim, dummy_dim, dummy_dim, dummy_dim,
      dummy_dim, dummy_dim, dummy_dim, dummy_dim, dummy_dim);
  assert_shapes_eq(internal::dynamic_optimize_shape(e), e_optimized);
  assert_shapes_eq(internal::dynamic_optimize_shape(e2), e_optimized);

  shape_of_rank<2> f({0, 2}, {1, 2});
  shape_of_rank<2> f_optimized({2, 4, 1}, dummy_dim);
  f.resolve();
  assert_shapes_eq(internal::dynamic_optimize_shape(f), f_optimized);

  shape_of_rank<2> g({1, 2}, {1, 2});
  shape_of_rank<2> g_optimized({3, 4, 1}, dummy_dim);
  g.resolve();
  assert_shapes_eq(internal::dynamic_optimize_shape(g), g_optimized);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x6c8, %rsp            # imm = 0x6C8
pushq $0x5
popq %r15
leaq 0x3b0(%rsp), %rsi
movq %r15, (%rsi)
pushq $0x3
popq %r12
movq %r12, 0x8(%rsi)
pushq $0x1
popq %rbp
movq %rbp, 0x10(%rsi)
andq $0x0, 0x18(%rsi)
pushq $0x7
popq %rax
movq %rax, 0x20(%rsi)
movq %r12, 0x28(%rsi)
andq $0x0, 0x30(%rsi)
movq %r15, 0x38(%rsi)
leaq 0x368(%rsp), %rbx
andq $0x0, (%rbx)
movq $0x15, 0x40(%rsi)
movq %rbp, 0x8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movq %rbp, 0x20(%rbx)
andq $0x0, 0x28(%rbx)
movq %r15, 0x30(%rbx)
pushq $0x69
popq %rax
movq %rax, 0x38(%rbx)
movq %rbp, 0x40(%rbx)
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
callq 0x12237
movq %r14, %rdi
movq %rbx, %rsi
callq 0x82b09
leaq 0x320(%rsp), %rsi
andq $0x0, (%rsi)
movq %r12, 0x8(%rsi)
pushq $0x2
popq %r13
movq %r13, 0x10(%rsi)
movq %r12, 0x18(%rsi)
pushq $0x7
popq %r12
movq %r12, 0x20(%rsi)
movq $0x6, 0x28(%rsi)
andq $0x0, 0x30(%rsi)
leaq 0x2d8(%rsp), %rbx
andq $0x0, (%rbx)
movq %r15, 0x38(%rsi)
movq %rbp, 0x8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movq %rbp, 0x20(%rbx)
andq $0x0, 0x28(%rbx)
movq $0x2a, 0x40(%rsi)
movq $0x9, 0x30(%rbx)
pushq $0x69
popq %rax
movq %rax, 0x38(%rbx)
movq %r13, 0x40(%rbx)
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
callq 0x12237
movq %r14, %rdi
movq %rbx, %rsi
callq 0x82b09
leaq 0x290(%rsp), %rsi
andq $0x0, (%rsi)
movq %r13, 0x8(%rsi)
movq %rbp, 0x10(%rsi)
andq $0x0, 0x18(%rsi)
movq %r12, %rcx
movq %r12, 0x20(%rsi)
pushq $0x3
popq %r12
movq %r12, 0x28(%rsi)
andq $0x0, 0x30(%rsi)
leaq 0x248(%rsp), %rbx
andq $0x0, (%rbx)
pushq $0x28
popq %rax
movq %r15, 0x8(%rbx)
movq %rax, 0x10(%rbx)
andq $0x0, 0x18(%rbx)
movq %rcx, 0x20(%rbx)
movq %r12, 0x28(%rbx)
andq $0x0, 0x30(%rbx)
movq %r15, 0x38(%rsi)
movq %rax, 0x40(%rsi)
movq %r13, 0x38(%rbx)
movq %rbp, 0x40(%rbx)
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
callq 0x12237
movq %r14, %rdi
movq %rbx, %rsi
callq 0x82b09
leaq 0x200(%rsp), %rsi
andq $0x0, (%rsi)
movq %r12, 0x8(%rsi)
movq %rbp, 0x10(%rsi)
andq $0x0, 0x18(%rsi)
pushq $0x7
popq %rax
movq %rax, 0x20(%rsi)
pushq $0x4
popq %rax
movq %rax, 0x28(%rsi)
andq $0x0, 0x30(%rsi)
leaq 0x1b8(%rsp), %rbx
andq $0x0, (%rbx)
movq %rbp, 0x8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movq $0x23, 0x20(%rbx)
movq %rax, 0x28(%rbx)
andq $0x0, 0x30(%rbx)
movq %r15, 0x38(%rsi)
movq $0x1c, 0x40(%rsi)
movq %r12, 0x38(%rbx)
movq %rbp, 0x40(%rbx)
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
callq 0x12237
movq %r14, %rdi
movq %rbx, %rsi
callq 0x82b09
subq $0x8, %rsp
leaq 0xd0(%rsp), %rbx
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
pushq $0x3
popq %rcx
pushq $0x4
popq %r8
pushq $0x5
popq %r9
movq %rbx, %rdi
pushq $0xa
pushq $0x9
pushq $0x8
pushq $0x7
pushq $0x6
callq 0x772b4
addq $0x30, %rsp
movq %rbx, %rdi
callq 0x82e0a
leaq 0x5d8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x77358
leaq 0x4e8(%rsp), %r15
andq $0x0, (%r15)
movq %rbp, 0x8(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r15)
movq %rbp, 0x20(%r15)
movups %xmm0, 0x28(%r15)
movq %rbp, 0x38(%r15)
movups %xmm0, 0x40(%r15)
movq %rbp, 0x50(%r15)
movups %xmm0, 0x58(%r15)
movq %rbp, 0x68(%r15)
movups %xmm0, 0x70(%r15)
movq %rbp, 0x80(%r15)
movups %xmm0, 0x88(%r15)
movq %rbp, 0x98(%r15)
movups %xmm0, 0xa0(%r15)
movq %rbp, 0xb0(%r15)
movups %xmm0, 0xb8(%r15)
movq %rbp, 0xc8(%r15)
movups %xmm0, 0xd0(%r15)
movq $0x375f00, 0xe0(%r15) # imm = 0x375F00
movq %rbp, 0xe8(%r15)
leaq 0x3f8(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x77453
movq %r12, %rdi
movq %r15, %rsi
callq 0x838a0
leaq 0x3f8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x77453
movq %rbx, %rdi
movq %r15, %rsi
callq 0x838a0
movq %rbp, (%rbx)
movq %r13, 0x8(%rbx)
movabsq $-0x8000000000000000, %r12 # imm = 0x8000000000000000
movq %r12, 0x10(%rbx)
andq $0x0, 0x18(%rbx)
movq %r13, 0x20(%rbx)
leaq 0x98(%rsp), %r14
andq $0x0, (%r14)
movq %rbp, 0x8(%r14)
andq $0x0, 0x10(%r14)
movq %r12, 0x28(%rbx)
movq %r13, 0x18(%r14)
pushq $0x4
popq %rax
movq %rax, 0x20(%r14)
movq %rbp, 0x28(%r14)
leaq 0x3f8(%rsp), %rbx
movq %rbx, %rdi
callq 0x8e70
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x9125
movq %r15, %rdi
movq %r14, %rsi
callq 0x839a6
movq %rbp, (%r15)
movq %r13, 0x8(%r15)
movq %r12, 0x10(%r15)
movq %rbp, 0x18(%r15)
movq %r13, 0x20(%r15)
leaq 0x68(%rsp), %rbx
andq $0x0, (%rbx)
movq %rbp, 0x8(%rbx)
andq $0x0, 0x10(%rbx)
movq %r12, 0x28(%r15)
pushq $0x3
popq %rax
movq %rax, 0x18(%rbx)
pushq $0x4
popq %rax
movq %rax, 0x20(%rbx)
movq %rbp, 0x28(%rbx)
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x8e70
leaq 0x38(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x9125
movq %r15, %rdi
movq %rbx, %rsi
callq 0x839a6
addq $0x6c8, %rsp            # imm = 0x6C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq