// File: ef-gy[P]libefgy/src/test-case/transformation.cpp
// Function: testIdentity(std::ostream&)
bool testIdentity(std::ostream &log) {
  identity<double, 3> id;

  linear<double, 3> phi;

  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 3; k++) {
      phi.matrix[i][k] = i * k;
    }
  }

  linear<double, 3> leftProduct = id * phi;
  linear<double, 3> rightProduct = phi * id;

  bool leftProductOK = true;
  bool rightProductOK = true;

  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 3; k++) {
      leftProductOK &= (leftProduct.matrix[i][k] == i * k);
      rightProductOK &= (rightProduct.matrix[i][k] == i * k);
    }
  }

  if (!leftProductOK) {
    log << "Incorrect product of identity transformation with non-trivial "
           "transformation (id * phi).\n";
    log << "\n Expected: \n";
    log << phi.matrix;
    log << "\n Actual: \n";
    log << leftProduct.matrix;

    return false;
  }
  if (!rightProductOK) {
    log << "Incorrect product of non-trivial transformation with identity "
           "transformation (phi * id).\n";
    log << "\n Expected: \n";
    log << phi.matrix;
    log << "\n Actual: \n";
    log << rightProduct.matrix;

    return false;
  }

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x69e0
leaq -0xa0(%rbp), %rdi
callq 0x6a00
movl $0x0, -0xa4(%rbp)
cmpl $0x3, -0xa4(%rbp)
jge 0x5cec
movl $0x0, -0xa8(%rbp)
cmpl $0x3, -0xa8(%rbp)
jge 0x5cd6
movl -0xa4(%rbp), %eax
imull -0xa8(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x150(%rbp)
leaq -0xa0(%rbp), %rdi
movslq -0xa4(%rbp), %rsi
callq 0x6a40
movq %rax, %rdi
movslq -0xa8(%rbp), %rsi
callq 0x6a70
movsd -0x150(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x5c75
jmp 0x5cd8
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x5c5e
leaq -0xf0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x6aa0
leaq -0x138(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x6aa0
movb $0x1, -0x139(%rbp)
movb $0x1, -0x13a(%rbp)
movl $0x0, -0x140(%rbp)
cmpl $0x3, -0x140(%rbp)
jge 0x5e46
movl $0x0, -0x144(%rbp)
cmpl $0x3, -0x144(%rbp)
jge 0x5e30
leaq -0xf0(%rbp), %rdi
movslq -0x140(%rbp), %rsi
callq 0x6a40
movq %rax, %rdi
movslq -0x144(%rbp), %rsi
callq 0x6a70
movsd (%rax), %xmm0
movl -0x140(%rbp), %eax
imull -0x144(%rbp), %eax
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
sete %al
setnp %cl
andb %cl, %al
andb $0x1, %al
movzbl %al, %ecx
movb -0x139(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x139(%rbp)
leaq -0x138(%rbp), %rdi
movslq -0x140(%rbp), %rsi
callq 0x6a40
movq %rax, %rdi
movslq -0x144(%rbp), %rsi
callq 0x6a70
movsd (%rax), %xmm0
movl -0x140(%rbp), %eax
imull -0x144(%rbp), %eax
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
sete %al
setnp %cl
andb %cl, %al
andb $0x1, %al
movzbl %al, %ecx
movb -0x13a(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x13a(%rbp)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x5d49
jmp 0x5e32
movl -0x140(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x140(%rbp)
jmp 0x5d32
testb $0x1, -0x139(%rbp)
jne 0x5ea5
movq -0x10(%rbp), %rdi
leaq 0x2e378(%rip), %rsi     # 0x341d2
callq 0x5350
movq -0x10(%rbp), %rdi
leaq 0x2e3c2(%rip), %rsi     # 0x3422c
callq 0x5350
movq -0x10(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x6ae0
movq -0x10(%rbp), %rdi
leaq 0x2e3b0(%rip), %rsi     # 0x3423a
callq 0x5350
movq -0x10(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x6ae0
movb $0x0, -0x1(%rbp)
jmp 0x5f08
testb $0x1, -0x13a(%rbp)
jne 0x5f04
movq -0x10(%rbp), %rdi
leaq 0x2e38d(%rip), %rsi     # 0x34246
callq 0x5350
movq -0x10(%rbp), %rdi
leaq 0x2e363(%rip), %rsi     # 0x3422c
callq 0x5350
movq -0x10(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x6ae0
movq -0x10(%rbp), %rdi
leaq 0x2e351(%rip), %rsi     # 0x3423a
callq 0x5350
movq -0x10(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x6ae0
movb $0x0, -0x1(%rbp)
jmp 0x5f08
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw %cs:(%rax,%rax)