// File: canzarlab[P]Trajan/geno/augmentedLagrangian.cpp
// Function: AugmentedLagrangian::solve()
SolverStatus AugmentedLagrangian::solve() 
{  
  static const double gamma = 2;
  //  static const double rhoMin = 1E-6;
  //  static const double rhoMax = 10;
    
  Scalar rho = 0;
//  Vector y = Vector::Zero(_genoNLP.getM());
  _genoNLP.getStartingPointDual(_y.data());
  //  std::cout << "y= " << y.transpose() << std::endl;
  AugmentedNLP augmentedNLP(_genoNLP, rho, _y);
  size_t mEqualities = augmentedNLP.mEqualities();
  size_t mInequalities = augmentedNLP.mInequalities();
  std::vector<int> cType = augmentedNLP.cType();
  

  /*
  _genoNLP.getStartingPoint(_x.data());
  Vector dummyG(_genoNLP.getN());
  _genoNLP.functionValueAndGradient(_x.data(), _f, dummyG.data());
  double dummyF;
  augmentedNLP.functionValueAndGradient(_x.data(), dummyF, dummyG.data());
  Vector constraintError = augmentedNLP.constraintError();

  for (size_t i = 0; i < mInequalities; ++i)
    if (constraintError(mEqualities + i) < 0)
      constraintError(mEqualities + i) = 0;
  std::cout << "constraint Error = " << constraintError.transpose() << std::endl;
  rho = 2 * (std::abs(_f) + 1) / constraintError.squaredNorm();
  if (rho < rhoMin)
    rho = rhoMin;
  if(rho > rhoMax)
    rho = rhoMax;
  */

  Vector constraintError;
  Vector cl = augmentedNLP.cl();
  Vector cu = augmentedNLP.cu();
  Vector dummyG(_genoNLP.getN());
  rho = 1.0;

  LBFGSB solver(augmentedNLP, _correctionPairs, _verbose);
  //NEWTONB solver(augmentedNLP, _correctionPairs);
  if (_tol != -1) solver.setParameter("pgtol", _tol);
  if (_tolFun != -1) solver.setParameter("factr", _tolFun);
  double oldFactor = INF;
  double tau = 0.5;
  double lambdaMin = -1E20;
  double lambdaMax = 1E20;
  double muMax = 1E20;
  double muMin = -1E20;
  SolverStatus status = SOLVED;
  
  for (size_t iter = 0; iter < _maxIter; ++iter) 
  {
    if (_verbose)
      std::cout << "rho = " << rho << std::endl;

    augmentedNLP.setParams(rho, _y);
    solver.restart();
    status = solver.solve();
    if ((status != SOLVED) && (status != SUBOPTIMAL))
      break;
    constraintError = augmentedNLP.constraintError();
    Vector trueConstraintError(constraintError);
    for (size_t i = 0; i < mInequalities; ++i) {
      if (cType[i+mEqualities] == 2)
        if (trueConstraintError(mEqualities + i) > 0)
          trueConstraintError(mEqualities + i) = 0;

      if (cType[i+mEqualities] == 4)
	if (trueConstraintError(mEqualities + i) < 0)
	  trueConstraintError(mEqualities + i) = 0;
    }
    double constraintErrorNorm = 
      trueConstraintError.lpNorm<Eigen::Infinity>();

    _x = Vector::Map(solver.x(), _x.size());

    //    std::cout << "cl " << cl.transpose() << std::endl;
    //    std::cout << "cu " << cu.transpose() << std::endl;
    //    std::cout << "constraint Values " << augmentedNLP.constraintValues().transpose() << std::endl;
    //    std::cout << "y " << y.transpose() << std::endl;
    if (constraintErrorNorm < _constraintsTol)
      break;

    //    y = y + rho * constraintError;

    _y.head(mEqualities) +=  rho * constraintError.head(mEqualities);

    //safeguard Lagrange multiplier for equality constraints
    for (size_t i = 0; i < mEqualities; ++i) {
      if (_y(i) < lambdaMin)
	_y(i) = lambdaMin;
      if (_y(i) > lambdaMax)
	_y(i) = lambdaMax;
    }


    Vector constraintValues = augmentedNLP.constraintValues();

    // compute new Lagrange multiplier and safeguard it
    for (size_t i = 0; i < mInequalities; ++i) {
      if (cType[i+mEqualities] == 2) {
	_y(i+mEqualities) += rho * constraintError(i+mEqualities);
        if (_y(i+mEqualities) > 0)
          _y(i+mEqualities) = 0;
      }

      if (cType[i+mEqualities] == 3) {
	double yLB = std::min(0.0, _y(i+mEqualities));
	double yUB = std::max(0.0, _y(i+mEqualities));
	yLB += rho * (constraintValues(i+mEqualities) - cl(i));
	yUB += rho * (constraintValues(i+mEqualities) - cu(i));
	yLB = std::min(0.0, yLB);
	yUB = std::max(0.0, yUB);

	_y(i+mEqualities) = yLB + yUB;

      }

      if (cType[i+mEqualities] == 4) {
        _y(i+mEqualities) += rho * constraintError(i+mEqualities);
 	if (_y(i+mEqualities) < 0)
	  _y(i+mEqualities) = 0;
      }

      if (_y(i+mEqualities) < muMin)
        _y(i+mEqualities) = muMin;
      if (_y(i+mEqualities) > muMax)
	_y(i+mEqualities) = muMax;
    }
    
    //    double factor = constraintErrorNorm;

    double factor = 0;
    // need to have the if there since if there are no equalities Eigen will make a mistake
    if (mEqualities)  factor = constraintError.head(mEqualities).lpNorm<Eigen::Infinity>();

    //    std::cout << "factor = " << factor << std::endl;
    for (size_t i = 0; i < mInequalities; ++i) {
      factor = std::max(std::abs(std::max(constraintError(mEqualities + i), -_y(mEqualities + i) / rho)), factor);
    }
    if (factor > tau * oldFactor) {
      rho *= gamma;
    }
    oldFactor = factor;
  }
  _genoNLP.functionValueAndGradient(_x.data(), _f, dummyG.data());
  return status;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x830, %rsp            # imm = 0x830
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x5f0(%rbp)
movq $0x0, -0x10(%rbp)
movq (%rdi), %rax
movq %rax, -0x600(%rbp)
addq $0x38, %rdi
movq %rdi, -0x5f8(%rbp)
callq 0x13cd0
movq -0x600(%rbp), %rdi
movq %rax, %rsi
movq (%rdi), %rax
movq 0x40(%rax), %rax
callq *%rax
movq -0x5f8(%rbp), %rdx
movq -0x5f0(%rbp), %rax
movq (%rax), %rsi
movsd -0x10(%rbp), %xmm0
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x5e8(%rbp)
callq 0x13cf0
movq -0x5e8(%rbp), %rdi
callq 0x14360
movq %rax, -0x5e0(%rbp)
jmp 0x1267d
movq -0x5e0(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x14380
movq %rax, -0x608(%rbp)
jmp 0x126a0
movq -0x608(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x143a0
movq %rax, -0x610(%rbp)
jmp 0x126c3
movq -0x610(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x143c0
jmp 0x126d8
leaq -0xf8(%rbp), %rdi
callq 0x144b0
jmp 0x126e6
leaq -0xb0(%rbp), %rdi
callq 0x144d0
movq %rax, -0x618(%rbp)
jmp 0x126fb
movq -0x618(%rbp), %rsi
leaq -0x108(%rbp), %rdi
callq 0x144f0
jmp 0x12710
leaq -0xb0(%rbp), %rdi
callq 0x14520
movq %rax, -0x620(%rbp)
jmp 0x12725
movq -0x620(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x144f0
jmp 0x1273a
movq -0x5f0(%rbp), %rax
movq (%rax), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movq %rax, -0x628(%rbp)
jmp 0x12756
movq -0x628(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x13bd0
jmp 0x12779
movq -0x5f0(%rbp), %rax
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, -0x10(%rbp)
movq 0x18(%rax), %rdx
movzbl 0x60(%rax), %ecx
andl $0x1, %ecx
leaq -0x390(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x24fc0
jmp 0x127ae
movq -0x5f0(%rbp), %rax
movsd 0x50(%rax), %xmm0
movsd 0xf8bbe(%rip), %xmm1    # 0x10b380
ucomisd %xmm1, %xmm0
jne 0x127cf
jp 0x127cf
jmp 0x12909
leaq -0x3b1(%rbp), %rdi
movq %rdi, -0x630(%rbp)
callq 0xa7d0
movq -0x630(%rbp), %rdx
leaq 0xf8bf8(%rip), %rsi     # 0x10b3e8
leaq -0x3b0(%rbp), %rdi
callq 0xe9b0
jmp 0x127fe
movq -0x5f0(%rbp), %rax
movsd 0x50(%rax), %xmm0
leaq -0x390(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0x25b80
jmp 0x1281f
leaq -0x3b0(%rbp), %rdi
callq 0xa8d8
leaq -0x3b1(%rbp), %rdi
callq 0xa4c0
jmp 0x12909
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x13960
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x13954
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x13948
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x1393c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x13930
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x13924
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x128f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x3b0(%rbp), %rdi
callq 0xa8d8
leaq -0x3b1(%rbp), %rdi
callq 0xa4c0
jmp 0x13918
movq -0x5f0(%rbp), %rax
movsd 0x58(%rax), %xmm0
movsd 0xf8a63(%rip), %xmm1    # 0x10b380
ucomisd %xmm1, %xmm0
jne 0x1292a
jp 0x1292a
jmp 0x129d7
leaq -0x3d9(%rbp), %rdi
movq %rdi, -0x638(%rbp)
callq 0xa7d0
movq -0x638(%rbp), %rdx
leaq 0xf8aa3(%rip), %rsi     # 0x10b3ee
leaq -0x3d8(%rbp), %rdi
callq 0xe9b0
jmp 0x12959
movq -0x5f0(%rbp), %rax
movsd 0x58(%rax), %xmm0
leaq -0x390(%rbp), %rdi
leaq -0x3d8(%rbp), %rsi
callq 0x25b80
jmp 0x1297a
leaq -0x3d8(%rbp), %rdi
callq 0xa8d8
leaq -0x3d9(%rbp), %rdi
callq 0xa4c0
jmp 0x129d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x129c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x3d8(%rbp), %rdi
callq 0xa8d8
leaq -0x3d9(%rbp), %rdi
callq 0xa4c0
jmp 0x13918
movsd 0xf89c1(%rip), %xmm0    # 0x10b3a0
movsd %xmm0, -0x3e8(%rbp)
movsd 0xf89a9(%rip), %xmm0    # 0x10b398
movsd %xmm0, -0x3f0(%rbp)
movsd 0xf8989(%rip), %xmm0    # 0x10b388
movsd %xmm0, -0x3f8(%rbp)
movsd 0xf8981(%rip), %xmm0    # 0x10b390
movsd %xmm0, -0x400(%rbp)
movsd 0xf8971(%rip), %xmm0    # 0x10b390
movsd %xmm0, -0x408(%rbp)
movsd 0xf8959(%rip), %xmm0    # 0x10b388
movsd %xmm0, -0x410(%rbp)
movl $0x0, -0x414(%rbp)
movq $0x0, -0x420(%rbp)
movq -0x5f0(%rbp), %rcx
movq -0x420(%rbp), %rax
cmpq 0x48(%rcx), %rax
jae 0x1382e
movq -0x5f0(%rbp), %rax
testb $0x1, 0x60(%rax)
je 0x12ad5
movq 0x18e538(%rip), %rdi    # 0x1a0fb0
leaq 0xf8975(%rip), %rsi     # 0x10b3f4
callq 0xa440
movq %rax, -0x640(%rbp)
jmp 0x12a8d
movq -0x640(%rbp), %rdi
movsd -0x10(%rbp), %xmm0
callq 0xa870
movq %rax, -0x648(%rbp)
jmp 0x12aa7
movq -0x648(%rbp), %rdi
movq 0x18e4ab(%rip), %rsi    # 0x1a0f60
callq 0xa4a0
jmp 0x12abc
jmp 0x12ad5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x13918
movq -0x5f0(%rbp), %rsi
movsd -0x10(%rbp), %xmm0
addq $0x38, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x14540
jmp 0x12af3
leaq -0x390(%rbp), %rdi
callq 0x24690
jmp 0x12b01
leaq -0x390(%rbp), %rdi
callq 0x249e0
movl %eax, -0x64c(%rbp)
jmp 0x12b15
movl -0x64c(%rbp), %eax
movl %eax, -0x414(%rbp)
cmpl $0x0, -0x414(%rbp)
je 0x12b38
cmpl $0x1, -0x414(%rbp)
je 0x12b38
jmp 0x1382e
leaq -0xb0(%rbp), %rdi
callq 0x14580
movq %rax, -0x658(%rbp)
jmp 0x12b4d
movq -0x658(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x145a0
jmp 0x12b62
leaq -0x430(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x144f0
jmp 0x12b77
movq $0x0, -0x438(%rbp)
movq -0x438(%rbp), %rax
cmpq -0xd0(%rbp), %rax
jae 0x12ce6
movq -0x438(%rbp), %rsi
addq -0xb8(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x145d0
cmpl $0x2, (%rax)
jne 0x12c42
movq -0xb8(%rbp), %rsi
movq -0x438(%rbp), %rax
addq %rax, %rsi
leaq -0x430(%rbp), %rdi
callq 0x145f0
movq %rax, -0x660(%rbp)
jmp 0x12bdf
movq -0x660(%rbp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x12c40
movq -0xb8(%rbp), %rsi
movq -0x438(%rbp), %rax
addq %rax, %rsi
leaq -0x430(%rbp), %rdi
callq 0x145f0
movq %rax, -0x668(%rbp)
jmp 0x12c19
movq -0x668(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
jmp 0x12c40
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x1381d
jmp 0x12c42
movq -0x438(%rbp), %rsi
addq -0xb8(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x145d0
cmpl $0x4, (%rax)
jne 0x12ccd
movq -0xb8(%rbp), %rsi
movq -0x438(%rbp), %rax
addq %rax, %rsi
leaq -0x430(%rbp), %rdi
callq 0x145f0
movq %rax, -0x670(%rbp)
jmp 0x12c87
movq -0x670(%rbp), %rax
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
jbe 0x12ccb
movq -0xb8(%rbp), %rsi
movq -0x438(%rbp), %rax
addq %rax, %rsi
leaq -0x430(%rbp), %rdi
callq 0x145f0
movq %rax, -0x678(%rbp)
jmp 0x12cbd
movq -0x678(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
jmp 0x12ccd
jmp 0x12ccf
movq -0x438(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x438(%rbp)
jmp 0x12b82
leaq -0x430(%rbp), %rdi
callq 0x14680
movsd %xmm0, -0x680(%rbp)
jmp 0x12cfc
movsd -0x680(%rbp), %xmm0
movsd %xmm0, -0x440(%rbp)
leaq -0x390(%rbp), %rdi
callq 0x25b40
movq %rax, -0x688(%rbp)
jmp 0x12d21
movq -0x5f0(%rbp), %rdi
addq $0x28, %rdi
callq 0x14700
movq %rax, -0x690(%rbp)
jmp 0x12d3a
movq -0x690(%rbp), %rdx
movq -0x688(%rbp), %rsi
leaq -0x458(%rbp), %rdi
callq 0x146a0
jmp 0x12d56
movq -0x5f0(%rbp), %rdi
addq $0x28, %rdi
leaq -0x458(%rbp), %rsi
callq 0x14740
jmp 0x12d6f
movq -0x5f0(%rbp), %rax
movsd -0x440(%rbp), %xmm1
movsd 0x8(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x12d98
movl $0x2, -0x45c(%rbp)
jmp 0x137ea
movq -0xb8(%rbp), %rdx
leaq -0x4f8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x14810
jmp 0x12db4
leaq -0x4c0(%rbp), %rdi
leaq -0x10(%rbp), %rsi
leaq -0x4f8(%rbp), %rdx
callq 0x14770
jmp 0x12dcd
movq -0x5f0(%rbp), %rsi
addq $0x38, %rsi
movq -0xb8(%rbp), %rdx
leaq -0x530(%rbp), %rdi
callq 0x14810
jmp 0x12ded
leaq -0x530(%rbp), %rdi
leaq -0x4c0(%rbp), %rsi
callq 0x14860
jmp 0x12e02
movq $0x0, -0x538(%rbp)
movq -0x538(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jae 0x12f2e
movq -0x5f0(%rbp), %rdi
addq $0x38, %rdi
movq -0x538(%rbp), %rsi
callq 0x145f0
movq %rax, -0x698(%rbp)
jmp 0x12e41
movq -0x698(%rbp), %rax
movsd (%rax), %xmm1
movsd -0x3f8(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x12e9d
movq -0x5f0(%rbp), %rdi
movsd -0x3f8(%rbp), %xmm0
movsd %xmm0, -0x6a8(%rbp)
addq $0x38, %rdi
movq -0x538(%rbp), %rsi
callq 0x145f0
movq %rax, -0x6a0(%rbp)
jmp 0x12e8a
movq -0x6a0(%rbp), %rax
movsd -0x6a8(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x5f0(%rbp), %rdi
addq $0x38, %rdi
movq -0x538(%rbp), %rsi
callq 0x145f0
movq %rax, -0x6b0(%rbp)
jmp 0x12ebd
movq -0x6b0(%rbp), %rax
movsd (%rax), %xmm0
ucomisd -0x400(%rbp), %xmm0
jbe 0x12f15
movq -0x5f0(%rbp), %rdi
movsd -0x400(%rbp), %xmm0
movsd %xmm0, -0x6c0(%rbp)
addq $0x38, %rdi
movq -0x538(%rbp), %rsi
callq 0x145f0
movq %rax, -0x6b8(%rbp)
jmp 0x12f02
movq -0x6b8(%rbp), %rax
movsd -0x6c0(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x12f17
movq -0x538(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x538(%rbp)
jmp 0x12e0d
leaq -0xb0(%rbp), %rdi
callq 0x148c0
movq %rax, -0x6c8(%rbp)
jmp 0x12f43
movq -0x6c8(%rbp), %rsi
leaq -0x548(%rbp), %rdi
callq 0x144f0
jmp 0x12f58
movq $0x0, -0x550(%rbp)
movq -0x550(%rbp), %rax
cmpq -0xd0(%rbp), %rax
jae 0x1361b
movq -0x550(%rbp), %rsi
addq -0xb8(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x145d0
cmpl $0x2, (%rax)
jne 0x130ce
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x6d8(%rbp)
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
leaq -0xf8(%rbp), %rdi
callq 0x145f0
movq %rax, -0x6d0(%rbp)
jmp 0x12fcd
movq -0x5f0(%rbp), %rdi
movq -0x6d0(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x6e8(%rbp)
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x6e0(%rbp)
jmp 0x1300a
movq -0x5f0(%rbp), %rdi
movq -0x6e0(%rbp), %rax
movsd -0x6e8(%rbp), %xmm2
movsd -0x6d8(%rbp), %xmm0
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x6f0(%rbp)
jmp 0x1305b
movq -0x6f0(%rbp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x130cc
movq -0x5f0(%rbp), %rdi
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x6f8(%rbp)
jmp 0x13099
movq -0x6f8(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
jmp 0x130cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x548(%rbp), %rdi
callq 0xff40
jmp 0x1381d
jmp 0x130ce
movq -0x550(%rbp), %rsi
addq -0xb8(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x145d0
cmpl $0x3, (%rax)
jne 0x133b8
movq -0x5f0(%rbp), %rdi
movq $0x0, -0x560(%rbp)
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x700(%rbp)
jmp 0x13126
movq -0x700(%rbp), %rsi
leaq -0x560(%rbp), %rdi
callq 0x148e0
movq %rax, -0x708(%rbp)
jmp 0x13142
movq -0x5f0(%rbp), %rdi
movq -0x708(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x558(%rbp)
movq $0x0, -0x570(%rbp)
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x710(%rbp)
jmp 0x1318a
movq -0x710(%rbp), %rsi
leaq -0x570(%rbp), %rdi
callq 0x14920
movq %rax, -0x718(%rbp)
jmp 0x131a6
movq -0x718(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x568(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x728(%rbp)
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
leaq -0x548(%rbp), %rdi
callq 0x145f0
movq %rax, -0x720(%rbp)
jmp 0x131ec
movq -0x720(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x738(%rbp)
movq -0x550(%rbp), %rsi
leaq -0x108(%rbp), %rdi
callq 0x145f0
movq %rax, -0x730(%rbp)
jmp 0x1321b
movsd -0x728(%rbp), %xmm0
movsd -0x738(%rbp), %xmm2
movq -0x730(%rbp), %rax
movsd (%rax), %xmm1
subsd %xmm1, %xmm2
movsd -0x558(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x558(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x748(%rbp)
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
leaq -0x548(%rbp), %rdi
callq 0x145f0
movq %rax, -0x740(%rbp)
jmp 0x13285
movq -0x740(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x758(%rbp)
movq -0x550(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x145f0
movq %rax, -0x750(%rbp)
jmp 0x132b4
movsd -0x748(%rbp), %xmm0
movsd -0x758(%rbp), %xmm2
movq -0x750(%rbp), %rax
movsd (%rax), %xmm1
subsd %xmm1, %xmm2
movsd -0x568(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x568(%rbp)
movq $0x0, -0x578(%rbp)
leaq -0x578(%rbp), %rdi
leaq -0x558(%rbp), %rsi
callq 0x148e0
movq %rax, -0x760(%rbp)
jmp 0x13312
movq -0x760(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x558(%rbp)
movq $0x0, -0x580(%rbp)
leaq -0x580(%rbp), %rdi
leaq -0x568(%rbp), %rsi
callq 0x14920
movq %rax, -0x768(%rbp)
jmp 0x1334c
movq -0x5f0(%rbp), %rdi
movq -0x768(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x568(%rbp)
movsd -0x558(%rbp), %xmm0
movsd -0x568(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x778(%rbp)
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x770(%rbp)
jmp 0x133a5
movq -0x770(%rbp), %rax
movsd -0x778(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x550(%rbp), %rsi
addq -0xb8(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x145d0
cmpl $0x4, (%rax)
jne 0x134e6
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x788(%rbp)
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
leaq -0xf8(%rbp), %rdi
callq 0x145f0
movq %rax, -0x780(%rbp)
jmp 0x1340e
movq -0x5f0(%rbp), %rdi
movq -0x780(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x798(%rbp)
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x790(%rbp)
jmp 0x1344b
movq -0x5f0(%rbp), %rdi
movq -0x790(%rbp), %rax
movsd -0x798(%rbp), %xmm2
movsd -0x788(%rbp), %xmm0
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x7a0(%rbp)
jmp 0x1349c
movq -0x7a0(%rbp), %rax
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
jbe 0x134e4
movq -0x5f0(%rbp), %rdi
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x7a8(%rbp)
jmp 0x134d6
movq -0x7a8(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
jmp 0x134e6
movq -0x5f0(%rbp), %rdi
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x7b0(%rbp)
jmp 0x13510
movq -0x7b0(%rbp), %rax
movsd (%rax), %xmm1
movsd -0x410(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x13576
movq -0x5f0(%rbp), %rdi
movsd -0x410(%rbp), %xmm0
movsd %xmm0, -0x7c0(%rbp)
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x7b8(%rbp)
jmp 0x13563
movq -0x7b8(%rbp), %rax
movsd -0x7c0(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x5f0(%rbp), %rdi
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x7c8(%rbp)
jmp 0x135a0
movq -0x7c8(%rbp), %rax
movsd (%rax), %xmm0
ucomisd -0x408(%rbp), %xmm0
jbe 0x13602
movq -0x5f0(%rbp), %rdi
movsd -0x408(%rbp), %xmm0
movsd %xmm0, -0x7d8(%rbp)
addq $0x38, %rdi
movq -0x550(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x7d0(%rbp)
jmp 0x135ef
movq -0x7d0(%rbp), %rax
movsd -0x7d8(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x13604
movq -0x550(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x550(%rbp)
jmp 0x12f63
xorps %xmm0, %xmm0
movsd %xmm0, -0x588(%rbp)
cmpq $0x0, -0xb8(%rbp)
je 0x13672
movq -0xb8(%rbp), %rdx
leaq -0x5c0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x14810
jmp 0x1364c
leaq -0x5c0(%rbp), %rdi
callq 0x14960
movsd %xmm0, -0x7e0(%rbp)
jmp 0x13662
movsd -0x7e0(%rbp), %xmm0
movsd %xmm0, -0x588(%rbp)
movq $0x0, -0x5c8(%rbp)
movq -0x5c8(%rbp), %rax
cmpq -0xd0(%rbp), %rax
jae 0x13794
movq -0xb8(%rbp), %rsi
movq -0x5c8(%rbp), %rax
addq %rax, %rsi
leaq -0xf8(%rbp), %rdi
callq 0x145f0
movq %rax, -0x7e8(%rbp)
jmp 0x136b7
movq -0x5f0(%rbp), %rdi
addq $0x38, %rdi
movq -0xb8(%rbp), %rsi
movq -0x5c8(%rbp), %rax
addq %rax, %rsi
callq 0x145f0
movq %rax, -0x7f0(%rbp)
jmp 0x136e1
movq -0x7e8(%rbp), %rdi
movq -0x7f0(%rbp), %rax
movsd (%rax), %xmm0
movaps 0xf7cc6(%rip), %xmm1    # 0x10b3c0
pxor %xmm1, %xmm0
movsd -0x10(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x5d8(%rbp)
leaq -0x5d8(%rbp), %rsi
callq 0x14920
movq %rax, -0x7f8(%rbp)
jmp 0x13724
movq -0x7f8(%rbp), %rax
movsd (%rax), %xmm0
callq 0x14980
movsd %xmm0, -0x800(%rbp)
jmp 0x1373e
movsd -0x800(%rbp), %xmm0
movsd %xmm0, -0x5d0(%rbp)
leaq -0x5d0(%rbp), %rdi
leaq -0x588(%rbp), %rsi
callq 0x14920
movq %rax, -0x808(%rbp)
jmp 0x1376a
movq -0x808(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x588(%rbp)
movq -0x5c8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x5c8(%rbp)
jmp 0x1367d
movsd -0x588(%rbp), %xmm0
movsd -0x3f0(%rbp), %xmm1
mulsd -0x3e8(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x137c4
movsd 0xf7bee(%rip), %xmm0    # 0x10b3a8
mulsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x588(%rbp), %xmm0
movsd %xmm0, -0x3e8(%rbp)
leaq -0x548(%rbp), %rdi
callq 0xff40
movl $0x0, -0x45c(%rbp)
leaq -0x430(%rbp), %rdi
callq 0xff40
movl -0x45c(%rbp), %eax
testl %eax, %eax
je 0x13804
jmp 0x13802
jmp 0x1382e
jmp 0x13806
movq -0x420(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x420(%rbp)
jmp 0x12a4c
leaq -0x430(%rbp), %rdi
callq 0xff40
jmp 0x13918
movq -0x5f0(%rbp), %rdi
movq (%rdi), %rax
movq %rax, -0x818(%rbp)
addq $0x28, %rdi
callq 0x13cd0
movq %rax, -0x810(%rbp)
jmp 0x13851
movq -0x5f0(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x828(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x13cd0
movq %rax, -0x820(%rbp)
jmp 0x13878
movq -0x820(%rbp), %rcx
movq -0x828(%rbp), %rdx
movq -0x810(%rbp), %rsi
movq -0x818(%rbp), %rdi
movq (%rdi), %rax
movq 0x48(%rax), %rax
callq *%rax
jmp 0x1389f
movl -0x414(%rbp), %eax
movl %eax, -0x82c(%rbp)
movl $0x1, -0x45c(%rbp)
leaq -0x390(%rbp), %rdi
callq 0x149a0
leaq -0x128(%rbp), %rdi
callq 0xff40
leaq -0x118(%rbp), %rdi
callq 0xff40
leaq -0x108(%rbp), %rdi
callq 0xff40
leaq -0xf8(%rbp), %rdi
callq 0xff40
leaq -0xe8(%rbp), %rdi
callq 0x14b50
leaq -0xb0(%rbp), %rdi
callq 0x14bb0
movl -0x82c(%rbp), %eax
addq $0x830, %rsp            # imm = 0x830
popq %rbp
retq
leaq -0x390(%rbp), %rdi
callq 0x149a0
leaq -0x128(%rbp), %rdi
callq 0xff40
leaq -0x118(%rbp), %rdi
callq 0xff40
leaq -0x108(%rbp), %rdi
callq 0xff40
leaq -0xf8(%rbp), %rdi
callq 0xff40
leaq -0xe8(%rbp), %rdi
callq 0x14b50
leaq -0xb0(%rbp), %rdi
callq 0x14bb0
movq -0xc0(%rbp), %rdi
callq 0xa7c0
nopl (%rax,%rax)