// File: dsharlet[P]array/test/ein_reduce.cpp
// Function: nda::test_ein_reduce_max_2d_body()
TEST(ein_reduce_max_2d) {
  array_of_rank<int, 3> T({4, 5, 8});
  fill_pattern(T);

  dense_array<int, 1> max_ik(dense_shape<1>{T.j().extent()}, std::numeric_limits<int>::min());

  // Reduce T along the i and k dimensions, using max as the reduction.
  auto r = ein<j>(max_ik);
  ein_reduce(r = max(r, ein<i, j, k>(T)));

  for (index_t j : T.i()) {
    int max_ik_ref = std::numeric_limits<int>::min();
    T(_, j, _).for_each_value([&](int i) { max_ik_ref = std::max(i, max_ik_ref); });
    ASSERT_EQ(max_ik(j), max_ik_ref);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x610, %rsp            # imm = 0x610
leaq -0x148(%rbp), %rdi
movq %rdi, -0x578(%rbp)
movl $0x4, %esi
movl $0x5, %edx
movl $0x8, %ecx
callq 0x34ec0
movq -0x578(%rbp), %rsi
leaq -0x100(%rbp), %rdi
movq %rdi, -0x570(%rbp)
callq 0x34f10
movq -0x570(%rbp), %rdi
xorl %esi, %esi
callq 0x34fb0
jmp 0xb3837
leaq -0x100(%rbp), %rdi
callq 0xc8650
movq %rax, -0x580(%rbp)
jmp 0xb384c
movq -0x580(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x588(%rbp)
movq -0x588(%rbp), %rsi
leaq -0x1a8(%rbp), %rdi
callq 0xc8740
jmp 0xb3886
callq 0xc8780
movl %eax, -0x1ac(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
leaq -0x1ac(%rbp), %rdx
callq 0x34cc0
jmp 0xb38ad
leaq -0x1d0(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0xc8790
jmp 0xb38c2
leaq -0x320(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0xc85a0
jmp 0xb38d7
leaq -0x2d0(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
leaq -0x320(%rbp), %rdx
callq 0xc87d0
jmp 0xb38f3
leaq -0x260(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
leaq -0x2d0(%rbp), %rdx
callq 0xc8820
jmp 0xb390f
leaq -0x340(%rbp), %rax
movq %rax, -0x10(%rbp)
leaq -0x260(%rbp), %rax
movq %rax, -0x18(%rbp)
movq $0x3, -0x20(%rbp)
movq -0x18(%rbp), %rdx
movq %rdx, %r8
addq $0x20, %r8
leaq -0x68(%rbp), %rdi
leaq -0x69(%rbp), %rsi
leaq -0x6a(%rbp), %rcx
callq 0xc0f10
jmp 0xb394b
movq -0x18(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0xc1a70
jmp 0xb395a
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x340(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x338(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x330(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x328(%rbp)
leaq -0x100(%rbp), %rdi
callq 0xc8670
movq %rax, -0x590(%rbp)
jmp 0xb399e
movq -0x590(%rbp), %rax
movq %rax, -0x348(%rbp)
movq -0x348(%rbp), %rdi
callq 0x366c0
movq %rax, -0x598(%rbp)
jmp 0xb39c1
movq -0x598(%rbp), %rax
movq %rax, -0x350(%rbp)
movq -0x348(%rbp), %rdi
callq 0x366f0
movq %rax, -0x5a0(%rbp)
jmp 0xb39e4
movq -0x5a0(%rbp), %rax
movq %rax, -0x358(%rbp)
leaq -0x350(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x358(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rax
movq (%rax), %rax
movq -0x98(%rbp), %rcx
cmpq (%rcx), %rax
setne %al
movb %al, -0x5a1(%rbp)
movb -0x5a1(%rbp), %al
testb $0x1, %al
jne 0xb3a3a
jmp 0xb3d3a
leaq -0x350(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x5b0(%rbp)
movq -0x5b0(%rbp), %rax
movq %rax, -0x360(%rbp)
callq 0xc8780
movl %eax, -0x364(%rbp)
movw 0x1de887(%rip), %ax     # 0x292300
movw %ax, -0x3a2(%rbp)
movq -0x360(%rbp), %rdx
movw 0x1de872(%rip), %ax     # 0x292300
movw %ax, -0x3a4(%rbp)
leaq -0x3a0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0xc8690
jmp 0xb3aaa
leaq -0x364(%rbp), %rax
movq %rax, -0x3b0(%rbp)
leaq -0x3a0(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0xb3d90
jmp 0xb3acd
movq -0x360(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0xc8700
movq %rax, -0x5b8(%rbp)
jmp 0xb3ae9
movq -0x5b8(%rbp), %rax
movl (%rax), %eax
movl -0x364(%rbp), %ecx
subl %ecx, %eax
sete %al
movb %al, -0x5c1(%rbp)
leaq -0x561(%rbp), %rdi
movq %rdi, -0x5c0(%rbp)
callq 0x33b0
movq -0x5c0(%rbp), %rdx
leaq 0x1362e1(%rip), %rsi    # 0x1e9e05
leaq -0x560(%rbp), %rdi
callq 0x10a90
jmp 0xb3b32
movb -0x5c1(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x540(%rbp), %rdi
leaq -0x560(%rbp), %rdx
callq 0x10f80
jmp 0xb3b53
leaq 0x128c8b(%rip), %rsi    # 0x1dc7e5
leaq -0x540(%rbp), %rdi
callq 0x34320
movq %rax, -0x5d0(%rbp)
jmp 0xb3b6f
movq -0x5d0(%rbp), %rdi
leaq 0x1362a0(%rip), %rsi    # 0x1e9e1d
callq 0x344d0
movq %rax, -0x5d8(%rbp)
jmp 0xb3b8b
movq -0x5d8(%rbp), %rdi
leaq 0x12cc13(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x5e0(%rbp)
jmp 0xb3ba7
movq -0x360(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0xc8700
movq %rax, -0x5e8(%rbp)
jmp 0xb3bc3
movq -0x5e8(%rbp), %rsi
movq -0x5e0(%rbp), %rdi
callq 0x343a0
movq %rax, -0x5f0(%rbp)
jmp 0xb3bdf
movq -0x5f0(%rbp), %rdi
leaq 0x128bf8(%rip), %rsi    # 0x1dc7e5
callq 0x34320
movq %rax, -0x5f8(%rbp)
jmp 0xb3bfb
movq -0x5f8(%rbp), %rdi
leaq 0x136209(%rip), %rsi    # 0x1e9e12
callq 0x34570
movq %rax, -0x600(%rbp)
jmp 0xb3c17
movq -0x600(%rbp), %rdi
leaq 0x12cb87(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x608(%rbp)
jmp 0xb3c33
movq -0x608(%rbp), %rdi
leaq -0x364(%rbp), %rsi
callq 0x343a0
movq %rax, -0x610(%rbp)
jmp 0xb3c4f
movq -0x610(%rbp), %rdi
leaq 0x14281e(%rip), %rsi    # 0x1f647b
callq 0x34320
jmp 0xb3c64
leaq -0x540(%rbp), %rdi
callq 0x10ff0
jmp 0xb3c72
leaq -0x560(%rbp), %rdi
callq 0x3100
leaq -0x561(%rbp), %rdi
callq 0x3290
leaq -0x350(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0xb39f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
jmp 0xb3d67
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
jmp 0xb3d5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
jmp 0xb3d2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
jmp 0xb3d20
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
leaq -0x540(%rbp), %rdi
callq 0x10ff0
jmp 0xb3d1e
jmp 0xb3d20
leaq -0x560(%rbp), %rdi
callq 0x3100
leaq -0x561(%rbp), %rdi
callq 0x3290
jmp 0xb3d5b
leaq -0x190(%rbp), %rdi
callq 0x34990
leaq -0x100(%rbp), %rdi
callq 0x35160
addq $0x610, %rsp            # imm = 0x610
popq %rbp
retq
leaq -0x190(%rbp), %rdi
callq 0x34990
leaq -0x100(%rbp), %rdi
callq 0x35160
movq -0x150(%rbp), %rdi
callq 0x33a0
movq %rax, %rdi
callq 0x116d0
nopw (%rax,%rax)