// File: dsharlet[P]array/test/shape.cpp
// Function: nda::test_for_each_index_3d_reorderd_body()
TEST(for_each_index_3d_reorderd) {
  shape_of_rank<3> s(3, 5, {0, 8, 1});
  s.resolve();
  int expected_flat_offset = 0;
  move_only token;
  for_each_index<2, 0, 1>(s, [&, token = std::move(token)](std::tuple<int, int, int> i) {
    ASSERT_EQ(s[i], expected_flat_offset);
    expected_flat_offset++;
    assert_used(token);
  });
  // Ensure the for_each_index loop above actually ran.
  ASSERT_EQ(expected_flat_offset, 120);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2f0, %rsp            # imm = 0x2F0
leaq -0x60(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
movl $0x3, %esi
callq 0x10c20
leaq -0x78(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
movl $0x5, %esi
callq 0x10c20
xorl %eax, %eax
movl %eax, %esi
leaq -0x90(%rbp), %rdi
movq %rdi, -0x298(%rbp)
movl $0x8, %edx
movl $0x1, %ecx
callq 0x10c60
movq -0x2a8(%rbp), %rsi
movq -0x2a0(%rbp), %rdx
movq -0x298(%rbp), %rcx
leaq -0x48(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x36640
movq -0x290(%rbp), %rdi
callq 0x378e0
movq -0x290(%rbp), %rdi
movl $0x0, -0x94(%rbp)
movq %rdi, -0xa8(%rbp)
leaq -0x94(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0xb0(%rbp), %rsi
callq 0x181530
movl -0x94(%rbp), %eax
subl $0x78, %eax
sete %al
movb %al, -0x281(%rbp)
leaq -0x261(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x33b0
movq -0x280(%rbp), %rdx
leaq 0x7a507(%rip), %rsi     # 0x1fb863
leaq -0x260(%rbp), %rdi
callq 0x10a90
jmp 0x18136a
movb -0x281(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x240(%rbp), %rdi
leaq -0x260(%rbp), %rdx
callq 0x10f80
jmp 0x18138b
leaq 0x5b453(%rip), %rsi     # 0x1dc7e5
leaq -0x240(%rbp), %rdi
callq 0x34320
movq %rax, -0x2b0(%rbp)
jmp 0x1813a7
movq -0x2b0(%rbp), %rdi
leaq 0x7b860(%rip), %rsi     # 0x1fcc15
callq 0x96ac0
movq %rax, -0x2b8(%rbp)
jmp 0x1813c3
movq -0x2b8(%rbp), %rdi
leaq 0x5f3db(%rip), %rsi     # 0x1e07ac
callq 0x34320
movq %rax, -0x2c0(%rbp)
jmp 0x1813df
movq -0x2c0(%rbp), %rdi
leaq -0x94(%rbp), %rsi
callq 0x343a0
movq %rax, -0x2c8(%rbp)
jmp 0x1813fb
movq -0x2c8(%rbp), %rdi
leaq 0x5b3dc(%rip), %rsi     # 0x1dc7e5
callq 0x34320
movq %rax, -0x2d0(%rbp)
jmp 0x181417
movq -0x2d0(%rbp), %rdi
leaq 0x7a456(%rip), %rsi     # 0x1fb87b
callq 0x356d0
movq %rax, -0x2d8(%rbp)
jmp 0x181433
movq -0x2d8(%rbp), %rdi
leaq 0x5f36b(%rip), %rsi     # 0x1e07ac
callq 0x34320
movq %rax, -0x2e0(%rbp)
jmp 0x18144f
movq -0x2e0(%rbp), %rdi
movl $0x78, -0x278(%rbp)
leaq -0x278(%rbp), %rsi
callq 0x343a0
movq %rax, -0x2e8(%rbp)
jmp 0x181475
movq -0x2e8(%rbp), %rdi
leaq 0x74ff8(%rip), %rsi     # 0x1f647b
callq 0x34320
jmp 0x18148a
leaq -0x240(%rbp), %rdi
callq 0x10ff0
jmp 0x181498
leaq -0x260(%rbp), %rdi
callq 0x3100
leaq -0x261(%rbp), %rdi
callq 0x3290
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
jmp 0x18150f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
jmp 0x181503
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x10ff0
jmp 0x181501
jmp 0x181503
leaq -0x260(%rbp), %rdi
callq 0x3100
leaq -0x261(%rbp), %rdi
callq 0x3290
movq -0x270(%rbp), %rdi
callq 0x33a0
movq %rax, %rdi
callq 0x116d0
nop