// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/RNMath/RNAlgebraic.cpp
// Function: gaps::RNAlgebraic::Construct(int, double, double, int)
void RNAlgebraic::
Construct(int op, RNScalar operand1, RNScalar operand2, RNBoolean force)
{
  // Condense scalars based on operation
  switch(op) {
  case RN_ZERO_OPERATION:
    break;

  case RN_ADD_OPERATION: {
    RNScalar sum = operand1 + operand2;
    if (sum == 0) break;
    operation = RN_POLYNOMIAL_OPERATION;
    polynomial = new RNPolynomial(sum, 0);
    break; }

  case RN_SUBTRACT_OPERATION: {
    RNScalar difference = operand1 - operand2;
    if (difference == 0) break;
    operation = RN_POLYNOMIAL_OPERATION;
    polynomial = new RNPolynomial(difference, 0);
    break; }

  case RN_MULTIPLY_OPERATION: {
    RNScalar product = operand1 * operand2;
    if (product == 0) break;
    operation = RN_POLYNOMIAL_OPERATION;
    polynomial = new RNPolynomial(product, 0);
    break; }

  case RN_DIVIDE_OPERATION:
    if (operand2 == 0) {
      operation = RN_POLYNOMIAL_OPERATION;
      polynomial = new RNPolynomial(RN_INFINITY, 0);
    }
    else {
      RNScalar quotient = operand1 / operand2;
      if (quotient == 0) break;
      operation = RN_POLYNOMIAL_OPERATION;
      polynomial = new RNPolynomial(quotient, 0);
    }
    break;

  case RN_POW_OPERATION:
    if (operand2 == 0) {
      operation = RN_POLYNOMIAL_OPERATION;
      polynomial = new RNPolynomial(1.0, 0);
    }
    else {
      RNScalar result = pow(operand1, operand2);
      if (result == 0) break;
      operation = RN_POLYNOMIAL_OPERATION;
      polynomial = new RNPolynomial(result, 0);
    }
    break;

  default:
    RNAbort("Invalid operation %d\n", op);
    break;
  }

  // Just checking
  assert(IsValid());
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
cmpl $0x6, %esi
ja 0x22c1c
movq %rdi, %rbx
movl %esi, %eax
leaq 0x37bab(%rip), %rcx     # 0x5a6e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x22b5a
jnp 0x22cb6
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
movsd %xmm0, (%rsp)
callq 0x4270
movq %rax, %r14
movq %rax, %rdi
movsd (%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20dd4
jmp 0x22cb2
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x22ba2
jnp 0x22cb6
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
movsd %xmm0, (%rsp)
callq 0x4270
movq %rax, %r14
movq %rax, %rdi
movsd (%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20dd4
jmp 0x22cb2
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0x22cbe
jp 0x22cbe
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
callq 0x4270
movq %rax, %r14
movsd 0x3640a(%rip), %xmm0    # 0x59010
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20dd4
jmp 0x22cb2
leaq 0x37c7e(%rip), %rdi     # 0x5a8a1
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x297ae
mulsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x22c41
jnp 0x22cb6
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
movsd %xmm0, (%rsp)
callq 0x4270
movq %rax, %r14
movq %rax, %rdi
movsd (%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20dd4
jmp 0x22cb2
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0x22d00
jp 0x22d00
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
callq 0x4270
movq %rax, %r14
leaq 0x5970b(%rip), %rax     # 0x7c3a8
movsd (%rax), %xmm0
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20dd4
movq %r14, 0x20(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
callq 0x44a0
ucomisd 0x36b15(%rip), %xmm0    # 0x597e0
jne 0x22ccf
jnp 0x22cb6
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
movsd %xmm0, (%rsp)
callq 0x4270
movq %rax, %r14
movq %rax, %rdi
movsd (%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20dd4
jmp 0x22cb2
divsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jne 0x22d0c
jnp 0x22cb6
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
movsd %xmm0, (%rsp)
callq 0x4270
movq %rax, %r14
movq %rax, %rdi
movsd (%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20dd4
jmp 0x22cb2
jmp 0x22d4c
jmp 0x22d4c
jmp 0x22d4c
jmp 0x22d4c
jmp 0x22d4c
jmp 0x22d4c
movq %rax, %rbx
movl $0x10, %esi
movq %r14, %rdi
callq 0x4280
movq %rbx, %rdi
callq 0x44b0