// File: /workspace/github_cpp_makefile_star2_O2/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 0x20548
movq %rdi, %rbx
movl %esi, %eax
leaq 0x32435(%rip), %rcx     # 0x528a4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2048c
jnp 0x205da
movl $0x1, 0x8(%rbx)
pushq $0x10
popq %rdi
movsd %xmm0, (%rsp)
callq 0x4280
movq %rax, %r14
movq %rax, %rdi
movsd (%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1e996
jmp 0x205d6
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x204d2
jnp 0x205da
movl $0x1, 0x8(%rbx)
pushq $0x10
popq %rdi
movsd %xmm0, (%rsp)
callq 0x4280
movq %rax, %r14
movq %rax, %rdi
movsd (%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1e996
jmp 0x205d6
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0x205e2
jp 0x205e2
movl $0x1, 0x8(%rbx)
pushq $0x10
popq %rdi
callq 0x4280
movq %rax, %r14
movsd 0x30ade(%rip), %xmm0    # 0x51010
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1e996
jmp 0x205d6
leaq 0x3250e(%rip), %rdi     # 0x52a5d
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x264a8
mulsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2056d
jnp 0x205da
movl $0x1, 0x8(%rbx)
pushq $0x10
popq %rdi
movsd %xmm0, (%rsp)
callq 0x4280
movq %rax, %r14
movq %rax, %rdi
movsd (%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1e996
jmp 0x205d6
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0x20622
jp 0x20622
movl $0x1, 0x8(%rbx)
pushq $0x10
popq %rdi
callq 0x4280
movq %rax, %r14
leaq 0x56df7(%rip), %rax     # 0x773b8
movsd (%rax), %xmm0
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1e996
movq %r14, 0x20(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
callq 0x44c0
ucomisd 0x313e9(%rip), %xmm0    # 0x519d8
jne 0x205f3
jnp 0x205da
movl $0x1, 0x8(%rbx)
pushq $0x10
popq %rdi
movsd %xmm0, (%rsp)
callq 0x4280
movq %rax, %r14
movq %rax, %rdi
movsd (%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1e996
jmp 0x205d6
divsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jne 0x2062e
jnp 0x205da
movl $0x1, 0x8(%rbx)
pushq $0x10
popq %rdi
movsd %xmm0, (%rsp)
callq 0x4280
movq %rax, %r14
movq %rax, %rdi
movsd (%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1e996
jmp 0x205d6
jmp 0x2066c
jmp 0x2066c
jmp 0x2066c
jmp 0x2066c
jmp 0x2066c
jmp 0x2066c
movq %rax, %rbx
pushq $0x10
popq %rsi
movq %r14, %rdi
callq 0x4290
movq %rbx, %rdi
callq 0x44d0