// File: dsharlet[P]array/test/image.cpp
// Function: void nda::test_slice<nda::shape<nda::dim<-9l, -9l, 1l>, nda::dim<-9l, -9l, -9l>, nda::dim<-9l, -9l, -9l>>>(long)
void test_slice(index_t channels) {
  array<int, Shape> base({100, 80, channels});
  fill_pattern(base);

  for (index_t c = 0; c < channels; c++) {
    auto slice = slice_channel(base, c);
    ASSERT_EQ(static_cast<index_t>(slice.shape().size()), base.width() * base.height());
    for_all_indices(slice.shape(),
        [&](int x, int y) { ASSERT_EQ(slice(x, y), pattern<int>(std::make_tuple(x, y, c))); });

    auto crop_slice = slice_channel(crop(base, 5, 3, 80, 70, crop_origin::crop), c);
    ASSERT_EQ(crop_slice.shape().size(), (80 - 5) * (70 - 3));
    for_all_indices(crop_slice.shape(),
        [&](int x, int y) { ASSERT_EQ(crop_slice(x, y), pattern<int>(std::make_tuple(x, y, c))); });
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x670, %rsp            # imm = 0x670
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rcx
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x550(%rbp)
movl $0x64, %esi
movl $0x50, %edx
callq 0x10f8d0
movq -0x550(%rbp), %rsi
leaq -0x70(%rbp), %rdi
movq %rdi, -0x548(%rbp)
callq 0x10d10
movq -0x548(%rbp), %rdi
xorl %esi, %esi
callq 0x10bf20
jmp 0x10a4c7
movq $0x0, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
cmpq -0x8(%rbp), %rax
jge 0x10ab0d
movq -0xd0(%rbp), %rdx
leaq -0x108(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x10f920
jmp 0x10a4fc
leaq -0x108(%rbp), %rdi
callq 0x96a20
movq %rax, -0x558(%rbp)
jmp 0x10a511
movq -0x558(%rbp), %rdi
callq 0x3d480
movq %rax, -0x560(%rbp)
jmp 0x10a526
leaq -0x70(%rbp), %rdi
callq 0x34690
movq %rax, -0x568(%rbp)
jmp 0x10a538
leaq -0x70(%rbp), %rdi
callq 0x346b0
movq %rax, -0x570(%rbp)
jmp 0x10a54a
movq -0x560(%rbp), %rax
movq -0x570(%rbp), %rdx
movq -0x568(%rbp), %rcx
imulq %rdx, %rcx
subq %rcx, %rax
sete %al
movb %al, -0x579(%rbp)
leaq -0x2b9(%rbp), %rdi
movq %rdi, -0x578(%rbp)
callq 0x33b0
movq -0x578(%rbp), %rdx
leaq 0xe44e5(%rip), %rsi     # 0x1eea75
leaq -0x2b8(%rbp), %rdi
callq 0x10a90
jmp 0x10a59e
movb -0x579(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x298(%rbp), %rdi
leaq -0x2b8(%rbp), %rdx
callq 0x10f80
jmp 0x10a5bf
leaq 0xd221f(%rip), %rsi     # 0x1dc7e5
leaq -0x298(%rbp), %rdi
callq 0x34320
movq %rax, -0x588(%rbp)
jmp 0x10a5db
movq -0x588(%rbp), %rdi
leaq 0xe44d7(%rip), %rsi     # 0x1eeac0
callq 0x10f970
movq %rax, -0x590(%rbp)
jmp 0x10a5f7
movq -0x590(%rbp), %rdi
leaq 0xd61a7(%rip), %rsi     # 0x1e07ac
callq 0x34320
movq %rax, -0x598(%rbp)
jmp 0x10a613
leaq -0x108(%rbp), %rdi
callq 0x96a20
movq %rax, -0x5a0(%rbp)
jmp 0x10a628
movq -0x5a0(%rbp), %rdi
callq 0x3d480
movq %rax, -0x5a8(%rbp)
jmp 0x10a63d
movq -0x598(%rbp), %rdi
movq -0x5a8(%rbp), %rax
movq %rax, -0x2c8(%rbp)
leaq -0x2c8(%rbp), %rsi
callq 0x34510
movq %rax, -0x5b0(%rbp)
jmp 0x10a667
movq -0x5b0(%rbp), %rdi
leaq 0xd2170(%rip), %rsi     # 0x1dc7e5
callq 0x34320
movq %rax, -0x5b8(%rbp)
jmp 0x10a683
movq -0x5b8(%rbp), %rdi
leaq 0xe4412(%rip), %rsi     # 0x1eeaa3
callq 0x8b1f0
movq %rax, -0x5c0(%rbp)
jmp 0x10a69f
movq -0x5c0(%rbp), %rdi
leaq 0xd60ff(%rip), %rsi     # 0x1e07ac
callq 0x34320
movq %rax, -0x5c8(%rbp)
jmp 0x10a6bb
leaq -0x70(%rbp), %rdi
callq 0x34690
movq %rax, -0x5d0(%rbp)
jmp 0x10a6cd
leaq -0x70(%rbp), %rdi
callq 0x346b0
movq %rax, -0x5d8(%rbp)
jmp 0x10a6df
movq -0x5c8(%rbp), %rdi
movq -0x5d8(%rbp), %rcx
movq -0x5d0(%rbp), %rax
imulq %rcx, %rax
movq %rax, -0x2d0(%rbp)
leaq -0x2d0(%rbp), %rsi
callq 0x34510
movq %rax, -0x5e0(%rbp)
jmp 0x10a714
movq -0x5e0(%rbp), %rdi
leaq 0xebd59(%rip), %rsi     # 0x1f647b
callq 0x34320
jmp 0x10a729
leaq -0x298(%rbp), %rdi
callq 0x10ff0
jmp 0x10a737
leaq -0x2b8(%rbp), %rdi
callq 0x3100
leaq -0x2b9(%rbp), %rdi
callq 0x3290
leaq -0x108(%rbp), %rdi
callq 0x96a20
movq %rax, -0x5e8(%rbp)
jmp 0x10a764
movq -0x5e8(%rbp), %rdi
leaq -0x108(%rbp), %rax
movq %rax, -0x2e0(%rbp)
leaq -0xd0(%rbp), %rax
movq %rax, -0x2d8(%rbp)
leaq -0x2e0(%rbp), %rsi
callq 0xf4060
jmp 0x10a795
movq %rsp, %rax
movl $0x1, (%rax)
leaq -0x368(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x5, %edx
movl $0x3, %ecx
movl $0x50, %r8d
movl $0x46, %r9d
callq 0x10bf50
jmp 0x10a7c6
movq -0xd0(%rbp), %rdx
leaq -0x318(%rbp), %rdi
leaq -0x368(%rbp), %rsi
callq 0x10f9b0
jmp 0x10a7e2
leaq -0x318(%rbp), %rdi
callq 0x96a20
movq %rax, -0x5f0(%rbp)
jmp 0x10a7f7
movq -0x5f0(%rbp), %rdi
callq 0x3d480
movq %rax, -0x5f8(%rbp)
jmp 0x10a80c
movq -0x5f8(%rbp), %rax
subq $0x13a1, %rax           # imm = 0x13A1
sete %al
movb %al, -0x601(%rbp)
leaq -0x519(%rbp), %rdi
movq %rdi, -0x600(%rbp)
callq 0x33b0
movq -0x600(%rbp), %rdx
leaq 0xe42a8(%rip), %rsi     # 0x1eeaeb
leaq -0x518(%rbp), %rdi
callq 0x10a90
jmp 0x10a851
movb -0x601(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x4f8(%rbp), %rdi
leaq -0x518(%rbp), %rdx
callq 0x10f80
jmp 0x10a872
leaq 0xd1f6c(%rip), %rsi     # 0x1dc7e5
leaq -0x4f8(%rbp), %rdi
callq 0x34320
movq %rax, -0x610(%rbp)
jmp 0x10a88e
movq -0x610(%rbp), %rdi
leaq 0xe4280(%rip), %rsi     # 0x1eeb1c
callq 0x85670
movq %rax, -0x618(%rbp)
jmp 0x10a8aa
movq -0x618(%rbp), %rdi
leaq 0xd5ef4(%rip), %rsi     # 0x1e07ac
callq 0x34320
movq %rax, -0x620(%rbp)
jmp 0x10a8c6
leaq -0x318(%rbp), %rdi
callq 0x96a20
movq %rax, -0x628(%rbp)
jmp 0x10a8db
movq -0x628(%rbp), %rdi
callq 0x3d480
movq %rax, -0x630(%rbp)
jmp 0x10a8f0
movq -0x620(%rbp), %rdi
movq -0x630(%rbp), %rax
movq %rax, -0x528(%rbp)
leaq -0x528(%rbp), %rsi
callq 0x355c0
movq %rax, -0x638(%rbp)
jmp 0x10a91a
movq -0x638(%rbp), %rdi
leaq 0xd1ebd(%rip), %rsi     # 0x1dc7e5
callq 0x34320
movq %rax, -0x640(%rbp)
jmp 0x10a936
movq -0x640(%rbp), %rdi
leaq 0xe41c4(%rip), %rsi     # 0x1eeb08
callq 0x35580
movq %rax, -0x648(%rbp)
jmp 0x10a952
movq -0x648(%rbp), %rdi
leaq 0xd5e4c(%rip), %rsi     # 0x1e07ac
callq 0x34320
movq %rax, -0x650(%rbp)
jmp 0x10a96e
movq -0x650(%rbp), %rdi
movl $0x13a1, -0x52c(%rbp)   # imm = 0x13A1
leaq -0x52c(%rbp), %rsi
callq 0x343a0
movq %rax, -0x658(%rbp)
jmp 0x10a994
movq -0x658(%rbp), %rdi
leaq 0xebad9(%rip), %rsi     # 0x1f647b
callq 0x34320
jmp 0x10a9a9
leaq -0x4f8(%rbp), %rdi
callq 0x10ff0
jmp 0x10a9b7
leaq -0x518(%rbp), %rdi
callq 0x3100
leaq -0x519(%rbp), %rdi
callq 0x3290
leaq -0x318(%rbp), %rdi
callq 0x96a20
movq %rax, -0x660(%rbp)
jmp 0x10a9e4
movq -0x660(%rbp), %rdi
leaq -0x318(%rbp), %rax
movq %rax, -0x540(%rbp)
leaq -0xd0(%rbp), %rax
movq %rax, -0x538(%rbp)
leaq -0x540(%rbp), %rsi
callq 0xf40a0
jmp 0x10aa15
jmp 0x10aa17
movq -0xd0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd0(%rbp)
jmp 0x10a4d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x10ab1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x10aa9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x10aa8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x10ff0
jmp 0x10aa8d
jmp 0x10aa8f
leaq -0x2b8(%rbp), %rdi
callq 0x3100
leaq -0x2b9(%rbp), %rdi
callq 0x3290
jmp 0x10ab1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x10aaff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x10aaf3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x4f8(%rbp), %rdi
callq 0x10ff0
jmp 0x10aaf1
jmp 0x10aaf3
leaq -0x518(%rbp), %rdi
callq 0x3100
leaq -0x519(%rbp), %rdi
callq 0x3290
jmp 0x10ab1f
leaq -0x70(%rbp), %rdi
callq 0x11110
addq $0x670, %rsp            # imm = 0x670
popq %rbp
retq
leaq -0x70(%rbp), %rdi
callq 0x11110
movq -0xc0(%rbp), %rdi
callq 0x33a0
movq %rax, %rdi
callq 0x116d0
nopl (%rax)