// File: 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
movq %rsp, %rbp
subq $0x820, %rsp            # imm = 0x820
leaq -0x48(%rbp), %rdi
movq $-0x2, %rsi
movl $0x5, %edx
movl $0x2, %ecx
callq 0x10c60
leaq -0x60(%rbp), %rdi
movl $0x4, %esi
movl $0xa, %edx
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
callq 0x10c60
movq -0x50(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x28(%rax)
movups -0x60(%rbp), %xmm0
movups %xmm0, 0x18(%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x10(%rax)
movups -0x48(%rbp), %xmm0
movups %xmm0, (%rax)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x680(%rbp)
callq 0x35550
movq -0x680(%rbp), %rdi
callq 0x1a1a0
movq -0x680(%rbp), %rdi
callq 0x1a900
movq -0x680(%rbp), %rdi
movq %rax, -0x678(%rbp)
callq 0x1a1c0
movq %rax, %rcx
movq -0x678(%rbp), %rax
subq %rcx, %rax
setb %al
movb %al, -0x669(%rbp)
leaq -0x211(%rbp), %rdi
movq %rdi, -0x668(%rbp)
callq 0x33b0
movq -0x668(%rbp), %rdx
leaq 0x1b93a1(%rip), %rsi    # 0x1de3c7
leaq -0x210(%rbp), %rdi
callq 0x10a90
jmp 0x25034
movb -0x669(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x1f0(%rbp), %rdi
leaq -0x210(%rbp), %rdx
callq 0x10f80
jmp 0x25055
leaq 0x1b7789(%rip), %rsi    # 0x1dc7e5
leaq -0x1f0(%rbp), %rdi
callq 0x34320
movq %rax, -0x688(%rbp)
jmp 0x25071
movq -0x688(%rbp), %rdi
leaq 0x1b9379(%rip), %rsi    # 0x1de3f8
callq 0x35580
movq %rax, -0x690(%rbp)
jmp 0x2508d
movq -0x690(%rbp), %rdi
leaq 0x1bb711(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x698(%rbp)
jmp 0x250a9
leaq -0x30(%rbp), %rdi
callq 0x1a900
movq %rax, -0x6a0(%rbp)
jmp 0x250bb
movq -0x698(%rbp), %rdi
movq -0x6a0(%rbp), %rax
movq %rax, -0x230(%rbp)
leaq -0x230(%rbp), %rsi
callq 0x355c0
movq %rax, -0x6a8(%rbp)
jmp 0x250e5
movq -0x6a8(%rbp), %rdi
leaq 0x1b76f2(%rip), %rsi    # 0x1dc7e5
callq 0x34320
movq %rax, -0x6b0(%rbp)
jmp 0x25101
movq -0x6b0(%rbp), %rdi
leaq 0x1b92ce(%rip), %rsi    # 0x1de3dd
callq 0x35600
movq %rax, -0x6b8(%rbp)
jmp 0x2511d
movq -0x6b8(%rbp), %rdi
leaq 0x1bb681(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x6c0(%rbp)
jmp 0x25139
leaq -0x30(%rbp), %rdi
callq 0x1a1c0
movq %rax, -0x6c8(%rbp)
jmp 0x2514b
movq -0x6c0(%rbp), %rdi
movq -0x6c8(%rbp), %rax
movq %rax, -0x238(%rbp)
leaq -0x238(%rbp), %rsi
callq 0x355c0
movq %rax, -0x6d0(%rbp)
jmp 0x25175
movq -0x6d0(%rbp), %rdi
leaq 0x1d12f8(%rip), %rsi    # 0x1f647b
callq 0x34320
jmp 0x2518a
leaq -0x1f0(%rbp), %rdi
callq 0x10ff0
jmp 0x25198
leaq -0x210(%rbp), %rdi
callq 0x3100
leaq -0x211(%rbp), %rdi
callq 0x3290
leaq -0x288(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x11190
movq $0x0, -0x290(%rbp)
movq -0x290(%rbp), %rax
movq %rax, -0x6e0(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x1a1c0
movq %rax, -0x6d8(%rbp)
jmp 0x251eb
movq -0x6e0(%rbp), %rax
movq -0x6d8(%rbp), %rcx
cmpq %rcx, %rax
jae 0x252be
leaq -0x288(%rbp), %rdi
callq 0x35a00
movq %rax, -0x6e8(%rbp)
jmp 0x25217
movq -0x6e8(%rbp), %rax
movq -0x290(%rbp), %rcx
movl $0x7, (%rax,%rcx,4)
movq -0x290(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x290(%rbp)
jmp 0x251cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x25296
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x2528a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x10ff0
jmp 0x25288
jmp 0x2528a
leaq -0x210(%rbp), %rdi
callq 0x3100
leaq -0x211(%rbp), %rdi
callq 0x3290
jmp 0x258dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x258d1
movups -0x30(%rbp), %xmm0
movups -0x20(%rbp), %xmm1
movups -0x10(%rbp), %xmm2
movaps %xmm2, -0x2a0(%rbp)
movaps %xmm1, -0x2b0(%rbp)
movaps %xmm0, -0x2c0(%rbp)
movl $0x3, -0x2c4(%rbp)
leaq -0x288(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
leaq -0x2c4(%rbp), %rdx
callq 0x35640
jmp 0x25305
movl $0x4, -0x2c8(%rbp)
cmpl $0xe, -0x2c8(%rbp)
jge 0x25590
movl $0xfffffffe, -0x2cc(%rbp) # imm = 0xFFFFFFFE
cmpl $0x3, -0x2cc(%rbp)
jge 0x2557a
movl -0x2cc(%rbp), %esi
movl -0x2c8(%rbp), %edx
leaq -0x288(%rbp), %rdi
callq 0x34880
movq %rax, -0x6f0(%rbp)
jmp 0x25354
movq -0x6f0(%rbp), %rax
movl (%rax), %eax
subl $0x3, %eax
sete %al
movb %al, -0x6f9(%rbp)
leaq -0x481(%rbp), %rdi
movq %rdi, -0x6f8(%rbp)
callq 0x33b0
movq -0x6f8(%rbp), %rdx
leaq 0x1b9111(%rip), %rsi    # 0x1de49b
leaq -0x480(%rbp), %rdi
callq 0x10a90
jmp 0x25398
movb -0x6f9(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x460(%rbp), %rdi
leaq -0x480(%rbp), %rdx
callq 0x10f80
jmp 0x253b9
leaq 0x1b7425(%rip), %rsi    # 0x1dc7e5
leaq -0x460(%rbp), %rdi
callq 0x34320
movq %rax, -0x708(%rbp)
jmp 0x253d5
movq -0x708(%rbp), %rdi
leaq 0x1b8ded(%rip), %rsi    # 0x1de1d0
callq 0x346f0
movq %rax, -0x710(%rbp)
jmp 0x253f1
movq -0x710(%rbp), %rdi
leaq 0x1bb3ad(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x718(%rbp)
jmp 0x2540d
movl -0x2cc(%rbp), %esi
movl -0x2c8(%rbp), %edx
leaq -0x288(%rbp), %rdi
callq 0x34880
movq %rax, -0x720(%rbp)
jmp 0x2542e
movq -0x720(%rbp), %rsi
movq -0x718(%rbp), %rdi
callq 0x343a0
movq %rax, -0x728(%rbp)
jmp 0x2544a
movq -0x728(%rbp), %rdi
leaq 0x1b738d(%rip), %rsi    # 0x1dc7e5
callq 0x34320
movq %rax, -0x730(%rbp)
jmp 0x25466
movq -0x730(%rbp), %rdi
leaq 0x1c1de6(%rip), %rsi    # 0x1e725a
callq 0x34320
movq %rax, -0x738(%rbp)
jmp 0x25482
movq -0x738(%rbp), %rdi
leaq 0x1bb31c(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x740(%rbp)
jmp 0x2549e
movq -0x740(%rbp), %rdi
movl $0x3, -0x488(%rbp)
leaq -0x488(%rbp), %rsi
callq 0x343a0
movq %rax, -0x748(%rbp)
jmp 0x254c4
movq -0x748(%rbp), %rdi
leaq 0x1d0fa9(%rip), %rsi    # 0x1f647b
callq 0x34320
jmp 0x254d9
leaq -0x460(%rbp), %rdi
callq 0x10ff0
jmp 0x254e7
leaq -0x480(%rbp), %rdi
callq 0x3100
leaq -0x481(%rbp), %rdi
callq 0x3290
movl -0x2cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2cc(%rbp)
jmp 0x25326
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x25569
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x2555d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x460(%rbp), %rdi
callq 0x10ff0
jmp 0x2555b
jmp 0x2555d
leaq -0x480(%rbp), %rdi
callq 0x3100
leaq -0x481(%rbp), %rdi
callq 0x3290
jmp 0x258d1
jmp 0x2557c
movl -0x2c8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c8(%rbp)
jmp 0x2530f
movq $0x0, -0x490(%rbp)
movq $0x0, -0x498(%rbp)
movq -0x498(%rbp), %rax
movq %rax, -0x758(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x1a1c0
movq %rax, -0x750(%rbp)
jmp 0x255c6
movq -0x758(%rbp), %rax
movq -0x750(%rbp), %rcx
cmpq %rcx, %rax
jae 0x2562d
leaq -0x288(%rbp), %rdi
callq 0x35a00
movq %rax, -0x760(%rbp)
jmp 0x255ee
movq -0x760(%rbp), %rax
movq -0x498(%rbp), %rcx
cmpl $0x7, (%rax,%rcx,4)
jne 0x25614
movq -0x490(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x490(%rbp)
jmp 0x25616
movq -0x498(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x498(%rbp)
jmp 0x255a6
movq -0x490(%rbp), %rax
movq %rax, -0x770(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x35a40
movq %rax, -0x768(%rbp)
jmp 0x25650
movq -0x768(%rbp), %rcx
movq -0x770(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x780(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x1a1c0
movq %rax, -0x778(%rbp)
jmp 0x2567a
movq -0x778(%rbp), %rcx
movq -0x780(%rbp), %rax
subq %rcx, %rax
sete %al
movb %al, -0x789(%rbp)
leaq -0x649(%rbp), %rdi
movq %rdi, -0x788(%rbp)
callq 0x33b0
movq -0x788(%rbp), %rdx
leaq 0x1b8df8(%rip), %rsi    # 0x1de4ad
leaq -0x648(%rbp), %rdi
callq 0x10a90
jmp 0x256c3
movb -0x789(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x628(%rbp), %rdi
leaq -0x648(%rbp), %rdx
callq 0x10f80
jmp 0x256e4
leaq 0x1b70fa(%rip), %rsi    # 0x1dc7e5
leaq -0x628(%rbp), %rdi
callq 0x34320
movq %rax, -0x798(%rbp)
jmp 0x25700
movq -0x798(%rbp), %rdi
leaq 0x1b8dd4(%rip), %rsi    # 0x1de4e2
callq 0x35a60
movq %rax, -0x7a0(%rbp)
jmp 0x2571c
movq -0x7a0(%rbp), %rdi
leaq 0x1bb082(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x7a8(%rbp)
jmp 0x25738
movq -0x490(%rbp), %rax
movq %rax, -0x7b8(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x35a40
movq %rax, -0x7b0(%rbp)
jmp 0x2575b
movq -0x7a8(%rbp), %rdi
movq -0x7b0(%rbp), %rcx
movq -0x7b8(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x658(%rbp)
leaq -0x658(%rbp), %rsi
callq 0x355c0
movq %rax, -0x7c0(%rbp)
jmp 0x2578f
movq -0x7c0(%rbp), %rdi
leaq 0x1b7048(%rip), %rsi    # 0x1dc7e5
callq 0x34320
movq %rax, -0x7c8(%rbp)
jmp 0x257ab
movq -0x7c8(%rbp), %rdi
leaq 0x1b8c24(%rip), %rsi    # 0x1de3dd
callq 0x35600
movq %rax, -0x7d0(%rbp)
jmp 0x257c7
movq -0x7d0(%rbp), %rdi
leaq 0x1bafd7(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x7d8(%rbp)
jmp 0x257e3
leaq -0x30(%rbp), %rdi
callq 0x1a1c0
movq %rax, -0x7e0(%rbp)
jmp 0x257f5
movq -0x7d8(%rbp), %rdi
movq -0x7e0(%rbp), %rax
movq %rax, -0x660(%rbp)
leaq -0x660(%rbp), %rsi
callq 0x355c0
movq %rax, -0x7e8(%rbp)
jmp 0x2581f
movq -0x7e8(%rbp), %rdi
leaq 0x1d0c4e(%rip), %rsi    # 0x1f647b
callq 0x34320
jmp 0x25834
leaq -0x628(%rbp), %rdi
callq 0x10ff0
jmp 0x25842
leaq -0x648(%rbp), %rdi
callq 0x3100
leaq -0x649(%rbp), %rdi
callq 0x3290
leaq -0x288(%rbp), %rdi
callq 0x114a0
addq $0x820, %rsp            # imm = 0x820
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x258c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x258b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x628(%rbp), %rdi
callq 0x10ff0
jmp 0x258b7
jmp 0x258b9
leaq -0x648(%rbp), %rdi
callq 0x3100
leaq -0x649(%rbp), %rdi
callq 0x3290
leaq -0x288(%rbp), %rdi
callq 0x114a0
movq -0x220(%rbp), %rdi
callq 0x33a0
movq %rax, %rdi
callq 0x116d0
nopw %cs:(%rax,%rax)