// File: tomfunkhouser[P]gaps/pkgs/RNMath/RNAlgebraic.cpp
// Function: gaps::RNAlgebraic::Divide(gaps::RNAlgebraic const&)
void RNAlgebraic::
Divide(const RNAlgebraic& value)
{
  // Just checking
  assert(IsValid());
  assert(value.IsValid());

  // Check factor
  if (value.IsZero()) {
    if (IsZero()) {
      Empty();
    }
    else {
      Empty();
      operation = RN_POLYNOMIAL_OPERATION;
      polynomial = new RNPolynomial(RN_INFINITY, 0);
    }
  }
  else if (!value.IsOne()) {
    switch(operation) {
    case RN_ZERO_OPERATION: 
      return;
      
    case RN_POLYNOMIAL_OPERATION:
      operands[1] = new RNAlgebraic(value);
      operands[0] = new RNAlgebraic(polynomial);
      operation = RN_DIVIDE_OPERATION;
      polynomial = NULL;
      return;
    
    default: {
      RNAlgebraic *e = new RNAlgebraic(operation, operands[0], operands[1]);
      operands[0] = new RNAlgebraic(value);
      operands[1] = e;
      operation = RN_DIVIDE_OPERATION;
      return; }
    }
  }
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x58(%rsp), %rdi
callq 0x3fa70
cmpl $0x0, %eax
je 0x45cb6
movq 0x38(%rsp), %rdi
callq 0x3fa70
cmpl $0x0, %eax
je 0x45c36
movq 0x38(%rsp), %rdi
callq 0x444e0
jmp 0x45cb1
movq 0x38(%rsp), %rdi
callq 0x444e0
movq 0x38(%rsp), %rax
movl $0x1, 0x8(%rax)
movl $0x10, %edi
callq 0x4280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x30(%rsp)
leaq 0x84680(%rip), %rax     # 0xca2e8
movsd (%rax), %xmm0
xorl %r8d, %r8d
movl %r8d, %ecx
movl %r8d, %esi
movq %rcx, %rdx
callq 0x3c6e0
jmp 0x45c7f
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x20(%rax)
jmp 0x45cb1
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
movl $0x10, %esi
callq 0x4290
jmp 0x45e64
jmp 0x45e5f
movq 0x58(%rsp), %rdi
callq 0x43990
cmpl $0x0, %eax
jne 0x45e5d
movq 0x38(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x2c(%rsp)
testl %eax, %eax
je 0x45ce9
jmp 0x45cdb
movl 0x2c(%rsp), %eax
subl $0x1, %eax
je 0x45cee
jmp 0x45da8
jmp 0x45e5f
movl $0x28, %edi
callq 0x4280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
movq 0x58(%rsp), %rsi
callq 0x3fe60
jmp 0x45d0f
movq 0x38(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, 0x18(%rax)
movl $0x28, %edi
callq 0x4280
movq %rax, %rdi
movq 0x38(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x18(%rsp)
movq 0x20(%rax), %rsi
callq 0x3f8b0
jmp 0x45d42
movq 0x38(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x10(%rax)
movl $0x5, 0x8(%rax)
movq $0x0, 0x20(%rax)
jmp 0x45e5f
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
movl $0x28, %esi
callq 0x4290
jmp 0x45e64
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
movl $0x28, %esi
callq 0x4290
jmp 0x45e64
movl $0x28, %edi
callq 0x4280
movq %rax, %rdi
movq 0x38(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x10(%rsp)
movl 0x8(%rax), %esi
movq 0x10(%rax), %rdx
movq 0x18(%rax), %rcx
callq 0x42ac0
jmp 0x45dd4
movq 0x10(%rsp), %rax
movq %rax, 0x40(%rsp)
movl $0x28, %edi
callq 0x4280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rsi
callq 0x3fe60
jmp 0x45dff
movq 0x38(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x40(%rsp), %rcx
movq %rcx, 0x18(%rax)
movl $0x5, 0x8(%rax)
jmp 0x45e5f
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
movl $0x28, %esi
callq 0x4290
jmp 0x45e64
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
movl $0x28, %esi
callq 0x4290
jmp 0x45e64
jmp 0x45e5f
addq $0x68, %rsp
retq
movq 0x50(%rsp), %rdi
callq 0x44b0
nop