// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
leaq 0xc8(%rsp), %rbx
pushq $0x4
popq %rsi
pushq $0x5
popq %rdx
pushq $0x8
popq %rcx
movq %rbx, %rdi
callq 0x10b74
leaq 0x258(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x10b92
movq %r14, %rdi
xorl %esi, %esi
callq 0x10bbd
movq 0x298(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x46fac
leaq 0x30(%rsp), %rdx
movl $0x80000000, (%rdx)     # imm = 0x80000000
leaq 0x78(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x10a16
leaq 0x290(%rsp), %rax
movq 0x90(%rsp), %rcx
movq 0xa8(%rsp), %rdx
movq %rdx, 0xe0(%rsp)
movups 0x98(%rsp), %xmm0
movups %xmm0, 0xd0(%rsp)
movq -0x20(%rax), %rdx
movq -0x8(%rax), %rsi
movq %rsi, 0x120(%rsp)
movups -0x18(%rax), %xmm0
movups %xmm0, 0x110(%rsp)
movups (%rax), %xmm0
movups %xmm0, 0x128(%rsp)
movq 0x10(%rax), %rsi
movq %rsi, 0x138(%rsp)
movq 0x28(%rax), %rsi
movq %rsi, 0x150(%rsp)
movups 0x18(%rax), %xmm0
movups %xmm0, 0x140(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x100(%rsp)
movdqu 0x98(%rsp), %xmm0
movdqu %xmm0, 0xf0(%rsp)
movq %rcx, 0xc8(%rsp)
movq %rcx, 0xe8(%rsp)
movq %rdx, 0x108(%rsp)
movq 0xd0(%rsp), %rax
movq 0x128(%rsp), %rdx
cmpq %rax, %rdx
jg 0x461f6
movdqu 0xd8(%rsp), %xmm0
movq %xmm0, %rcx
addq %rax, %rcx
addq 0x130(%rsp), %rdx
cmpq %rdx, %rcx
jg 0x461f6
movq 0xf0(%rsp), %rdx
cmpq %rax, %rdx
jg 0x461f6
addq 0xf8(%rsp), %rdx
cmpq %rdx, %rcx
jg 0x461f6
movups 0x140(%rsp), %xmm1
movups 0x110(%rsp), %xmm2
leaq 0x10(%rsp), %rcx
movaps %xmm2, (%rcx)
leaq 0xb0(%rsp), %rdx
movq %rax, (%rdx)
movdqu %xmm0, 0x8(%rdx)
leaq 0x2c0(%rsp), %rsi
movaps %xmm1, (%rsi)
leaq 0x30(%rsp), %rdi
callq 0x49d50
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %rax
addq %r14, %rax
movq %rax, 0x28(%rsp)
cmpq 0x28(%rsp), %r14
je 0x45fa1
movq 0x48(%rsp), %r15
movq 0x50(%rsp), %rax
addq %r15, %rax
movq %rax, 0x8(%rsp)
cmpq 0x8(%rsp), %r15
je 0x45f99
movq 0x60(%rsp), %r12
movq 0x68(%rsp), %r13
subq $0x1, %r13
jb 0x45f94
movq 0xe8(%rsp), %rbp
movq 0xf0(%rsp), %rbx
leaq 0x108(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x49cae
movq %r15, %rcx
subq %rbx, %rcx
movl (%rbp,%rcx,4), %ecx
movl (%rax), %eax
cmpl %eax, %ecx
cmovgl %ecx, %eax
movq 0xc8(%rsp), %rcx
movq %r15, %rdx
subq 0xd0(%rsp), %rdx
movl %eax, (%rcx,%rdx,4)
incq %r12
jmp 0x45f3c
incq %r15
jmp 0x45f2b
incq %r14
jmp 0x45f0e
leaq 0x258(%rsp), %rax
movq 0x50(%rax), %r14
movq 0x58(%rax), %rax
addq %r14, %rax
movq %rax, 0x8(%rsp)
leaq 0xc8(%rsp), %r12
leaq 0x30(%rsp), %r13
cmpq 0x8(%rsp), %r14
je 0x461ae
movl $0x80000000, 0x10(%rsp) # imm = 0x80000000
movq %r12, %rdi
leaq 0x258(%rsp), %rsi
movq %r14, %rdx
callq 0x46f7e
movq 0xc8(%rsp), %rbp
movq %r13, %rdi
leaq 0xd0(%rsp), %rsi
callq 0x9125
testq %rbp, %rbp
je 0x460a9
movq 0x58(%rsp), %rax
movq 0x38(%rsp), %rcx
movq 0x50(%rsp), %rdx
testq %rdx, %rdx
movl $0x0, %esi
cmovgq %rdx, %rsi
movq 0x40(%rsp), %rdi
testq %rcx, %rcx
movl $0x0, %r8d
cmovleq %r8, %rcx
movl 0x10(%rsp), %r15d
shlq $0x2, %rdi
leaq (,%rax,4), %r8
xorl %r9d, %r9d
cmpq %rcx, %r9
je 0x460c2
cmpq $0x1, %rax
jne 0x46081
leaq (,%rdx,4), %r10
addq %rbp, %r10
movq %rbp, %r11
cmpq %r10, %r11
jae 0x460a1
movl (%r11), %ebx
addq $0x4, %r11
cmpl %ebx, %r15d
cmovlel %ebx, %r15d
movl %r15d, 0x10(%rsp)
jmp 0x46067
movq %rsi, %r10
movq %rbp, %r11
subq $0x1, %r10
jb 0x460a1
movl (%r11), %ebx
cmpl %ebx, %r15d
cmovlel %ebx, %r15d
movl %r15d, 0x10(%rsp)
addq %r8, %r11
jmp 0x46087
addq %rdi, %rbp
incq %r9
jmp 0x4604e
movq 0x38(%rsp), %rax
imulq 0x50(%rsp), %rax
testq %rax, %rax
jg 0x461d7
movl 0x10(%rsp), %r15d
movq 0x90(%rsp), %rax
movq %r14, %rcx
subq 0x98(%rsp), %rcx
movl (%rax,%rcx,4), %ebp
movq %r13, %rdi
leaq 0x547a7(%rip), %rsi     # 0x9a889
leaq 0xb0(%rsp), %rdx
callq 0x66a0
xorl %esi, %esi
cmpl %r15d, %ebp
sete %sil
movq %r12, %rdi
movq %r13, %rdx
callq 0x6894
leaq 0x4753d(%rip), %rbx     # 0x8d647
leaq 0x4b4e1(%rip), %r15     # 0x915f2
movq %r12, %rdi
movq %rbx, %rsi
callq 0x106fe
movq %rax, %rdi
leaq 0x5477b(%rip), %rsi     # 0x9a8a1
callq 0x1079e
movq %rax, %rdi
movq %r15, %rsi
callq 0x106fe
movq %r14, %rsi
subq 0x98(%rsp), %rsi
shlq $0x2, %rsi
addq 0x90(%rsp), %rsi
movq %rax, %rdi
callq 0x10736
movq %rax, %rdi
movq %rbx, %rsi
callq 0x106fe
movq %rax, %rdi
leaq 0x5472c(%rip), %rsi     # 0x9a896
callq 0x107d8
movq %rax, %rdi
movq %r15, %rsi
callq 0x106fe
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x10736
movq %rax, %rdi
leaq 0x5f111(%rip), %rsi     # 0xa52a2
callq 0x106fe
movq %r12, %rdi
callq 0x68d4
movq %r13, %rdi
callq 0x2090
incq %r14
jmp 0x45fc6
leaq 0x78(%rsp), %rdi
callq 0x1090e
leaq 0x258(%rsp), %rdi
callq 0x10d02
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x470b1(%rip), %rdi     # 0x8d28f
leaq 0x46eec(%rip), %rsi     # 0x8d0d1
leaq 0x57fef(%rip), %rcx     # 0x9e1db
movl $0x6a1, %edx            # imm = 0x6A1
callq 0x20e0
leaq 0x54ca3(%rip), %rdi     # 0x9aea0
leaq 0x54cbb(%rip), %rsi     # 0x9aebf
leaq 0x55894(%rip), %rcx     # 0x9ba9f
movl $0xf2, %edx
callq 0x20e0
jmp 0x4624f
jmp 0x4621b
jmp 0x4621b
movq %rax, %rbx
jmp 0x4625c
jmp 0x4624f
jmp 0x4624f
jmp 0x4624f
movq %rax, %rbx
jmp 0x4623b
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x68d4
leaq 0x30(%rsp), %rdi
callq 0x2090
jmp 0x46252
movq %rax, %rdi
callq 0x6bba
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x1090e
leaq 0x258(%rsp), %rdi
callq 0x10d02
movq %rbx, %rdi
callq 0x22f0