// File: dsharlet[P]array/test/array.cpp
// Function: nda::test_array_for_each_value_body()
TEST(array_for_each_value) {
  array_of_rank<int, 3> in_order({{0, 4, 1}, {0, 4, 4}, {0, 4, 16}});
  array_of_rank<int, 3> out_of_order({{0, 4, 16}, {0, 4, 1}, {0, 4, 4}});

  int out_of_order_counter = 0;
  move_only token;
  out_of_order.for_each_value([&, token = std::move(token)](int& v) {
    v = out_of_order_counter++;
    assert_used(token);
  });

  int in_order_counter = 0;
  in_order.for_each_value([&](int& v) { v = in_order_counter++; });

  in_order_counter = 0;
  for (int z : in_order.z()) {
    for (int y : in_order.y()) {
      for (int x : in_order.x()) {
        int expected = in_order_counter++;
        ASSERT_EQ(in_order(x, y, z), expected);
      }
    }
  }

  out_of_order_counter = 0;
  for (int x : out_of_order.x()) {
    for (int z : out_of_order.z()) {
      for (int y : out_of_order.y()) {
        int expected = out_of_order_counter++;
        ASSERT_EQ(out_of_order(x, y, z), expected);
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x900, %rsp            # imm = 0x900
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x730(%rbp)
leaq -0x188(%rbp), %rdi
movq %rdi, -0x750(%rbp)
movl $0x4, %edx
movq %rdx, -0x728(%rbp)
movl $0x1, %ecx
callq 0x10c60
movq -0x730(%rbp), %rsi
movq -0x728(%rbp), %rcx
leaq -0x1a0(%rbp), %rdi
movq %rdi, -0x748(%rbp)
movq %rcx, %rdx
callq 0x10c60
movq -0x730(%rbp), %rsi
movq -0x728(%rbp), %rdx
leaq -0x1b8(%rbp), %rdi
movq %rdi, -0x740(%rbp)
movl $0x10, %ecx
movq %rcx, -0x720(%rbp)
callq 0x10c60
movq -0x750(%rbp), %rsi
movq -0x748(%rbp), %rdx
movq -0x740(%rbp), %rcx
leaq -0x170(%rbp), %rdi
movq %rdi, -0x738(%rbp)
callq 0x36640
movq -0x738(%rbp), %rsi
leaq -0x128(%rbp), %rdi
callq 0x34f10
movq -0x730(%rbp), %rsi
movq -0x728(%rbp), %rdx
movq -0x720(%rbp), %rcx
leaq -0x280(%rbp), %rdi
callq 0x10c60
jmp 0x281c9
xorl %eax, %eax
movl %eax, %esi
leaq -0x2a8(%rbp), %rdi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x10c60
jmp 0x281e5
xorl %eax, %eax
movl %eax, %esi
leaq -0x2c0(%rbp), %rdi
movl $0x4, %ecx
movq %rcx, %rdx
callq 0x10c60
jmp 0x281ff
leaq -0x268(%rbp), %rdi
leaq -0x280(%rbp), %rsi
leaq -0x2a8(%rbp), %rdx
leaq -0x2c0(%rbp), %rcx
callq 0x36640
jmp 0x28222
leaq -0x220(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x34f10
jmp 0x28237
movl $0x0, -0x2c4(%rbp)
leaq -0x2c4(%rbp), %rax
movq %rax, -0x2d0(%rbp)
leaq -0x220(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0x28d70
jmp 0x28264
movl $0x0, -0x2dc(%rbp)
leaq -0x2dc(%rbp), %rax
movq %rax, -0x2e8(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0x28da0
jmp 0x28291
movl $0x0, -0x2dc(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x366a0
movq %rax, -0x758(%rbp)
jmp 0x282b0
movq -0x758(%rbp), %rax
movq %rax, -0x2f0(%rbp)
movq -0x2f0(%rbp), %rdi
callq 0x366c0
movq %rax, -0x760(%rbp)
jmp 0x282d3
movq -0x760(%rbp), %rax
movq %rax, -0x2f8(%rbp)
movq -0x2f0(%rbp), %rdi
callq 0x366f0
movq %rax, -0x768(%rbp)
jmp 0x282f6
movq -0x768(%rbp), %rax
movq %rax, -0x300(%rbp)
leaq -0x2f8(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x300(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rax
movq -0x70(%rbp), %rcx
cmpq (%rcx), %rax
setne %al
movb %al, -0x769(%rbp)
movb -0x769(%rbp), %al
testb $0x1, %al
jne 0x28340
jmp 0x287e4
leaq -0x2f8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x778(%rbp)
movq -0x778(%rbp), %rax
movl %eax, -0x304(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x36740
movq %rax, -0x780(%rbp)
jmp 0x2837b
movq -0x780(%rbp), %rax
movq %rax, -0x310(%rbp)
movq -0x310(%rbp), %rdi
callq 0x366c0
movq %rax, -0x788(%rbp)
jmp 0x2839e
movq -0x788(%rbp), %rax
movq %rax, -0x318(%rbp)
movq -0x310(%rbp), %rdi
callq 0x366f0
movq %rax, -0x790(%rbp)
jmp 0x283c1
movq -0x790(%rbp), %rax
movq %rax, -0x320(%rbp)
leaq -0x318(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x320(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
movq (%rax), %rax
movq -0x80(%rbp), %rcx
cmpq (%rcx), %rax
setne %al
movb %al, -0x791(%rbp)
movb -0x791(%rbp), %al
testb $0x1, %al
jne 0x2840b
jmp 0x287c4
leaq -0x318(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x7a0(%rbp)
movq -0x7a0(%rbp), %rax
movl %eax, -0x324(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x36760
movq %rax, -0x7a8(%rbp)
jmp 0x28446
movq -0x7a8(%rbp), %rax
movq %rax, -0x330(%rbp)
movq -0x330(%rbp), %rdi
callq 0x366c0
movq %rax, -0x7b0(%rbp)
jmp 0x28469
movq -0x7b0(%rbp), %rax
movq %rax, -0x338(%rbp)
movq -0x330(%rbp), %rdi
callq 0x366f0
movq %rax, -0x7b8(%rbp)
jmp 0x2848c
movq -0x7b8(%rbp), %rax
movq %rax, -0x340(%rbp)
leaq -0x338(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x340(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rax
movq -0x90(%rbp), %rcx
cmpq (%rcx), %rax
setne %al
movb %al, -0x7b9(%rbp)
movb -0x7b9(%rbp), %al
testb $0x1, %al
jne 0x284e2
jmp 0x287a4
leaq -0x338(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x7c8(%rbp)
movq -0x7c8(%rbp), %rax
movl %eax, -0x344(%rbp)
movl -0x2dc(%rbp), %eax
movl %eax, %ecx
incl %ecx
movl %ecx, -0x2dc(%rbp)
movl %eax, -0x348(%rbp)
movl -0x344(%rbp), %esi
movl -0x324(%rbp), %edx
movl -0x304(%rbp), %ecx
leaq -0x128(%rbp), %rdi
callq 0x35b40
movq %rax, -0x7d0(%rbp)
jmp 0x28545
movq -0x7d0(%rbp), %rax
movl (%rax), %eax
movl -0x348(%rbp), %ecx
subl %ecx, %eax
sete %al
movb %al, -0x7d9(%rbp)
leaq -0x4f9(%rbp), %rdi
movq %rdi, -0x7d8(%rbp)
callq 0x33b0
movq -0x7d8(%rbp), %rdx
leaq 0x1b60b5(%rip), %rsi    # 0x1de635
leaq -0x4f8(%rbp), %rdi
callq 0x10a90
jmp 0x2858e
movb -0x7d9(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x4d8(%rbp), %rdi
leaq -0x4f8(%rbp), %rdx
callq 0x10f80
jmp 0x285af
leaq 0x1b422f(%rip), %rsi    # 0x1dc7e5
leaq -0x4d8(%rbp), %rdi
callq 0x34320
movq %rax, -0x7e8(%rbp)
jmp 0x285cb
movq -0x7e8(%rbp), %rdi
leaq 0x1b607a(%rip), %rsi    # 0x1de653
callq 0x36780
movq %rax, -0x7f0(%rbp)
jmp 0x285e7
movq -0x7f0(%rbp), %rdi
leaq 0x1b81b7(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x7f8(%rbp)
jmp 0x28603
movl -0x344(%rbp), %esi
movl -0x324(%rbp), %edx
movl -0x304(%rbp), %ecx
leaq -0x128(%rbp), %rdi
callq 0x35b40
movq %rax, -0x800(%rbp)
jmp 0x2862a
movq -0x800(%rbp), %rsi
movq -0x7f8(%rbp), %rdi
callq 0x343a0
movq %rax, -0x808(%rbp)
jmp 0x28646
movq -0x808(%rbp), %rdi
leaq 0x1b4191(%rip), %rsi    # 0x1dc7e5
callq 0x34320
movq %rax, -0x810(%rbp)
jmp 0x28662
movq -0x810(%rbp), %rdi
leaq 0x1b600e(%rip), %rsi    # 0x1de67e
callq 0x36600
movq %rax, -0x818(%rbp)
jmp 0x2867e
movq -0x818(%rbp), %rdi
leaq 0x1b8120(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x820(%rbp)
jmp 0x2869a
movq -0x820(%rbp), %rdi
leaq -0x348(%rbp), %rsi
callq 0x343a0
movq %rax, -0x828(%rbp)
jmp 0x286b6
movq -0x828(%rbp), %rdi
leaq 0x1cddb7(%rip), %rsi    # 0x1f647b
callq 0x34320
jmp 0x286cb
leaq -0x4d8(%rbp), %rdi
callq 0x10ff0
jmp 0x286d9
leaq -0x4f8(%rbp), %rdi
callq 0x3100
leaq -0x4f9(%rbp), %rdi
callq 0x3290
leaq -0x338(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x2849a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x288(%rbp)
movl %eax, -0x28c(%rbp)
jmp 0x28d4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x288(%rbp)
movl %eax, -0x28c(%rbp)
jmp 0x28d3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x288(%rbp)
movl %eax, -0x28c(%rbp)
jmp 0x28793
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x288(%rbp)
movl %eax, -0x28c(%rbp)
jmp 0x28787
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x288(%rbp)
movl %eax, -0x28c(%rbp)
leaq -0x4d8(%rbp), %rdi
callq 0x10ff0
jmp 0x28785
jmp 0x28787
leaq -0x4f8(%rbp), %rdi
callq 0x3100
leaq -0x4f9(%rbp), %rdi
callq 0x3290
jmp 0x28d3f
jmp 0x287a6
leaq -0x318(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x283cf
jmp 0x287c6
leaq -0x2f8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x28304
movl $0x0, -0x2c4(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x36760
movq %rax, -0x830(%rbp)
jmp 0x28803
movq -0x830(%rbp), %rax
movq %rax, -0x508(%rbp)
movq -0x508(%rbp), %rdi
callq 0x366c0
movq %rax, -0x838(%rbp)
jmp 0x28826
movq -0x838(%rbp), %rax
movq %rax, -0x510(%rbp)
movq -0x508(%rbp), %rdi
callq 0x366f0
movq %rax, -0x840(%rbp)
jmp 0x28849
movq -0x840(%rbp), %rax
movq %rax, -0x518(%rbp)
leaq -0x510(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x518(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rax
movq (%rax), %rax
movq -0xa0(%rbp), %rcx
cmpq (%rcx), %rax
setne %al
movb %al, -0x841(%rbp)
movb -0x841(%rbp), %al
testb $0x1, %al
jne 0x2889f
jmp 0x28d1e
leaq -0x510(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x850(%rbp)
movq -0x850(%rbp), %rax
movl %eax, -0x51c(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x366a0
movq %rax, -0x858(%rbp)
jmp 0x288da
movq -0x858(%rbp), %rax
movq %rax, -0x528(%rbp)
movq -0x528(%rbp), %rdi
callq 0x366c0
movq %rax, -0x860(%rbp)
jmp 0x288fd
movq -0x860(%rbp), %rax
movq %rax, -0x530(%rbp)
movq -0x528(%rbp), %rdi
callq 0x366f0
movq %rax, -0x868(%rbp)
jmp 0x28920
movq -0x868(%rbp), %rax
movq %rax, -0x538(%rbp)
leaq -0x530(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x538(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
movq (%rax), %rax
movq -0xb0(%rbp), %rcx
cmpq (%rcx), %rax
setne %al
movb %al, -0x869(%rbp)
movb -0x869(%rbp), %al
testb $0x1, %al
jne 0x28976
jmp 0x28cfe
leaq -0x530(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x878(%rbp)
movq -0x878(%rbp), %rax
movl %eax, -0x53c(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x36740
movq %rax, -0x880(%rbp)
jmp 0x289b1
movq -0x880(%rbp), %rax
movq %rax, -0x548(%rbp)
movq -0x548(%rbp), %rdi
callq 0x366c0
movq %rax, -0x888(%rbp)
jmp 0x289d4
movq -0x888(%rbp), %rax
movq %rax, -0x550(%rbp)
movq -0x548(%rbp), %rdi
callq 0x366f0
movq %rax, -0x890(%rbp)
jmp 0x289f7
movq -0x890(%rbp), %rax
movq %rax, -0x558(%rbp)
leaq -0x550(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x558(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rax
movq (%rax), %rax
movq -0xc0(%rbp), %rcx
cmpq (%rcx), %rax
setne %al
movb %al, -0x891(%rbp)
movb -0x891(%rbp), %al
testb $0x1, %al
jne 0x28a4d
jmp 0x28cde
leaq -0x550(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x8a0(%rbp)
movq -0x8a0(%rbp), %rax
movl %eax, -0x55c(%rbp)
movl -0x2c4(%rbp), %eax
movl %eax, %ecx
incl %ecx
movl %ecx, -0x2c4(%rbp)
movl %eax, -0x560(%rbp)
movl -0x51c(%rbp), %esi
movl -0x55c(%rbp), %edx
movl -0x53c(%rbp), %ecx
leaq -0x220(%rbp), %rdi
callq 0x35b40
movq %rax, -0x8a8(%rbp)
jmp 0x28ab0
movq -0x8a8(%rbp), %rax
movl (%rax), %eax
movl -0x560(%rbp), %ecx
subl %ecx, %eax
sete %al
movb %al, -0x8b1(%rbp)
leaq -0x711(%rbp), %rdi
movq %rdi, -0x8b0(%rbp)
callq 0x33b0
movq -0x8b0(%rbp), %rdx
leaq 0x1b5b7a(%rip), %rsi    # 0x1de665
leaq -0x710(%rbp), %rdi
callq 0x10a90
jmp 0x28af9
movb -0x8b1(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x6f0(%rbp), %rdi
leaq -0x710(%rbp), %rdx
callq 0x10f80
jmp 0x28b1a
leaq 0x1b3cc4(%rip), %rsi    # 0x1dc7e5
leaq -0x6f0(%rbp), %rdi
callq 0x34320
movq %rax, -0x8c0(%rbp)
jmp 0x28b36
movq -0x8c0(%rbp), %rdi
leaq 0x1b5b43(%rip), %rsi    # 0x1de687
callq 0x34ba0
movq %rax, -0x8c8(%rbp)
jmp 0x28b52
movq -0x8c8(%rbp), %rdi
leaq 0x1b7c4c(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x8d0(%rbp)
jmp 0x28b6e
movl -0x51c(%rbp), %esi
movl -0x55c(%rbp), %edx
movl -0x53c(%rbp), %ecx
leaq -0x220(%rbp), %rdi
callq 0x35b40
movq %rax, -0x8d8(%rbp)
jmp 0x28b95
movq -0x8d8(%rbp), %rsi
movq -0x8d0(%rbp), %rdi
callq 0x343a0
movq %rax, -0x8e0(%rbp)
jmp 0x28bb1
movq -0x8e0(%rbp), %rdi
leaq 0x1b3c26(%rip), %rsi    # 0x1dc7e5
callq 0x34320
movq %rax, -0x8e8(%rbp)
jmp 0x28bcd
movq -0x8e8(%rbp), %rdi
leaq 0x1b5aa3(%rip), %rsi    # 0x1de67e
callq 0x36600
movq %rax, -0x8f0(%rbp)
jmp 0x28be9
movq -0x8f0(%rbp), %rdi
leaq 0x1b7bb5(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x8f8(%rbp)
jmp 0x28c05
movq -0x8f8(%rbp), %rdi
leaq -0x560(%rbp), %rsi
callq 0x343a0
movq %rax, -0x900(%rbp)
jmp 0x28c21
movq -0x900(%rbp), %rdi
leaq 0x1cd84c(%rip), %rsi    # 0x1f647b
callq 0x34320
jmp 0x28c36
leaq -0x6f0(%rbp), %rdi
callq 0x10ff0
jmp 0x28c44
leaq -0x710(%rbp), %rdi
callq 0x3100
leaq -0x711(%rbp), %rdi
callq 0x3290
leaq -0x550(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x28a05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x288(%rbp)
movl %eax, -0x28c(%rbp)
jmp 0x28cd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x288(%rbp)
movl %eax, -0x28c(%rbp)
jmp 0x28cc4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x288(%rbp)
movl %eax, -0x28c(%rbp)
leaq -0x6f0(%rbp), %rdi
callq 0x10ff0
jmp 0x28cc2
jmp 0x28cc4
leaq -0x710(%rbp), %rdi
callq 0x3100
leaq -0x711(%rbp), %rdi
callq 0x3290
jmp 0x28d3f
jmp 0x28ce0
leaq -0x530(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x2892e
jmp 0x28d00
leaq -0x510(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x28857
leaq -0x220(%rbp), %rdi
callq 0x35160
leaq -0x128(%rbp), %rdi
callq 0x35160
addq $0x900, %rsp            # imm = 0x900
popq %rbp
retq
leaq -0x220(%rbp), %rdi
callq 0x35160
leaq -0x128(%rbp), %rdi
callq 0x35160
movq -0x288(%rbp), %rdi
callq 0x33a0
movq %rax, %rdi
callq 0x116d0
nopl (%rax,%rax)