// File: /workspace/github_cpp_makefile_star2_O2/ef-gy[P]libefgy/src/test-case/matrix.cpp
// Function: testAddition(std::ostream&)
bool testAddition(std::ostream &log) {
  matrix<int, 3, 4> m;
  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 4; k++) {
      m[i][k] = i * k;
    }
  }

  matrix<int, 3, 4> n;

  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 4; k++) {
      n[i][k] = 0;
    }
  }

  // results of left and right addition of
  // neutral element to m
  matrix<int, 3, 4> leftNeutral = n + m;
  matrix<int, 3, 4> rightNeutral = m + n;

  // test addition of neutral element;
  bool allCorrectLeft = true;
  bool allCorrectRight = true;
  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 4; k++) {
      allCorrectLeft &= (leftNeutral[i][k] == (i * k));
      allCorrectRight &= (rightNeutral[i][k] == (i * k));
    }
  }
  if (!allCorrectLeft) {
    log << "n + m, where n is the neutral element: ";
    for (int i = 0; i < 3; i++) {
      for (int k = 0; k < 4; k++) {
        log << leftNeutral[i][k];
      }
      log << "\n";
    }
    log << "\n";
    log << "m (original matrix):";
    for (int i = 0; i < 3; i++) {
      for (int k = 0; k < 4; k++) {
        log << m[i][k];
      }
      log << "\n";
    }

    log << "Unexpected result of left addition of neutral element to matrix.";
    return false;
  }
  if (!allCorrectRight) {
    log << "m + n, where n is the neutral element: ";
    for (int i = 0; i < 3; i++) {
      for (int k = 0; k < 4; k++) {
        log << rightNeutral[i][k];
      }
      log << "\n";
    }

    log << "\n";
    log << "m (original matrix):";
    for (int i = 0; i < 3; i++) {
      for (int k = 0; k < 4; k++) {
        log << m[i][k];
      }
      log << "\n";
    }
    log << "Unexpected result of right addition of neutral element to matrix.";
    return false;
  }

  // another test for addition of two non-neutral elements
  matrix<int, 3, 4> m2;

  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 4; k++) {
      m2[i][k] = i + k;
    }
  }

  matrix<int, 3, 4> sum = m + m2;

  bool allCorrectSum = true;
  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 3; k++) {
      allCorrectSum &= (sum[i][k] == (i * k) + (i + k));
    }
  }

  if (!allCorrectSum) {
    log << "Unexpected result adding two matrices.";
    return false;
  }

  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %rbx
leaq 0x8(%rsp), %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x4b98
xorl %edx, %edx
xorl %esi, %esi
cmpq $0x4, %rsi
je 0x4b8f
movl %edx, (%rax,%rsi,4)
incq %rsi
addl %ecx, %edx
jmp 0x4b7f
incq %rcx
addq $0x10, %rax
jmp 0x4b75
leaq 0xc8(%rsp), %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x4bc2
xorl %edx, %edx
cmpq $0x4, %rdx
je 0x4bb9
andl $0x0, (%rax,%rdx,4)
incq %rdx
jmp 0x4baa
incq %rcx
addq $0x10, %rax
jmp 0x4ba2
leaq 0x98(%rsp), %r15
leaq 0xc8(%rsp), %r13
leaq 0x8(%rsp), %r14
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x540f
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x540f
movb $0x1, %al
xorl %ecx, %ecx
movb $0x1, %dl
cmpq $0x3, %rcx
je 0x4c3f
xorl %esi, %esi
xorl %edi, %edi
cmpq $0x4, %rdi
je 0x4c32
movl (%r15,%rdi,4), %r8d
cmpq %r8, %rsi
sete %r8b
andb %r8b, %al
movl (%r12,%rdi,4), %r8d
cmpq %r8, %rsi
sete %r8b
andb %r8b, %dl
incq %rdi
addq %rcx, %rsi
jmp 0x4c08
incq %rcx
addq $0x10, %r15
addq $0x10, %r12
jmp 0x4bfe
testb $0x1, %al
je 0x4c79
testb $0x1, %dl
je 0x4d31
leaq 0x38(%rsp), %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x4d87
xorl %edx, %edx
cmpq $0x4, %rdx
je 0x4c70
leal (%rcx,%rdx), %esi
movl %esi, (%rax,%rdx,4)
incq %rdx
jmp 0x4c5f
incq %rcx
addq $0x10, %rax
jmp 0x4c53
leaq 0xd514(%rip), %rsi      # 0x12194
movq %rbx, %rdi
callq 0x4290
leaq 0x98(%rsp), %r12
xorl %r13d, %r13d
leaq 0xd611(%rip), %r15      # 0x122ab
cmpq $0x3, %r13
je 0x4ccd
xorl %ebp, %ebp
cmpq $0x4, %rbp
je 0x4cb9
movl (%r12,%rbp,4), %esi
movq %rbx, %rdi
callq 0x4430
incq %rbp
jmp 0x4ca2
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4290
incq %r13
addq $0x10, %r12
jmp 0x4c9a
leaq 0xd5d7(%rip), %r15      # 0x122ab
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4290
leaq 0xd4d6(%rip), %rsi      # 0x121bc
movq %rbx, %rdi
callq 0x4290
xorl %r12d, %r12d
cmpq $0x3, %r12
je 0x4d25
xorl %r13d, %r13d
cmpq $0x4, %r13
je 0x4d11
movl (%r14,%r13,4), %esi
movq %rbx, %rdi
callq 0x4430
incq %r13
jmp 0x4cfa
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4290
incq %r12
addq $0x10, %r14
jmp 0x4cf1
leaq 0xd4a5(%rip), %rsi      # 0x121d1
jmp 0x4e5b
leaq 0xd4da(%rip), %rsi      # 0x12212
movq %rbx, %rdi
callq 0x4290
leaq 0x68(%rsp), %r15
xorl %r12d, %r12d
leaq 0xd55c(%rip), %r14      # 0x122ab
cmpq $0x3, %r12
je 0x4de0
xorl %r13d, %r13d
cmpq $0x4, %r13
je 0x4d73
movl (%r15,%r13,4), %esi
movq %rbx, %rdi
callq 0x4430
incq %r13
jmp 0x4d5c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4290
incq %r12
addq $0x10, %r15
jmp 0x4d4f
leaq 0xf8(%rsp), %r14
leaq 0x8(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
callq 0x540f
movb $0x1, %bpl
pushq $0x1
popq %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x4e3d
movq %rcx, %rdx
xorl %esi, %esi
cmpq $0x3, %rsi
je 0x4dd4
movl (%r14,%rsi,4), %edi
cmpq %rdi, %rdx
sete %dil
andb %dil, %bpl
incq %rsi
addq %rax, %rdx
jmp 0x4db8
incq %rcx
addq $0x10, %r14
incq %rax
jmp 0x4da9
leaq 0xd4c4(%rip), %r14      # 0x122ab
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4290
leaq 0xd3c3(%rip), %rsi      # 0x121bc
movq %rbx, %rdi
callq 0x4290
leaq 0x8(%rsp), %r15
xorl %r12d, %r12d
cmpq $0x3, %r12
je 0x4e54
xorl %r13d, %r13d
cmpq $0x4, %r13
je 0x4e29
movl (%r15,%r13,4), %esi
movq %rbx, %rdi
callq 0x4430
incq %r13
jmp 0x4e12
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4290
incq %r12
addq $0x10, %r15
jmp 0x4e09
testb $0x1, %bpl
jne 0x4e65
leaq 0xd432(%rip), %rsi      # 0x1227c
movq %rbx, %rdi
callq 0x4290
jmp 0x4e65
leaq 0xd3df(%rip), %rsi      # 0x1223a
movq %rbx, %rdi
callq 0x4290
xorl %ebp, %ebp
andb $0x1, %bpl
movl %ebp, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq