// File: dsharlet[P]array/include/array/z_order.h
// Function: void nda::internal::for_each_index_in_z_order_impl<1ul, void nda::for_all_indices_in_z_order<std::tuple<long>, nda::test_for_each_in_z_order_1d_body()::$_0>(std::tuple<long> const&, nda::test_for_each_in_z_order_1d_body()::$_0 const&)::'lambda'(std::tuple<long> const&)>(std::array<long, 1ul> const&, std::array<long, 1ul>, long, long, nda::test_for_each_in_z_order_1d_body()::$_0 const&)
NDARRAY_UNIQUE void for_each_index_in_z_order_impl(const std::array<index_t, Rank>& end,
    std::array<index_t, Rank> z, index_t dim, index_t step, const Fn& fn) {
  if (dim == 0 && step == 1) {
    // We're at the innermost step of the traversal, call fn for the two neighboring points we have.
    fn(z);
    z[0] += 1;
    if (z[0] < end[0]) {
      fn(z);
    }
  } else if (dim == 0) {
    // We're on the innermost dimension, but not the innermost step.
    // Move to the next step for the outermost dimension.
    for_each_index_in_z_order_impl(end, z, Rank - 1, step >> 1, fn);
    z[0] += step;
    if (z[0] < end[0]) {
      for_each_index_in_z_order_impl(end, z, Rank - 1, step >> 1, fn);
    }
  } else {
    // Move to the next dimension for the same step.
    for_each_index_in_z_order_impl(end, z, dim - 1, step, fn);
    z[dim] += step;
    if (z[dim] < end[dim]) {
      for_each_index_in_z_order_impl(end, z, dim - 1, step, fn);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rsi, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1d439d
cmpq $0x1, -0x20(%rbp)
jne 0x1d439d
movq -0x28(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0x1d44f0
leaq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1d7bf0
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
leaq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1d7bf0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1d7c20
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq (%rcx), %rax
jge 0x1d4398
movq -0x28(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0x1d44f0
jmp 0x1d44db
cmpq $0x0, -0x18(%rbp)
jne 0x1d4441
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rcx
sarq %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x1d4310
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1d7bf0
movq -0x60(%rbp), %rcx
addq (%rax), %rcx
movq %rcx, (%rax)
leaq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1d7bf0
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1d7c20
movq %rax, %rcx
movq -0x58(%rbp), %rax
cmpq (%rcx), %rax
jge 0x1d443c
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rcx
sarq %rcx
movq -0x28(%rbp), %r8
movq -0x38(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x1d4310
jmp 0x1d44d9
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdx
subq $0x1, %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x40(%rbp), %rsi
callq 0x1d4310
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x8(%rbp), %rdi
callq 0x1d7bf0
movq -0x70(%rbp), %rcx
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rsi
leaq -0x8(%rbp), %rdi
callq 0x1d7bf0
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1d7c20
movq %rax, %rcx
movq -0x68(%rbp), %rax
cmpq (%rcx), %rax
jge 0x1d44d7
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdx
subq $0x1, %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x48(%rbp), %rsi
callq 0x1d4310
jmp 0x1d44d9
jmp 0x1d44db
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)