// File: dsharlet[P]array/test/shape.cpp
// Function: nda::test_shape_make_compact_body()
TEST(shape_make_compact) {
  shape<dim<>> s1({3, 5, 2});
  shape<dense_dim<>> s1_compact({3, 5, 1});
  assert_shapes_eq(make_compact(s1), s1_compact);

  shape<dim<>, dim<>> s2({3, 5, 8}, {1, 4, 1});
  shape<dense_dim<>, dim<>> s2_compact({3, 5, 1}, {1, 4, 5});
  assert_shapes_eq(make_compact(s2), s2_compact);

  shape<dim<>, dense_dim<>> s3({3, 5, 8}, {1, 4});
  shape<dim<>, dense_dim<>> s3_compact({3, 5, 4}, {1, 4});
  assert_shapes_eq(make_compact(s3), s3_compact);

  shape<dim<>, dense_dim<dynamic, 4>> s4({5, 3, 8}, {2, 4});
  shape<strided_dim<4>, dense_dim<dynamic, 4>> s4_compact({5, 3}, {2, 4});
  assert_shapes_eq(make_compact(s4), s4_compact);

  // We can't make the first dimenion static stride 1, because
  // we don't know its extent when assigning the static strides.
  shape<dim<>, strided_dim<8>> s5({5, 8}, {2, 4});
  shape<dim<>, strided_dim<8>> s5_compact({5, 8, 1}, {2, 4});
  assert_shapes_eq(make_compact(s5), s5_compact);

  // TODO: Try to give this first dimension static stride 1.
  shape<dim<0, 8>, dim<0, 4, 8>> s6({}, {});
  shape<dim<0, 8>, dim<0, 4, 8>> s6_compact({0, 8, 1}, {});
  assert_shapes_eq(make_compact(s6), s6_compact);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x490, %rsp            # imm = 0x490
leaq -0x30(%rbp), %rdi
movl $0x3, %esi
movl $0x5, %edx
movl $0x2, %ecx
callq 0x10c60
leaq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x367c0
leaq -0x60(%rbp), %rdi
movl $0x3, %esi
movl $0x5, %edx
movl $0x1, %ecx
callq 0x16d70
leaq -0x48(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x970b0
leaq -0x78(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x98da0
leaq -0x78(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x18bf80
leaq -0xc0(%rbp), %rdi
movl $0x3, %esi
movl $0x5, %edx
movl $0x8, %ecx
callq 0x10c60
leaq -0xd8(%rbp), %rdi
movl $0x1, %ecx
movl $0x4, %edx
movq %rcx, %rsi
callq 0x10c60
leaq -0xa8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x11310
leaq -0x120(%rbp), %rdi
movl $0x3, %esi
movl $0x5, %edx
movl $0x1, %ecx
callq 0x16d70
leaq -0x138(%rbp), %rdi
movl $0x1, %esi
movl $0x4, %edx
movl $0x5, %ecx
callq 0x10c60
leaq -0x108(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x138(%rbp), %rdx
callq 0x349d0
leaq -0x168(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3c990
leaq -0x168(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x18bfb0
leaq -0x1b0(%rbp), %rdi
movl $0x3, %esi
movl $0x5, %edx
movl $0x8, %ecx
callq 0x10c60
leaq -0x1c8(%rbp), %rdi
movl $0x1, %ecx
movl $0x4, %edx
movq %rcx, %rsi
callq 0x16d70
leaq -0x198(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
leaq -0x1c8(%rbp), %rdx
callq 0x18bfe0
leaq -0x210(%rbp), %rdi
movl $0x3, %esi
movl $0x5, %edx
movl $0x4, %ecx
callq 0x10c60
leaq -0x228(%rbp), %rdi
movl $0x1, %ecx
movl $0x4, %edx
movq %rcx, %rsi
callq 0x16d70
leaq -0x1f8(%rbp), %rdi
leaq -0x210(%rbp), %rsi
leaq -0x228(%rbp), %rdx
callq 0x18bfe0
leaq -0x258(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x18c060
leaq -0x258(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x18c030
leaq -0x298(%rbp), %rdi
movl $0x5, %esi
movl $0x3, %edx
movl $0x8, %ecx
callq 0x10c60
leaq -0x2a8(%rbp), %rdi
movl $0x2, %esi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x18c0d0
leaq -0x280(%rbp), %rdi
leaq -0x298(%rbp), %rsi
leaq -0x2a8(%rbp), %rdx
callq 0x18c120
leaq -0x2e8(%rbp), %rdi
movl $0x5, %esi
movl $0x3, %edx
movl $0x4, %ecx
callq 0x12ae50
leaq -0x2f8(%rbp), %rdi
movl $0x2, %esi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x18c0d0
leaq -0x2d0(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
leaq -0x2f8(%rbp), %rdx
callq 0x18c170
leaq -0x320(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x18c1f0
leaq -0x320(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x18c1c0
leaq -0x368(%rbp), %rdi
movl $0x5, %esi
movl $0x8, %edx
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
callq 0x10c60
leaq -0x380(%rbp), %rdi
movl $0x2, %esi
movl $0x4, %edx
movl $0x8, %ecx
callq 0x18c260
leaq -0x350(%rbp), %rdi
leaq -0x368(%rbp), %rsi
leaq -0x380(%rbp), %rdx
callq 0x18c2b0
leaq -0x3c8(%rbp), %rdi
movl $0x5, %esi
movl $0x8, %edx
movl $0x1, %ecx
callq 0x10c60
leaq -0x3e0(%rbp), %rdi
movl $0x2, %esi
movl $0x4, %edx
movl $0x8, %ecx
callq 0x18c260
leaq -0x3b0(%rbp), %rdi
leaq -0x3c8(%rbp), %rsi
leaq -0x3e0(%rbp), %rdx
callq 0x18c2b0
leaq -0x410(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x18c330
leaq -0x410(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0x18c300
leaq -0x438(%rbp), %rdi
callq 0x18c3a0
leaq -0x43b(%rbp), %rdi
callq 0x18c3c0
leaq -0x428(%rbp), %rdi
leaq -0x438(%rbp), %rsi
leaq -0x43b(%rbp), %rdx
callq 0x18c3e0
leaq -0x468(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x8, %edx
movl $0x1, %ecx
callq 0x18c440
leaq -0x46b(%rbp), %rdi
callq 0x18c3c0
leaq -0x458(%rbp), %rdi
leaq -0x468(%rbp), %rsi
leaq -0x46b(%rbp), %rdx
callq 0x18c3e0
leaq -0x488(%rbp), %rdi
leaq -0x428(%rbp), %rsi
callq 0x18c4c0
leaq -0x488(%rbp), %rdi
leaq -0x458(%rbp), %rsi
callq 0x18c490
addq $0x490, %rsp            # imm = 0x490
popq %rbp
retq
nopw (%rax,%rax)