// File: dsharlet[P]array/test/array_ref.cpp
// Function: nda::test_array_ref_crop_slice_body()
TEST(array_ref_crop_slice) {
  array<int, shape<dense_dim<0>, dim<>>> a({8, 9});
  fill_pattern(a);

  auto a_slice1 = a(3, _);
  static_assert(a_slice1.rank() == 1, "");
  assert_dim_eq(a_slice1.x(), a.y());
  // TODO: This doesn't pass because check_pattern doesn't understand
  // that there is a second dimension to the pattern.
  // check_pattern(a_slice1);

  auto a_slice2 = a(_, 2);
  static_assert(a_slice2.rank() == 1, "");
  assert_dim_eq(a_slice2.x(), a.x());
  // check_pattern(a_slice2);

  auto a_crop1_slice2 = a(interval<4, 3>(), 5);
  static_assert(a_crop1_slice2.rank() == 1, "");
  assert_dim_eq(a_crop1_slice2.x(), dense_dim<4, 3>());
  // check_pattern(a_crop1_slice2);

  auto a_slice1_crop2 = a(6, interval<4, 3>());
  static_assert(a_slice1_crop2.rank() == 1, "");
  assert_dim_eq(a_slice1_crop2.x(), dim<4, 3>(4, 3, a.y().stride()));
  // check_pattern(a_slice1_crop2);

  auto a_crop1_crop2 = a(interval<>(2, 6), interval<3, 4>());
  static_assert(a_crop1_crop2.rank() == 2, "");
  assert_dim_eq(a_crop1_crop2.x(), dense_dim<>(2, 6));
  assert_dim_eq(a_crop1_crop2.y(), dim<3, 4>(3, 4, a.y().stride()));
  check_pattern(a_crop1_crop2);

  auto a_all1_crop2 = a(_, interval<3, 4>());
  static_assert(a_all1_crop2.rank() == 2, "");
  assert_dim_eq(a_all1_crop2.x(), a.x());
  assert_dim_eq(a_all1_crop2.y(), dim<3, 4>(3, 4, a.y().stride()));
  check_pattern(a_all1_crop2);

  auto a_temp_names = a(range(2, 6), fixed_interval<5>(3));
  static_assert(a_temp_names.rank() == 2, "");
  assert_dim_eq(a_temp_names.x(), dense_dim<>(2, 4));
  assert_dim_eq(a_temp_names.y(), fixed_dim<5>(3, 5, a.y().stride()));
  check_pattern(a_temp_names);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3e0, %rsp            # imm = 0x3E0
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x308(%rbp)
movl $0x8, %esi
movl $0x9, %edx
callq 0x976a0
movq -0x308(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x300(%rbp)
callq 0x976e0
movq -0x300(%rbp), %rdi
xorl %esi, %esi
callq 0x97770
jmp 0x91b62
movw 0x200781(%rip), %ax     # 0x2922ea
movw %ax, -0x112(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movl $0x3, %edx
callq 0x977a0
jmp 0x91b8a
leaq -0x110(%rbp), %rdi
callq 0x97a20
movq %rax, -0x310(%rbp)
jmp 0x91b9f
leaq -0xb0(%rbp), %rdi
callq 0x97a40
movq %rax, -0x318(%rbp)
jmp 0x91bb4
movq -0x318(%rbp), %rsi
movq -0x310(%rbp), %rdi
callq 0x97810
jmp 0x91bc9
movw 0x20071a(%rip), %ax     # 0x2922ea
movw %ax, -0x13a(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movl $0x2, %edx
callq 0x97a60
jmp 0x91bf1
leaq -0x138(%rbp), %rdi
callq 0x97ce0
movq %rax, -0x320(%rbp)
jmp 0x91c06
leaq -0xb0(%rbp), %rdi
callq 0x97d00
movq %rax, -0x328(%rbp)
jmp 0x91c1b
movq -0x328(%rbp), %rsi
movq -0x320(%rbp), %rdi
callq 0x97ad0
jmp 0x91c30
leaq -0x152(%rbp), %rdi
callq 0x97d90
jmp 0x91c3e
leaq -0x150(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movl $0x5, %edx
callq 0x97d20
jmp 0x91c58
leaq -0x150(%rbp), %rdi
callq 0x97fc0
movq %rax, -0x330(%rbp)
jmp 0x91c6d
leaq -0x155(%rbp), %rdi
callq 0x97fe0
jmp 0x91c7b
movq -0x330(%rbp), %rdi
leaq -0x155(%rbp), %rsi
callq 0x97db0
jmp 0x91c90
leaq -0x172(%rbp), %rdi
callq 0x97d90
jmp 0x91c9e
leaq -0x170(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movl $0x6, %edx
callq 0x98000
jmp 0x91cb8
leaq -0x170(%rbp), %rdi
callq 0x98280
movq %rax, -0x338(%rbp)
jmp 0x91ccd
leaq -0xb0(%rbp), %rdi
callq 0x97a40
movq %rax, -0x340(%rbp)
jmp 0x91ce2
movq -0x340(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x348(%rbp)
movq -0x348(%rbp), %rcx
leaq -0x188(%rbp), %rdi
movl $0x4, %esi
movl $0x3, %edx
callq 0x982a0
jmp 0x91d26
movq -0x338(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x98070
jmp 0x91d3b
leaq -0x1c8(%rbp), %rdi
movl $0x2, %esi
movl $0x6, %edx
callq 0x13e90
jmp 0x91d53
leaq -0x1ca(%rbp), %rdi
callq 0x98360
jmp 0x91d61
movq -0x1c8(%rbp), %rdx
movq -0x1c0(%rbp), %rcx
leaq -0x1b8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x982f0
jmp 0x91d84
leaq -0x1b8(%rbp), %rdi
callq 0x98590
movq %rax, -0x350(%rbp)
jmp 0x91d99
leaq -0x1e8(%rbp), %rdi
movl $0x2, %esi
movl $0x6, %edx
movl $0x1, %ecx
callq 0x16d70
jmp 0x91db6
movq -0x350(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x98380
jmp 0x91dcb
leaq -0x1b8(%rbp), %rdi
callq 0x987c0
movq %rax, -0x358(%rbp)
jmp 0x91de0
leaq -0xb0(%rbp), %rdi
callq 0x97a40
movq %rax, -0x360(%rbp)
jmp 0x91df5
movq -0x360(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x368(%rbp)
movq -0x368(%rbp), %rcx
leaq -0x1f8(%rbp), %rdi
movl $0x3, %esi
movl $0x4, %edx
callq 0x987e0
jmp 0x91e39
movq -0x358(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x985b0
jmp 0x91e4e
leaq -0x208(%rbp), %rdi
movq %rdi, -0x370(%rbp)
callq 0x365d0
movq -0x370(%rbp), %rsi
leaq -0x1b8(%rbp), %rdi
callq 0x98830
jmp 0x91e76
movw 0x20046d(%rip), %ax     # 0x2922ea
movw %ax, -0x23a(%rbp)
leaq -0x23c(%rbp), %rdi
callq 0x98360
jmp 0x91e92
leaq -0x238(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x98870
jmp 0x91ea7
leaq -0x238(%rbp), %rdi
callq 0x988d0
movq %rax, -0x378(%rbp)
jmp 0x91ebc
leaq -0xb0(%rbp), %rdi
callq 0x97d00
movq %rax, -0x380(%rbp)
jmp 0x91ed1
movq -0x380(%rbp), %rsi
movq -0x378(%rbp), %rdi
callq 0x97ad0
jmp 0x91ee6
leaq -0x238(%rbp), %rdi
callq 0x988f0
movq %rax, -0x388(%rbp)
jmp 0x91efb
leaq -0xb0(%rbp), %rdi
callq 0x97a40
movq %rax, -0x390(%rbp)
jmp 0x91f10
movq -0x390(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x398(%rbp)
movq -0x398(%rbp), %rcx
leaq -0x250(%rbp), %rdi
movl $0x3, %esi
movl $0x4, %edx
callq 0x987e0
jmp 0x91f54
movq -0x388(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x985b0
jmp 0x91f69
leaq -0x260(%rbp), %rdi
movq %rdi, -0x3a0(%rbp)
callq 0x365d0
movq -0x3a0(%rbp), %rsi
leaq -0x238(%rbp), %rdi
callq 0x98910
jmp 0x91f91
movq $0x2, -0x38(%rbp)
movq $0x6, -0x40(%rbp)
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
subq %rsi, %rdx
leaq -0x30(%rbp), %rdi
callq 0x13e90
jmp 0x91fb7
movq -0x30(%rbp), %rax
movq %rax, -0x3b0(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x3a8(%rbp)
movq -0x3a8(%rbp), %rax
movq -0x3b0(%rbp), %rcx
movq %rcx, -0x2a8(%rbp)
movq %rax, -0x2a0(%rbp)
leaq -0x2b8(%rbp), %rdi
movl $0x3, %esi
callq 0x989c0
jmp 0x91ffc
movq -0x2a8(%rbp), %rdx
movq -0x2a0(%rbp), %rcx
movq -0x2b8(%rbp), %r8
leaq -0x298(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x98950
jmp 0x92026
leaq -0x298(%rbp), %rdi
callq 0x989f0
movq %rax, -0x3b8(%rbp)
jmp 0x9203b
leaq -0x2d0(%rbp), %rdi
movl $0x2, %esi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x16d70
jmp 0x92058
movq -0x3b8(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x98380
jmp 0x9206d
leaq -0x298(%rbp), %rdi
callq 0x98c20
movq %rax, -0x3c0(%rbp)
jmp 0x92082
leaq -0xb0(%rbp), %rdi
callq 0x97a40
movq %rax, -0x3c8(%rbp)
jmp 0x92097
movq -0x3c8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x3d0(%rbp)
movq -0x3d0(%rbp), %rcx
leaq -0x2e8(%rbp), %rdi
movl $0x3, %esi
movl $0x5, %edx
callq 0x98c40
jmp 0x920db
movq -0x3c0(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0x98a10
jmp 0x920f0
leaq -0x2f8(%rbp), %rdi
movq %rdi, -0x3d8(%rbp)
callq 0x365d0
movq -0x3d8(%rbp), %rsi
leaq -0x298(%rbp), %rdi
callq 0x98c90
jmp 0x92118
leaq -0xb0(%rbp), %rdi
callq 0x98cd0
addq $0x3e0, %rsp            # imm = 0x3E0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x98cd0
movq -0xe8(%rbp), %rdi
callq 0x33a0
nopw (%rax,%rax)