// File: /workspace/github_cpp_makefile_star2_O3/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 0x22ad0
movq %rdi, %rbx
movl %esi, %eax
leaq 0x37d07(%rip), %rcx     # 0x5a6f8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x22a0e
jnp 0x22b6a
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
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 0x20ce4
jmp 0x22b66
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x22a56
jnp 0x22b6a
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
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 0x20ce4
jmp 0x22b66
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0x22b72
jp 0x22b72
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
callq 0x4280
movq %rax, %r14
movsd 0x36556(%rip), %xmm0    # 0x59010
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20ce4
jmp 0x22b66
leaq 0x37dda(%rip), %rdi     # 0x5a8b1
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x29356
mulsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x22af5
jnp 0x22b6a
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
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 0x20ce4
jmp 0x22b66
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0x22bb4
jp 0x22bb4
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
callq 0x4280
movq %rax, %r14
leaq 0x5985f(%rip), %rax     # 0x7c3b0
movsd (%rax), %xmm0
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20ce4
movq %r14, 0x20(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
callq 0x44b0
ucomisd 0x36c61(%rip), %xmm0    # 0x597e0
jne 0x22b83
jnp 0x22b6a
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
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 0x20ce4
jmp 0x22b66
divsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jne 0x22bc0
jnp 0x22b6a
movl $0x1, 0x8(%rbx)
movl $0x10, %edi
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 0x20ce4
jmp 0x22b66
jmp 0x22c00
jmp 0x22c00
jmp 0x22c00
jmp 0x22c00
jmp 0x22c00
jmp 0x22c00
movq %rax, %rbx
movl $0x10, %esi
movq %r14, %rdi
callq 0x4290
movq %rbx, %rdi
callq 0x44c0