// File: /workspace/github_cpp_makefile_star2_O3/dsharlet[P]array/include/array/z_order.h
// Function: void nda::internal::for_each_index_in_z_order_impl<2ul, void nda::internal::for_each_in_z_order_impl<nda::internal::split_result<3l>, nda::internal::split_result<-9l>, void nda::for_all_in_z_order<nda::test_split_z_order_2d_body()::$_0, nda::internal::split_result<3l>, nda::internal::split_result<-9l>>(std::tuple<nda::internal::split_result<3l>, nda::internal::split_result<-9l>> const&, nda::test_split_z_order_2d_body()::$_0 const&)::'lambda'(nda::test_split_z_order_2d_body()::$_0 const&), 0ul, 1ul>(std::tuple<nda::internal::split_result<3l>, nda::internal::split_result<-9l>> const&, void nda::for_all_in_z_order<nda::test_split_z_order_2d_body()::$_0, nda::internal::split_result<3l>, nda::internal::split_result<-9l>>(std::tuple<nda::internal::split_result<3l>, nda::internal::split_result<-9l>> const&, nda::test_split_z_order_2d_body()::$_0 const&)::'lambda'(nda::test_split_z_order_2d_body()::$_0 const&) const&, std::integer_sequence<unsigned long, 0ul, 1ul>)::'lambda'(std::array<long, 2ul> const&)>(std::array<long, 2ul> const&, std::array<long, 2ul>, long, long, void nda::for_all_in_z_order<nda::test_split_z_order_2d_body()::$_0, nda::internal::split_result<3l>, nda::internal::split_result<-9l>>(std::tuple<nda::internal::split_result<3l>, nda::internal::split_result<-9l>> const&, nda::test_split_z_order_2d_body()::$_0 const&)::'lambda'(nda::test_split_z_order_2d_body()::$_0 const&) 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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, %r14
movq %r8, %r13
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
testq %rcx, %rcx
sete %al
cmpq $0x1, %r13
setne %cl
movl %eax, %edx
notb %dl
orb %cl, %dl
testb $0x1, %dl
je 0xa1946
testb $0x1, %al
jne 0xa1914
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
movq %r13, %r8
movq %r14, %r9
callq 0xa18b1
addq %r13, %rbx
movb $0x1, %al
cmpq 0x8(%r12), %rbx
jl 0xa18d7
jmp 0xa1ba8
movq %r13, %rbp
sarq %rbp
movl $0x1, %ecx
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %rbp, %r8
movq %r14, %r9
callq 0xa18b1
addq %r13, %r15
xorl %eax, %eax
movq %rbp, %r13
cmpq (%r12), %r15
jl 0xa18d7
jmp 0xa1ba8
movq (%r14), %rbp
movq 0x8(%r14), %rax
movq 0x40(%rax), %rcx
leaq 0x30(%rsp), %r13
movq %rcx, 0x10(%r13)
movups 0x30(%rax), %xmm0
movaps %xmm0, (%r13)
movq %r13, %rdi
movq %r15, %rsi
callq 0xa2154
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%r14), %rax
movq 0x10(%rax), %rcx
movq %rcx, 0x70(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x60(%rsp)
movq %rcx, 0x10(%r13)
movaps %xmm0, (%r13)
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0xa21aa
movq (%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
movq (%rbp), %rax
movq %rax, 0x10(%rsp)
movq (%rax), %rbp
movq 0x18(%rbp), %r13
movq 0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %rax
leaq 0x30(%rsp), %rcx
movq %rax, (%rcx)
movq $0x3, 0x8(%rcx)
movq $0x1, 0x10(%rcx)
leaq 0x30(%rsp), %rsi
xorl %edi, %edi
callq 0xa203e
movq 0x8(%rsp), %rdx
movq %rdx, %rax
subq 0x38(%rbp), %rax
movq 0x18(%rsp), %rsi
movq %rsi, %rcx
subq 0x20(%rbp), %rcx
imulq 0x30(%rbp), %rcx
testq %r13, %r13
leaq (%r13,%rax,4), %rax
leaq (%rax,%rcx,4), %rax
cmoveq %r13, %rax
leaq 0x30(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x38(%rsp), %rdi
movq %rsi, (%rdi)
movq 0x28(%rsp), %rax
movq %rax, 0x8(%rdi)
movq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rdi)
movq %rdx, 0x18(%rdi)
leaq (%rax,%rax,2), %rax
testq %rax, %rax
movl $0x0, %edx
cmovgq %rax, %rdx
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
addq %rdx, (%rax)
leaq 0x4(%rsp), %rax
movl $0x0, (%rax)
leaq 0x78(%rsp), %rsi
movq %rax, (%rsi)
movq %rcx, 0x8(%rsi)
callq 0xa20d6
incq %r15
cmpq (%r12), %r15
jge 0xa1ba8
movq (%r14), %rbp
movq 0x8(%r14), %rax
movq 0x40(%rax), %rcx
leaq 0x30(%rsp), %r12
movq %rcx, 0x10(%r12)
movups 0x30(%rax), %xmm0
movaps %xmm0, (%r12)
movq %r12, %rdi
movq %r15, %rsi
callq 0xa2154
movq (%rax), %r15
movq 0x8(%r14), %rax
movq 0x10(%rax), %rcx
movq %rcx, 0x70(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x60(%rsp)
movq %rcx, 0x10(%r12)
movaps %xmm0, (%r12)
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa21aa
movq (%rax), %rbx
movq 0x8(%rax), %r13
movq (%rbp), %rax
movq %rax, 0x8(%rsp)
movq (%rax), %rbp
movq 0x18(%rbp), %r12
movq 0x30(%rbp), %rax
movq %rax, 0x10(%rsp)
movq %r15, (%r14)
movq $0x3, 0x8(%r14)
movq $0x1, 0x10(%r14)
xorl %r14d, %r14d
leaq 0x30(%rsp), %rsi
xorl %edi, %edi
callq 0xa203e
movq %r15, %rax
subq 0x38(%rbp), %rax
movq %rbx, %rcx
subq 0x20(%rbp), %rcx
imulq 0x30(%rbp), %rcx
testq %r12, %r12
leaq (%r12,%rax,4), %rax
leaq (%rax,%rcx,4), %rax
cmoveq %r12, %rax
leaq 0x30(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x38(%rsp), %rdi
movq %rbx, (%rdi)
movq %r13, 0x8(%rdi)
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rdi)
movq %r15, 0x18(%rdi)
leaq (,%r13,2), %rax
addq %r13, %rax
testq %rax, %rax
cmovgq %rax, %r14
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
addq %r14, (%rax)
movl $0x0, 0x4(%rsp)
leaq 0x78(%rsp), %rsi
leaq 0x4(%rsp), %rax
movq %rax, (%rsi)
movq %rcx, 0x8(%rsi)
callq 0xa20d6
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq