// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
leaq 0x148(%rsp), %rbx
andq $0x0, (%rbx)
pushq $0x4
popq %r14
movq %r14, 0x8(%rbx)
pushq $0x10
popq %r15
movq %r15, 0x10(%rbx)
andq $0x0, 0x18(%rbx)
movq %r14, 0x20(%rbx)
movq %r14, 0x28(%rbx)
andq $0x0, 0x30(%rbx)
movq %r14, 0x38(%rbx)
pushq $0x1
popq %r12
movq %r12, 0x40(%rbx)
leaq 0xe0(%rsp), %rdi
movq %rbx, %rsi
callq 0x10b92
andq $0x0, (%rbx)
movq %r14, 0x8(%rbx)
movq %r14, 0x10(%rbx)
andq $0x0, 0x18(%rbx)
movq %r14, 0x20(%rbx)
movq %r12, 0x28(%rbx)
andq $0x0, 0x30(%rbx)
movq %r14, 0x38(%rbx)
movq %r15, 0x40(%rbx)
leaq 0x78(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x10b92
leaq 0x1c(%rsp), %rax
andl $0x0, (%rax)
movq %rax, 0x60(%rsp)
leaq 0x98(%rsp), %rsi
movq -0x8(%rsi), %r13
leaq 0x148(%rsp), %rdi
callq 0x12237
testq %r13, %r13
je 0xedf1
movq 0x188(%rsp), %rax
movq 0x170(%rsp), %rcx
movq 0x150(%rsp), %rdx
movq 0x158(%rsp), %rsi
movq 0x180(%rsp), %rdi
xorl %r8d, %r8d
testq %rdx, %rdx
cmovleq %r8, %rdx
movq %rdx, 0x40(%rsp)
movq 0x168(%rsp), %rdx
testq %rdx, %rdx
cmovleq %r8, %rdx
movq %rdx, 0x10(%rsp)
testq %rdi, %rdi
movl $0x0, %r9d
movq %rdi, 0x30(%rsp)
cmovgq %rdi, %r9
movq %r9, 0x20(%rsp)
shlq $0x2, %rsi
movq %rsi, 0x38(%rsp)
shlq $0x2, %rcx
movq %rcx, 0x28(%rsp)
movq %rax, 0x8(%rsp)
leaq (,%rax,4), %r12
leaq 0x58(%rsp), %rbx
cmpq 0x40(%rsp), %r8
je 0xee14
movq %r8, 0x48(%rsp)
movq %r13, 0x50(%rsp)
xorl %r15d, %r15d
cmpq 0x10(%rsp), %r15
je 0xedda
movq 0x20(%rsp), %rbp
movq %r13, %r14
cmpq $0x1, 0x8(%rsp)
jne 0xedba
movq 0x30(%rsp), %rax
leaq (,%rax,4), %r14
addq %r13, %r14
movq %r13, %rsi
cmpq %r14, %rsi
jae 0xedd0
leaq 0x4(%rsi), %rbp
movq %rbx, %rdi
callq 0x106ac
movq %rbp, %rsi
jmp 0xeda4
subq $0x1, %rbp
jb 0xedd0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x106ac
addq %r12, %r14
jmp 0xedba
addq 0x28(%rsp), %r13
incq %r15
jmp 0xed7a
movq 0x48(%rsp), %r8
incq %r8
movq 0x50(%rsp), %r13
addq 0x38(%rsp), %r13
jmp 0xed62
movq 0x168(%rsp), %rax
imulq 0x180(%rsp), %rax
imulq 0x150(%rsp), %rax
testq %rax, %rax
jg 0xf26f
leaq 0x100(%rsp), %rsi
movq -0x8(%rsi), %rbx
leaq 0x148(%rsp), %rdi
callq 0x12237
testq %rbx, %rbx
je 0xeeee
movq 0x188(%rsp), %rax
movq 0x170(%rsp), %rcx
movq 0x150(%rsp), %rdx
movq 0x158(%rsp), %rsi
movq 0x168(%rsp), %rdi
xorl %r8d, %r8d
testq %rdi, %rdi
cmovleq %r8, %rdi
movq 0x180(%rsp), %r9
testq %rdx, %rdx
cmovleq %r8, %rdx
testq %r9, %r9
movl $0x0, %r10d
cmovgq %r9, %r10
shlq $0x2, %rsi
shlq $0x2, %rcx
leaq (,%rax,4), %r11
xorl %r14d, %r14d
cmpq %rdx, %r14
je 0xef11
movq %rbx, %r15
xorl %r12d, %r12d
cmpq %rdi, %r12
je 0xeee6
cmpq $0x1, %rax
jne 0xeec6
leaq (%r15,%r9,4), %r13
movq %r15, %rbp
cmpq %r13, %rbp
jae 0xeede
movl %r8d, (%rbp)
incl %r8d
addq $0x4, %rbp
jmp 0xeeb4
movq %r10, %r13
movq %r15, %rbp
subq $0x1, %r13
jb 0xeede
movl %r8d, (%rbp)
incl %r8d
addq %r11, %rbp
jmp 0xeecc
addq %rcx, %r15
incq %r12
jmp 0xeea2
incq %r14
addq %rsi, %rbx
jmp 0xee97
movq 0x168(%rsp), %rax
imulq 0x180(%rsp), %rax
imulq 0x150(%rsp), %rax
testq %rax, %rax
jg 0xf286
leaq 0xe0(%rsp), %rax
movq 0x20(%rax), %rbx
movq 0x28(%rax), %rax
addq %rbx, %rax
movq %rax, 0x30(%rsp)
xorl %eax, %eax
leaq 0x58(%rsp), %r12
leaq 0x148(%rsp), %r15
cmpq 0x30(%rsp), %rbx
je 0xf0b0
movq 0x118(%rsp), %r14
movq 0x120(%rsp), %rcx
addq %r14, %rcx
movq %rcx, 0x20(%rsp)
cmpq 0x20(%rsp), %r14
je 0xf0a8
movl 0x130(%rsp), %r13d
movq 0x138(%rsp), %rbp
movq %r14, 0x8(%rsp)
subq $0x1, %rbp
jb 0xf0a0
movl %eax, 0x28(%rsp)
movl %eax, 0x4(%rsp)
leaq 0xe0(%rsp), %rdi
movl %r13d, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0x112c6
movl %r13d, 0x10(%rsp)
movl (%rax), %r13d
movl 0x4(%rsp), %r14d
movq %r12, %rdi
leaq 0x80438(%rip), %rsi     # 0x8f3f1
leaq 0x3(%rsp), %rdx
callq 0x66a0
xorl %esi, %esi
cmpl %r14d, %r13d
sete %sil
movq %r15, %rdi
movq %r12, %r14
movq %r12, %rdx
callq 0x6894
movq %r15, %rdi
leaq 0x7e663(%rip), %r12     # 0x8d647
movq %r12, %rsi
callq 0x106fe
movq %rax, %rdi
leaq 0x80419(%rip), %rsi     # 0x8f40f
callq 0x118c8
movq %rax, %rdi
leaq 0x825ed(%rip), %rsi     # 0x915f2
callq 0x106fe
movq %rax, %r13
leaq 0xe0(%rsp), %rdi
movl 0x10(%rsp), %esi
movq 0x8(%rsp), %rdx
movl %ebx, %ecx
callq 0x112c6
movq %r13, %rdi
movq %rax, %rsi
callq 0x10736
movq %rax, %rdi
movq %r12, %rsi
callq 0x106fe
movq %rax, %rdi
leaq 0x803f5(%rip), %rsi     # 0x8f43a
callq 0x118ac
movq %rax, %rdi
leaq 0x8259e(%rip), %rsi     # 0x915f2
callq 0x106fe
movq %rax, %rdi
leaq 0x4(%rsp), %rsi
callq 0x10736
movq %rax, %rdi
leaq 0x96232(%rip), %rsi     # 0xa52a2
callq 0x106fe
movq %r15, %rdi
callq 0x68d4
movq %r14, %r12
movq %r14, %rdi
callq 0x2090
movl 0x10(%rsp), %r13d
incl %r13d
movl 0x28(%rsp), %eax
incl %eax
movq 0x8(%rsp), %r14
jmp 0xef7b
incq %r14
jmp 0xef5b
incq %rbx
jmp 0xef38
andl $0x0, 0x1c(%rsp)
leaq 0x78(%rsp), %rax
movq 0x50(%rax), %r14
movq 0x58(%rax), %rax
addq %r14, %rax
movq %rax, 0x20(%rsp)
leaq 0x58(%rsp), %rbx
leaq 0x148(%rsp), %r15
cmpq 0x20(%rsp), %r14
je 0xf246
movq 0x98(%rsp), %r13
movq 0xa0(%rsp), %rax
addq %r13, %rax
movq %rax, 0x28(%rsp)
cmpq 0x28(%rsp), %r13
je 0xf23e
movl 0xb0(%rsp), %ebp
movq 0xb8(%rsp), %r12
movq %r13, 0x8(%rsp)
subq $0x1, %r12
jb 0xf236
movl 0x1c(%rsp), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x1c(%rsp)
movl %eax, 0x4(%rsp)
leaq 0x78(%rsp), %rdi
movl %r14d, %esi
movl %ebp, %edx
movl %r13d, %ecx
callq 0x112c6
movl %ebp, 0x10(%rsp)
movl (%rax), %r13d
movl 0x4(%rsp), %ebp
movq %rbx, %rdi
leaq 0x802c8(%rip), %rsi     # 0x8f421
leaq 0x3(%rsp), %rdx
callq 0x66a0
xorl %esi, %esi
cmpl %ebp, %r13d
sete %sil
movq %r15, %rdi
movq %rbx, %rbp
movq %rbx, %rdx
callq 0x6894
movq %r15, %rdi
leaq 0x7e4c3(%rip), %rbx     # 0x8d647
movq %rbx, %rsi
callq 0x106fe
movq %rax, %rdi
leaq 0x802ad(%rip), %rsi     # 0x8f443
callq 0x109ea
movq %rax, %rdi
leaq 0x8244d(%rip), %rsi     # 0x915f2
callq 0x106fe
movq %rax, %r13
leaq 0x78(%rsp), %rdi
movl %r14d, %esi
movl 0x10(%rsp), %edx
movq 0x8(%rsp), %rcx
callq 0x112c6
movq %r13, %rdi
movq %rax, %rsi
callq 0x10736
movq %rax, %rdi
movq %rbx, %rsi
callq 0x106fe
movq %rax, %rdi
leaq 0x80257(%rip), %rsi     # 0x8f43a
callq 0x118ac
movq %rax, %rdi
leaq 0x82400(%rip), %rsi     # 0x915f2
callq 0x106fe
movq %rax, %rdi
leaq 0x4(%rsp), %rsi
callq 0x10736
movq %rax, %rdi
leaq 0x96094(%rip), %rsi     # 0xa52a2
callq 0x106fe
movq %r15, %rdi
callq 0x68d4
movq %rbp, %rbx
movq %rbp, %rdi
callq 0x2090
movl 0x10(%rsp), %ebp
incl %ebp
movq 0x8(%rsp), %r13
jmp 0xf119
incq %r13
jmp 0xf0fa
incq %r14
jmp 0xf0d7
leaq 0x78(%rsp), %rdi
callq 0x10d02
leaq 0xe0(%rsp), %rdi
callq 0x10d02
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7e019(%rip), %rdi     # 0x8d28f
leaq 0x7de54(%rip), %rsi     # 0x8d0d1
leaq 0x826f1(%rip), %rcx     # 0x91975
jmp 0xf29b
leaq 0x7e002(%rip), %rdi     # 0x8d28f
leaq 0x7de3d(%rip), %rsi     # 0x8d0d1
leaq 0x82787(%rip), %rcx     # 0x91a22
movl $0x6a1, %edx            # imm = 0x6A1
callq 0x20e0
jmp 0xf2b4
jmp 0xf2b4
movq %rax, %rbx
jmp 0xf2f6
jmp 0xf2b4
jmp 0xf2b4
jmp 0xf2b4
movq %rax, %rbx
jmp 0xf2ec
jmp 0xf2bb
movq %rax, %rbx
jmp 0xf2e2
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x68d4
jmp 0xf2e2
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x68d4
leaq 0x58(%rsp), %rdi
callq 0x2090
leaq 0x78(%rsp), %rdi
callq 0x10d02
leaq 0xe0(%rsp), %rdi
callq 0x10d02
movq %rbx, %rdi
callq 0x22f0
movq %rax, %rdi
callq 0x6bba