// File: /workspace/github_cpp_makefile_star2_O2/dsharlet[P]array/test/array.cpp
// Function: nda::test_sparse_array_body()
TEST(sparse_array) {
  auto sparse_shape = make_shape(dim<>(-2, 5, 2), dim<>(4, 10));
  sparse_shape.resolve();
  ASSERT_LT(sparse_shape.size(), sparse_shape.flat_extent());

  array<int, shape<dim<>, dim<>>> sparse(sparse_shape);
  // Fill the storage with a constant.
  for (size_t i = 0; i < sparse_shape.flat_extent(); i++) {
    sparse.data()[i] = 7;
  }
  // Assign a different constant.
  sparse.assign(sparse_shape, 3);

  // Check that we assigned all of the elements of the array.
  for (int y = 4; y < 14; y++) {
    for (int x = -2; x < 3; x++) {
      ASSERT_EQ(sparse(x, y), 3);
    }
  }

  // Check that only the elements of the array were assigned.
  size_t sevens = 0;
  for (size_t i = 0; i < sparse_shape.flat_extent(); i++) {
    if (sparse.data()[i] == 7) { sevens++; }
  }
  ASSERT_EQ(sevens + sparse.size(), sparse_shape.flat_extent());
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
leaq 0x20(%rsp), %rbx
movq $0x4, (%rbx)
movq $0xa, 0x8(%rbx)
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
movq %rax, 0x10(%rbx)
movq $-0x2, 0x18(%rbx)
movq $0x5, 0x20(%rbx)
movq $0x2, 0x28(%rbx)
movq %rbx, %rdi
callq 0x8e70
movq 0x8(%rbx), %r14
movq 0x20(%rbx), %r15
movq %rbx, %rdi
callq 0x8e44
movq %rax, %rbx
leaq 0x8201f(%rip), %rsi     # 0x8f183
leaq 0x70(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x66a0
imulq %r15, %r14
xorl %eax, %eax
testq %r14, %r14
cmovgq %r14, %rax
xorl %esi, %esi
cmpq %rbx, %rax
setb %sil
leaq 0xc0(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x6894
leaq 0x804a5(%rip), %rsi     # 0x8d647
leaq 0xc0(%rsp), %rdi
callq 0x106fe
leaq 0x81ffe(%rip), %rsi     # 0x8f1b4
movq %rax, %rdi
callq 0x11036
leaq 0x8442d(%rip), %rsi     # 0x915f2
movq %rax, %rdi
callq 0x106fe
movq 0x28(%rsp), %rcx
imulq 0x40(%rsp), %rcx
xorl %edx, %edx
testq %rcx, %rcx
cmovgq %rcx, %rdx
leaq 0x50(%rsp), %rsi
movq %rdx, (%rsi)
movq %rax, %rdi
callq 0x11052
leaq 0x8044f(%rip), %rsi     # 0x8d647
movq %rax, %rdi
callq 0x106fe
leaq 0x81f92(%rip), %rsi     # 0x8f199
movq %rax, %rdi
callq 0x11070
leaq 0x843dc(%rip), %rsi     # 0x915f2
movq %rax, %rdi
callq 0x106fe
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x8e44
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movq %rbx, %rdi
callq 0x11052
leaq 0x98060(%rip), %rsi     # 0xa52a2
movq %rax, %rdi
callq 0x106fe
leaq 0xc0(%rsp), %rdi
callq 0x68d4
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
callq 0x2090
leaq 0x70(%rsp), %rdi
leaq 0x20(%rsp), %r14
movq %r14, %rsi
callq 0x69d2
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x8e44
cmpq %rax, %r15
jae 0xd29b
movq %rbx, %rdi
callq 0x1123a
movl $0x7, (%rax,%r15,4)
incq %r15
jmp 0xd279
movups 0x20(%rsp), %xmm0
movups 0x30(%rsp), %xmm1
movups 0x40(%rsp), %xmm2
leaq 0x250(%rsp), %rsi
movaps %xmm2, 0x20(%rsi)
movaps %xmm1, 0x10(%rsi)
movaps %xmm0, (%rsi)
leaq 0xc0(%rsp), %rdx
movl $0x3, (%rdx)
leaq 0x70(%rsp), %rdi
callq 0x1108c
pushq $0x4
popq %rbx
leaq 0x50(%rsp), %r12
leaq 0xc0(%rsp), %rbp
leaq 0x84306(%rip), %r13     # 0x915f2
cmpl $0xe, %ebx
je 0xd3f0
pushq $-0x2
popq %r14
cmpl $0x3, %r14d
je 0xd3e9
leaq 0x70(%rsp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x108b2
movl (%rax), %r15d
movq %r12, %rdi
leaq 0x81f38(%rip), %rsi     # 0x8f257
leaq 0x18(%rsp), %rdx
callq 0x66a0
xorl %esi, %esi
cmpl $0x3, %r15d
sete %sil
movq %rbp, %rdi
movq %r12, %rdx
callq 0x6894
movq %rbp, %rdi
leaq 0x802ff(%rip), %rsi     # 0x8d647
callq 0x106fe
movq %rax, %rdi
leaq 0x81c35(%rip), %rsi     # 0x8ef8c
callq 0x1082e
movq %rax, %rdi
movq %r13, %rsi
callq 0x106fe
movq %rax, %r15
leaq 0x70(%rsp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x108b2
movq %r15, %rdi
movq %rax, %rsi
callq 0x10736
movq %rax, %rdi
leaq 0x802b9(%rip), %rsi     # 0x8d647
callq 0x106fe
movq %rax, %rdi
leaq 0x8ab4c(%rip), %rsi     # 0x97ee9
callq 0x106fe
movq %rax, %rdi
movq %r13, %rsi
callq 0x106fe
movl $0x3, 0x10(%rsp)
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x10736
movq %rax, %rdi
leaq 0x97ed6(%rip), %rsi     # 0xa52a2
callq 0x106fe
movq %rbp, %rdi
callq 0x68d4
movq %r12, %rdi
callq 0x2090
incl %r14d
jmp 0xd2f9
incl %ebx
jmp 0xd2ec
xorl %r15d, %r15d
leaq 0x20(%rsp), %rbx
leaq 0x70(%rsp), %r14
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0x8e44
cmpq %rax, %r12
jae 0xd427
movq %r14, %rdi
callq 0x1123a
xorl %ecx, %ecx
cmpl $0x7, (%rax,%r12,4)
sete %cl
addq %rcx, %r15
incq %r12
jmp 0xd400
movq 0x98(%rsp), %rax
imulq 0xb0(%rsp), %rax
xorl %r14d, %r14d
testq %rax, %rax
cmovgq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x8e44
movq %rax, %rbx
leaq 0x81e13(%rip), %rsi     # 0x8f269
leaq 0x50(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x66a0
addq %r15, %r14
xorl %esi, %esi
cmpq %rbx, %r14
sete %sil
leaq 0xc0(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x6894
leaq 0x801bd(%rip), %rsi     # 0x8d647
leaq 0xc0(%rsp), %rdi
callq 0x106fe
leaq 0x81e00(%rip), %rsi     # 0x8f29e
movq %rax, %rdi
callq 0x11256
leaq 0x84145(%rip), %rsi     # 0x915f2
movq %rax, %rdi
callq 0x106fe
movq 0x98(%rsp), %rcx
imulq 0xb0(%rsp), %rcx
xorl %edx, %edx
testq %rcx, %rcx
cmovgq %rcx, %rdx
addq %r15, %rdx
leaq 0x10(%rsp), %rsi
movq %rdx, (%rsi)
movq %rax, %rdi
callq 0x11052
leaq 0x8015e(%rip), %rsi     # 0x8d647
movq %rax, %rdi
callq 0x106fe
leaq 0x81ca1(%rip), %rsi     # 0x8f199
movq %rax, %rdi
callq 0x11070
leaq 0x840eb(%rip), %rsi     # 0x915f2
movq %rax, %rdi
callq 0x106fe
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x8e44
leaq 0x18(%rsp), %rsi
movq %rax, (%rsi)
movq %rbx, %rdi
callq 0x11052
leaq 0x97d6f(%rip), %rsi     # 0xa52a2
movq %rax, %rdi
callq 0x106fe
leaq 0xc0(%rsp), %rdi
callq 0x68d4
leaq 0x50(%rsp), %rdi
callq 0x2090
leaq 0x70(%rsp), %rdi
callq 0x6aca
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xd5bc
jmp 0xd5bc
jmp 0xd5bc
movq %rax, %rbx
jmp 0xd5ec
jmp 0xd5c3
movq %rax, %rbx
jmp 0xd5aa
jmp 0xd588
jmp 0xd588
jmp 0xd59a
jmp 0xd59a
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x68d4
jmp 0xd5d8
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x68d4
leaq 0x70(%rsp), %rdi
callq 0x2090
jmp 0xd5ec
jmp 0xd5bc
jmp 0xd5bc
jmp 0xd5bc
movq %rax, %rbx
jmp 0xd5e2
jmp 0xd5c8
movq %rax, %rbx
jmp 0xd5d8
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x68d4
leaq 0x50(%rsp), %rdi
callq 0x2090
leaq 0x70(%rsp), %rdi
callq 0x6aca
movq %rbx, %rdi
callq 0x22f0
movq %rax, %rdi
callq 0x6bba