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

  int max_ik[5];
  std::fill(std::begin(max_ik), std::end(max_ik), 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 $0x560, %rsp            # imm = 0x560
leaq -0x128(%rbp), %rdi
movq %rdi, -0x4d0(%rbp)
movl $0x4, %esi
movl $0x5, %edx
movl $0x8, %ecx
callq 0x34ec0
movq -0x4d0(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x4c8(%rbp)
callq 0x34f10
movq -0x4c8(%rbp), %rdi
xorl %esi, %esi
callq 0x34fb0
jmp 0xb3e17
leaq -0x150(%rbp), %rdi
movq %rdi, -0x4e8(%rbp)
callq 0xc8890
movq -0x4e8(%rbp), %rdi
movq %rax, -0x4e0(%rbp)
callq 0xc88a0
movq %rax, -0x4d8(%rbp)
callq 0xc8780
movq -0x4e0(%rbp), %rdi
movq -0x4d8(%rbp), %rsi
movl %eax, -0x154(%rbp)
leaq -0x154(%rbp), %rdx
callq 0xc8860
jmp 0xb3e6b
leaq -0x168(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0xc88c0
jmp 0xb3e80
leaq -0x288(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xc85a0
jmp 0xb3e95
leaq -0x238(%rbp), %rdi
leaq -0x168(%rbp), %rsi
leaq -0x288(%rbp), %rdx
callq 0xc8920
jmp 0xb3eb1
leaq -0x1d8(%rbp), %rdi
leaq -0x168(%rbp), %rsi
leaq -0x238(%rbp), %rdx
callq 0xc8970
jmp 0xb3ecd
leaq -0x298(%rbp), %rax
movq %rax, -0x8(%rbp)
leaq -0x1d8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq $0x3, -0x18(%rbp)
movq -0x10(%rbp), %rdx
movq %rdx, %r8
addq $0x10, %r8
leaq -0x50(%rbp), %rdi
leaq -0x51(%rbp), %rsi
leaq -0x52(%rbp), %rcx
callq 0xc1eb0
jmp 0xb3f09
movq -0x10(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0xc2940
jmp 0xb3f18
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x298(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x290(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0xc8670
movq %rax, -0x4f0(%rbp)
jmp 0xb3f46
movq -0x4f0(%rbp), %rax
movq %rax, -0x2a0(%rbp)
movq -0x2a0(%rbp), %rdi
callq 0x366c0
movq %rax, -0x4f8(%rbp)
jmp 0xb3f69
movq -0x4f8(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movq -0x2a0(%rbp), %rdi
callq 0x366f0
movq %rax, -0x500(%rbp)
jmp 0xb3f8c
movq -0x500(%rbp), %rax
movq %rax, -0x2b0(%rbp)
leaq -0x2a8(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x2b0(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq -0x78(%rbp), %rcx
cmpq (%rcx), %rax
setne %al
movb %al, -0x501(%rbp)
movb -0x501(%rbp), %al
testb $0x1, %al
jne 0xb3fd6
jmp 0xb428b
leaq -0x2a8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x510(%rbp)
movq -0x510(%rbp), %rax
movq %rax, -0x2b8(%rbp)
callq 0xc8780
movl %eax, -0x2bc(%rbp)
movw 0x1de2f1(%rip), %ax     # 0x292300
movw %ax, -0x2fa(%rbp)
movq -0x2b8(%rbp), %rdx
movw 0x1de2dc(%rip), %ax     # 0x292300
movw %ax, -0x2fc(%rbp)
leaq -0x2f8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xc8690
jmp 0xb4040
leaq -0x2bc(%rbp), %rax
movq %rax, -0x308(%rbp)
leaq -0x2f8(%rbp), %rdi
leaq -0x308(%rbp), %rsi
callq 0xb42c0
jmp 0xb4063
movq -0x2b8(%rbp), %rax
movl -0x150(%rbp,%rax,4), %eax
movl -0x2bc(%rbp), %ecx
subl %ecx, %eax
sete %al
movb %al, -0x519(%rbp)
leaq -0x4b9(%rbp), %rdi
movq %rdi, -0x518(%rbp)
callq 0x33b0
movq -0x518(%rbp), %rdx
leaq 0x135d9d(%rip), %rsi    # 0x1e9e40
leaq -0x4b8(%rbp), %rdi
callq 0x10a90
jmp 0xb40b1
movb -0x519(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x498(%rbp), %rdi
leaq -0x4b8(%rbp), %rdx
callq 0x10f80
jmp 0xb40d2
leaq 0x12870c(%rip), %rsi    # 0x1dc7e5
leaq -0x498(%rbp), %rdi
callq 0x34320
movq %rax, -0x528(%rbp)
jmp 0xb40ee
movq -0x528(%rbp), %rdi
leaq 0x135d5c(%rip), %rsi    # 0x1e9e58
callq 0x344d0
movq %rax, -0x530(%rbp)
jmp 0xb410a
movq -0x530(%rbp), %rdi
leaq 0x12c694(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x538(%rbp)
jmp 0xb4126
movq -0x538(%rbp), %rdi
movq -0x2b8(%rbp), %rax
leaq -0x150(%rbp,%rax,4), %rsi
callq 0x343a0
movq %rax, -0x540(%rbp)
jmp 0xb414a
movq -0x540(%rbp), %rdi
leaq 0x12868d(%rip), %rsi    # 0x1dc7e5
callq 0x34320
movq %rax, -0x548(%rbp)
jmp 0xb4166
movq -0x548(%rbp), %rdi
leaq 0x135c9e(%rip), %rsi    # 0x1e9e12
callq 0x34570
movq %rax, -0x550(%rbp)
jmp 0xb4182
movq -0x550(%rbp), %rdi
leaq 0x12c61c(%rip), %rsi    # 0x1e07ac
callq 0x34320
movq %rax, -0x558(%rbp)
jmp 0xb419e
movq -0x558(%rbp), %rdi
leaq -0x2bc(%rbp), %rsi
callq 0x343a0
movq %rax, -0x560(%rbp)
jmp 0xb41ba
movq -0x560(%rbp), %rdi
leaq 0x1422b3(%rip), %rsi    # 0x1f647b
callq 0x34320
jmp 0xb41cf
leaq -0x498(%rbp), %rdi
callq 0x10ff0
jmp 0xb41dd
leaq -0x4b8(%rbp), %rdi
callq 0x3100
leaq -0x4b9(%rbp), %rdi
callq 0x3290
leaq -0x2a8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0xb3f9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
jmp 0xb42a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
jmp 0xb427d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
jmp 0xb4271
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
leaq -0x498(%rbp), %rdi
callq 0x10ff0
jmp 0xb426f
jmp 0xb4271
leaq -0x4b8(%rbp), %rdi
callq 0x3100
leaq -0x4b9(%rbp), %rdi
callq 0x3290
jmp 0xb42a0
leaq -0xe0(%rbp), %rdi
callq 0x35160
addq $0x560, %rsp            # imm = 0x560
popq %rbp
retq
leaq -0xe0(%rbp), %rdi
callq 0x35160
movq -0x130(%rbp), %rdi
callq 0x33a0
movq %rax, %rdi
callq 0x116d0