// File: /workspace/github_cpp_makefile_star2_O1/dsharlet[P]array/test/readme.cpp
// Function: nda::test_readme_body()
TEST(readme) {
  // Define a 3 dimensional shape, and an array of this shape.
  using my_3d_shape_type = shape<dim<>, dim<>, dim<>>;
  constexpr int width = 16;
  constexpr int height = 10;
  constexpr int depth = 3;
  my_3d_shape_type my_3d_shape(width, height, depth);
  array<int, my_3d_shape_type> my_array(my_3d_shape);

  // Access elements of this array.
  for (int z = 0; z < depth; z++) {
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        my_array(x, y, z) = 5;
      }
    }
  }

  // Use for_each_value helper to access this array.
  my_array.for_each_value([](int& value) { value = 5; });

  // Use for_all_indices/for_each_index helper to access this array.
  for_all_indices(my_3d_shape, [&](int x, int y, int z) { my_array(x, y, z) = 5; });
  for_each_index(my_3d_shape, [&](my_3d_shape_type::index_type i) { my_array[i] = 5; });

  // This shows the default iteration order of for_all_indices.
  my_3d_shape_type my_shape(2, 2, 2);
  for_all_indices(
      my_shape, [](int x, int y, int z) { std::cout << x << ", " << y << ", " << z << std::endl; });
  // Output:
  // 0, 0, 0
  // 1, 0, 0
  // 0, 1, 0
  // 1, 1, 0
  // 0, 0, 1
  // 1, 0, 1
  // 0, 1, 1
  // 1, 1, 1

  // This shows the iteration order of for_all_indices with
  // a permutation.
  for_all_indices<2, 0, 1>(
      my_shape, [](int x, int y, int z) { std::cout << x << ", " << y << ", " << z << std::endl; });
  // Output:
  // 0, 0, 0
  // 0, 0, 1
  // 1, 0, 0
  // 1, 0, 1
  // 0, 1, 0
  // 0, 1, 1
  // 1, 1, 0
  // 1, 1, 1

  index_t y = 0;
  index_t z = 0;

  // Define a compile-time dense 3 dimensional shape.
  using my_dense_3d_shape_type =
      shape<dim</*Min=*/dynamic, /*Extent=*/dynamic, /*Stride=*/1>, dim<>, dim<>>;
  array<char, my_dense_3d_shape_type> my_dense_array({16, 3, 3});
  for (auto x : my_dense_array.x()) {
    // The compiler knows that each loop iteration accesses
    // elements that are contiguous in memory for contiguous x.
    my_dense_array(x, y, z) = 0;
  }

  // Define a matrix type with row, column indices.
  using matrix_shape = shape<dim<>, dense_dim<>>;
  array<double, matrix_shape> my_matrix({10, 4});
  for (auto i : my_matrix.i()) {
    for (auto j : my_matrix.j()) {
      // This loop ordering is efficient for this type.
      my_matrix(i, j) = 0.0;
    }
  }

  // Demonstrate slicing an array.
  // Slicing
  array_ref_of_rank<int, 2> channel1 = my_array(_, _, 1);
  array_ref_of_rank<int, 1> row4_channel2 = my_array(_, 4, 2);

  // Cropping
  array_ref_of_rank<int, 3> top_left = my_array(interval<>{0, 2}, interval<>{0, 4}, _);
  array_ref_of_rank<int, 2> center_channel0 = my_array(interval<>{1, 2}, interval<>{2, 4}, 0);

  assert_used(channel1);
  assert_used(row4_channel2);
  assert_used(top_left);
  assert_used(center_channel0);

  // Demonstrate iterating over an array in tiles using split.
  constexpr index_t x_split_factor = 3;
  const index_t y_split_factor = 5;
  for (auto yo : split(my_array.y(), y_split_factor)) {
    for (auto xo : split<x_split_factor>(my_array.x())) {
      auto tile = my_array(xo, yo, _);
      for (auto x : tile.x()) {
        // The compiler knows this loop has a fixed extent x_split_factor!
        tile(x, y, z) = x;
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
leaq 0x30(%rsp), %r15
xorps %xmm0, %xmm0
movups %xmm0, -0x8(%r15)
movups %xmm0, -0x18(%r15)
movq $0x3, 0x8(%r15)
movq %rax, 0x10(%r15)
xorl %r14d, %r14d
movq %r14, 0x18(%r15)
movq $0xa, 0x20(%r15)
movq %rax, 0x28(%r15)
movq %r14, 0x30(%r15)
movq $0x10, 0x38(%r15)
movq %rax, 0x40(%r15)
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x1a362
movq %rbx, %rdi
callq 0x1a43a
movq 0x60(%rbx), %rax
movq 0x48(%rbx), %rcx
movq 0x18(%rbx), %rdx
movq 0x30(%rbx), %rsi
movq 0x50(%rbx), %rdi
imulq %rax, %rdi
movq 0x38(%rbx), %r8
imulq %rcx, %r8
shlq $0x2, %r8
leaq (%r8,%rdi,4), %rdi
movq 0x20(%rbx), %r8
imulq %rsi, %r8
leaq (%rdi,%r8,4), %rdi
subq %rdi, %rdx
shlq $0x2, %rsi
shlq $0x2, %rcx
shlq $0x2, %rax
movq %rdx, %rdi
xorl %r8d, %r8d
movl $0x10, %r9d
movq %rdi, %r10
movl $0x5, (%r10)
addq %rax, %r10
decq %r9
jne 0x7a7b3
incq %r8
addq %rcx, %rdi
cmpq $0xa, %r8
jne 0x7a7aa
incq %r14
addq %rsi, %rdx
cmpq $0x3, %r14
jne 0x7a7a4
movq 0x28(%rsp), %rbx
leaq 0xa0(%rsp), %rdi
movq %r15, %rsi
callq 0x1a813
testq %rbx, %rbx
je 0x7a8a7
movq 0xa8(%rsp), %rax
testq %rax, %rax
jle 0x7a8ca
movq 0xe0(%rsp), %rcx
movq 0xc8(%rsp), %rdx
movq 0xb0(%rsp), %rsi
movq 0xd8(%rsp), %rdi
movq 0xc0(%rsp), %r8
shlq $0x2, %rsi
shlq $0x2, %rdx
leaq (,%rcx,4), %r9
xorl %r10d, %r10d
testq %r8, %r8
jle 0x7a89a
movq %rbx, %r11
xorl %r14d, %r14d
cmpq $0x1, %rcx
jne 0x7a874
testq %rdi, %rdi
jle 0x7a88f
leaq (%r11,%rdi,4), %r15
movq %r11, %r12
movl $0x5, (%r12)
addq $0x4, %r12
cmpq %r15, %r12
jb 0x7a861
jmp 0x7a88f
movq %rdi, %r15
movq %r11, %r12
testq %rdi, %rdi
jle 0x7a88f
movl $0x5, (%r12)
addq %r9, %r12
decq %r15
jne 0x7a87f
addq %rdx, %r11
incq %r14
cmpq %r8, %r14
jne 0x7a84f
incq %r10
addq %rsi, %rbx
cmpq %rax, %r10
jne 0x7a844
jmp 0x7a8ca
movq 0xc0(%rsp), %rax
imulq 0xd8(%rsp), %rax
imulq 0xa8(%rsp), %rax
testq %rax, %rax
jg 0x7b01a
movq 0x70(%rsp), %rax
movq 0x58(%rsp), %rcx
movq 0x28(%rsp), %rdx
movq 0x40(%rsp), %rsi
movq 0x60(%rsp), %rdi
imulq %rax, %rdi
movq 0x48(%rsp), %r8
imulq %rcx, %r8
shlq $0x2, %r8
leaq (%r8,%rdi,4), %rdi
movq 0x30(%rsp), %r8
imulq %rsi, %r8
leaq (%rdi,%r8,4), %rdi
subq %rdi, %rdx
shlq $0x2, %rsi
shlq $0x2, %rcx
shlq $0x2, %rax
xorl %edi, %edi
movq %rdx, %r8
xorl %r9d, %r9d
movl $0x10, %r10d
movq %r8, %r11
movl $0x5, (%r11)
addq %rax, %r11
decq %r10
jne 0x7a925
incq %r9
addq %rcx, %r8
cmpq $0xa, %r9
jne 0x7a91c
incq %rdi
addq %rsi, %rdx
cmpq $0x3, %rdi
jne 0x7a916
movq 0x70(%rsp), %rax
movq 0x58(%rsp), %rcx
movq 0x28(%rsp), %rdx
movq 0x40(%rsp), %rsi
movq 0x60(%rsp), %rdi
imulq %rax, %rdi
movq 0x48(%rsp), %r8
imulq %rcx, %r8
shlq $0x2, %r8
leaq (%r8,%rdi,4), %rdi
movq 0x30(%rsp), %r8
imulq %rsi, %r8
leaq (%rdi,%r8,4), %rdi
subq %rdi, %rdx
shlq $0x2, %rsi
shlq $0x2, %rcx
shlq $0x2, %rax
xorl %edi, %edi
movq %rdx, %r8
xorl %r9d, %r9d
movl $0x10, %r10d
movq %r8, %r11
movl $0x5, (%r11)
addq %rax, %r11
decq %r10
jne 0x7a9a7
incq %r9
addq %rcx, %r8
cmpq $0xa, %r9
jne 0x7a99e
incq %rdi
addq %rsi, %rdx
cmpq $0x3, %rdi
jne 0x7a998
xorl %r14d, %r14d
movq 0x6a5f0(%rip), %r15     # 0xe4fc8
leaq 0x3d989(%rip), %r12     # 0xb8368
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r15, %rdi
movl %ebp, %esi
callq 0x22f0
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2210
movq %rbx, %rdi
movl %r13d, %esi
callq 0x22f0
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2210
movq %rbx, %rdi
movl %r14d, %esi
callq 0x22f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
incq %rbp
cmpq $0x2, %rbp
jne 0x7a9e4
incq %r13
cmpq $0x2, %r13
jne 0x7a9e2
incq %r14
cmpq $0x2, %r14
jne 0x7a9df
xorl %r14d, %r14d
movq 0x6a547(%rip), %r15     # 0xe4fc8
leaq 0x3d8e0(%rip), %r12     # 0xb8368
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r15, %rdi
movl %r13d, %esi
callq 0x22f0
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2210
movq %rbx, %rdi
movl %r14d, %esi
callq 0x22f0
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2210
movq %rbx, %rdi
movl %ebp, %esi
callq 0x22f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
incq %rbp
cmpq $0x2, %rbp
jne 0x7aa8d
incq %r13
cmpq $0x2, %r13
jne 0x7aa8b
incq %r14
cmpq $0x2, %r14
jne 0x7aa88
leaq 0x120(%rsp), %rsi
movq $0x0, (%rsi)
movq $0x10, 0x8(%rsi)
movabsq $-0x8000000000000000, %rbx # imm = 0x8000000000000000
movq %rbx, 0x10(%rsi)
xorl %edi, %edi
callq 0xd09f
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rdi
movups %xmm0, 0x8(%rdi)
movups %xmm0, 0x18(%rdi)
movl $0x3, %eax
movq %rax, 0x28(%rdi)
movq %rbx, 0x30(%rdi)
xorl %ecx, %ecx
movq %rcx, 0x38(%rdi)
movq %rax, 0x40(%rdi)
movq %rbx, 0x48(%rdi)
movq %rcx, 0x50(%rdi)
movq $0x10, 0x58(%rdi)
callq 0x7e8e2
leaq 0xa0(%rsp), %rdi
callq 0x7e9c0
movq 0xf8(%rsp), %rax
testq %rax, %rax
je 0x7abf1
movq 0xf0(%rsp), %rcx
movq 0xd8(%rsp), %rdx
imulq 0xe8(%rsp), %rdx
movq 0xc0(%rsp), %rsi
imulq 0xd0(%rsp), %rsi
movq 0xb8(%rsp), %rdi
addq %rdx, %rsi
addq 0xf0(%rsp), %rsi
subq %rsi, %rdi
movb $0x0, (%rcx,%rdi)
incq %rcx
decq %rax
jne 0x7abad
leaq 0x190(%rsp), %rsi
movq $0x0, (%rsi)
movq $0x4, 0x8(%rsi)
movq %rbx, 0x10(%rsi)
movl $0x1, %edi
callq 0xd09f
xorps %xmm0, %xmm0
leaq 0x120(%rsp), %rdi
movups %xmm0, 0x8(%rdi)
movups %xmm0, 0x18(%rdi)
movq $0x4, 0x28(%rdi)
movq $0x0, 0x38(%rdi)
movq $0xa, 0x40(%rdi)
movq %rbx, 0x48(%rdi)
callq 0x7ec1c
leaq 0x120(%rsp), %rdi
callq 0x7ecd6
movq 0x160(%rsp), %rbx
testq %rbx, %rbx
je 0x7aca2
movq 0x138(%rsp), %r14
movq 0x148(%rsp), %r12
movq 0x168(%rsp), %r13
shlq $0x3, %r13
leaq (,%r12,8), %r15
testq %r12, %r12
je 0x7ac9a
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x20e0
addq %r13, %r14
decq %rbx
jne 0x7ac88
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
movups 0x60(%rsp), %xmm0
leaq 0x190(%rsp), %r14
movups %xmm0, 0x18(%r14)
movq 0x70(%rsp), %rdx
movq %rdx, 0x28(%r14)
movq 0x58(%rsp), %rdx
movq %rdx, 0x10(%r14)
movups 0x48(%rsp), %xmm0
movl $0x1, %edx
subq %rcx, %rdx
movq 0x40(%rsp), %r10
imulq %r10, %rdx
testq %rax, %rax
leaq (%rax,%rdx,4), %rdx
cmoveq %rax, %rdx
movl $0x1, %r11d
leaq 0x220(%rsp), %rdi
movq %rdx, (%rdi)
movups %xmm0, 0x8(%rdi)
movq 0x10(%r14), %rdx
movq %rdx, 0x18(%rdi)
movq 0x18(%r14), %rdx
movq %rdx, 0x20(%rdi)
movaps 0x20(%r14), %xmm0
movups %xmm0, 0x28(%rdi)
movq 0x70(%rsp), %rdx
leaq 0x170(%rsp), %r15
movq %rdx, 0x18(%r15)
movups 0x60(%rsp), %xmm0
movups %xmm0, 0x8(%r15)
movq 0x48(%rsp), %rbx
movq 0x58(%rsp), %rdx
movl $0x4, %esi
movl $0x4, %r9d
subq %rbx, %r9
imulq %rdx, %r9
movl $0x2, %r8d
movl $0x2, %r12d
subq %rcx, %r12
imulq %r10, %r12
testq %rax, %rax
leaq (%rax,%r9,4), %r9
leaq (%r9,%r12,4), %r9
cmoveq %rax, %r9
movq %r9, (%r15)
movq 0x70(%rsp), %r9
leaq 0x30(%rsp), %r12
movups (%r12), %xmm0
movups %xmm0, 0x8(%r14)
movq 0x10(%r12), %r12
movq %r12, 0x18(%r14)
movq 0x60(%rsp), %r12
subq %r12, %r11
imulq %r9, %r11
movl $0x2, %r13d
subq %rbx, %r13
imulq %rdx, %r13
imulq %r10, %rcx
leaq (%rax,%r13,4), %r10
leaq (%r10,%r11,4), %r10
shlq $0x2, %rcx
subq %rcx, %r10
testq %rax, %rax
cmoveq %rax, %r10
imulq %r9, %r12
imulq %rdx, %rbx
shlq $0x2, %rbx
movq %rax, %rcx
subq %rbx, %rcx
shlq $0x2, %r12
subq %r12, %rcx
testq %rax, %rax
cmoveq %rax, %rcx
movq %rcx, (%r14)
xorl %eax, %eax
movq %rax, 0x20(%r14)
movq %rsi, 0x28(%r14)
movq %rdx, 0x30(%r14)
movq %rax, 0x38(%r14)
movq %r8, 0x40(%r14)
movq %r9, 0x48(%r14)
leaq 0x1e8(%rsp), %rbx
movq %r10, (%rbx)
movq %r8, 0x8(%rbx)
movq %rsi, 0x10(%rbx)
movq %rdx, 0x18(%rbx)
movq $0x1, 0x20(%rbx)
movq %r8, 0x28(%rbx)
movq %r9, 0x30(%rbx)
callq 0x7c8e4
movq %r15, %rdi
callq 0x7c8e5
movq %r14, %rdi
callq 0x7c8e6
movq %rbx, %rdi
callq 0x7c8e4
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x7afc5
movq 0x48(%rsp), %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x80(%rsp)
movq %rcx, 0x8(%rsp)
addq %rax, %rcx
decq %rcx
movq %rcx, 0x78(%rsp)
cmpq $0x5, %rax
movl $0x5, %edx
cmovlq %rax, %rdx
movq %rdx, 0x88(%rsp)
movq 0x68(%rsp), %rax
cmpq $0x2, %rax
jle 0x7affb
movq 0x60(%rsp), %r15
leaq (%r15,%rax), %rcx
movq %rcx, 0x98(%rsp)
addq %r15, %rax
addq $-0x3, %rax
movq %rax, 0x90(%rsp)
movq 0x70(%rsp), %rbx
movq 0x28(%rsp), %r14
movq 0x30(%rsp), %r13
movq 0x58(%rsp), %r12
imulq 0x40(%rsp), %r13
movq 0x8(%rsp), %rbp
imulq %rbp, %r12
movq %r15, 0x108(%rsp)
movq $0x3, 0x110(%rsp)
movq %rbx, 0x118(%rsp)
xorl %edi, %edi
leaq 0x108(%rsp), %rsi
callq 0x57a9b
movq %r15, %rax
subq 0x60(%rsp), %rax
imulq 0x70(%rsp), %rax
subq 0x48(%rsp), %rbp
imulq 0x58(%rsp), %rbp
testq %r14, %r14
leaq (%r14,%rbp,4), %rcx
leaq (%rcx,%rax,4), %rcx
cmoveq %r14, %rcx
leaq 0x3(%r15), %rax
shlq $0x2, %r12
subq %r12, %rcx
shlq $0x2, %r13
subq %r13, %rcx
shlq $0x2, %rbx
xorl %edx, %edx
leal (%r15,%rdx), %esi
movl %esi, (%rcx)
incq %rdx
addq %rbx, %rcx
cmpq $0x3, %rdx
jne 0x7af4d
addq $0x5, %r15
movq 0x98(%rsp), %rcx
cmpq %rcx, %r15
movq %rax, %r15
cmovgeq 0x90(%rsp), %r15
cmpq %rcx, %rax
cmovgeq %rax, %r15
cmpq %rcx, %r15
jne 0x7aebf
movq 0x8(%rsp), %rax
movq 0x88(%rsp), %rdx
addq %rdx, %rax
addq %rax, %rdx
decq %rdx
movq 0x78(%rsp), %rcx
cmpq %rdx, %rcx
cmovlq %rcx, %rdx
subq %rax, %rdx
incq %rdx
movq %rax, 0x8(%rsp)
cmpq 0x80(%rsp), %rax
jne 0x7ae88
leaq 0x120(%rsp), %rdi
callq 0x7ee44
leaq 0xa0(%rsp), %rdi
callq 0x7eb24
leaq 0x10(%rsp), %rdi
callq 0x1d3b4
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x402c0(%rip), %rdi     # 0xbb2c2
leaq 0x260e4(%rip), %rsi     # 0xa10ed
leaq 0x402cc(%rip), %rcx     # 0xbb2dc
movl $0x269, %edx            # imm = 0x269
callq 0x2100
leaq 0x2628a(%rip), %rdi     # 0xa12ab
leaq 0x260c5(%rip), %rsi     # 0xa10ed
leaq 0x3faba(%rip), %rcx     # 0xbaae9
movl $0x6a1, %edx            # imm = 0x6A1
callq 0x2100
jmp 0x7b06e
jmp 0x7b06e
jmp 0x7b06e
jmp 0x7b059
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x7eb24
jmp 0x7b05c
jmp 0x7b06e
jmp 0x7b059
jmp 0x7b059
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x1d3b4
movq %rbx, %rdi
callq 0x2300
movq %rax, %rdi
callq 0xc036