// File: /workspace/github_cpp_makefile_star2_O2/canzarlab[P]Trajan/geno/augmentedLagrangian.cpp
// Function: AugmentedNLP::functionValueAndGradient(double const*, double&, double*)
virtual bool functionValueAndGradient(const Scalar* x,
					Scalar& functionValue,
					Scalar* gradient)
  {
    _genoNLP.functionValueAndGradient(x, functionValue, gradient);

    _genoNLP.functionValueConstraints(x, _constraintValues.data());

    computeConstraintError();
    
    Vector toAdd(_constraintError);
    // for equality constraints
    toAdd.head(_mEqualities) += _y.head(_mEqualities) / _rho;

    // for inequality constraints
    toAdd.tail(_mInequalities) += _y.tail(_mInequalities) / _rho;
    for (size_t i = 0; i < _mInequalities; ++i) {
      if (_cType[i+_mEqualities] == 2)
        if (toAdd(_mEqualities + i) > 0)
          toAdd(_mEqualities + i) = 0;

      if (_cType[i+_mEqualities] == 4)
	if (toAdd(_mEqualities + i) < 0)
	  toAdd(_mEqualities + i) = 0;
    }
    functionValue += _rho/2 * toAdd.squaredNorm();

    Vector::MapType gradientMapX(gradient, _n);
    Vector gradientX(_n);

    Vector v = _rho * toAdd;
    _genoNLP.gradientConstraintsTimesVector(x, v.data(), gradientX.data());

    gradientMapX += gradientX;
    //    std::cout << "const " << _constraintValues.transpose() << std::endl;
    //    std::cout << "toAdd " << toAdd.transpose() << std::endl;
    return true;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rdi), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq 0x8(%r14), %rdi
movq 0x30(%r14), %rdx
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x70(%rax)
movq %r14, %rdi
callq 0xd932
leaq 0x90(%r14), %rsi
movq %rsp, %rdi
callq 0xe746
leaq 0x48(%r14), %rbp
movq 0x20(%r14), %rdx
leaq 0x68(%rsp), %rdi
movq %rbp, %rsi
callq 0xd304
leaq 0x40(%r14), %r13
leaq 0xa0(%rsp), %rdi
leaq 0x68(%rsp), %rsi
movq %r13, %rdx
callq 0xdade
movq 0x20(%r14), %rdx
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0xd304
leaq 0x30(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xdb2e
movq 0x28(%r14), %rdx
leaq 0x68(%rsp), %rdi
movq %rbp, %rsi
callq 0xdb4a
leaq 0xa0(%rsp), %rdi
leaq 0x68(%rsp), %rsi
movq %r13, %rdx
callq 0xdade
movq %r15, 0x18(%rsp)
movq 0x28(%r14), %rdx
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0xdb4a
leaq 0x30(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xdb2e
xorl %r15d, %r15d
movq %rsp, %rbp
cmpq 0x28(%r14), %r15
jae 0xd707
movq 0x20(%r14), %rsi
movq 0x78(%r14), %rcx
leaq (%r15,%rsi), %rax
cmpl $0x2, (%rcx,%rax,4)
jne 0xd6d0
movq %rbp, %rdi
movq %rax, %rsi
callq 0xd27a
movsd (%rax), %xmm0
ucomisd 0x43d51(%rip), %xmm0    # 0x51408
movq 0x20(%r14), %rsi
jbe 0xd6d0
addq %r15, %rsi
movq %rbp, %rdi
callq 0xd27a
andq $0x0, (%rax)
movq 0x20(%r14), %rsi
addq %r15, %rsi
movq 0x78(%r14), %rax
cmpl $0x4, (%rax,%rsi,4)
jne 0xd702
movq %rbp, %rdi
callq 0xd27a
xorpd %xmm0, %xmm0
ucomisd (%rax), %xmm0
jbe 0xd702
movq 0x20(%r14), %rsi
addq %r15, %rsi
movq %rbp, %rdi
callq 0xd27a
andq $0x0, (%rax)
incq %r15
jmp 0xd688
movsd (%r13), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rsp, %rdi
callq 0xdb62
movsd 0x10(%rsp), %xmm1
mulsd 0x43cd7(%rip), %xmm1    # 0x51400
mulsd %xmm0, %xmm1
addsd (%r12), %xmm1
movsd %xmm1, (%r12)
movq 0x10(%r14), %rdx
leaq 0x68(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xe296
leaq 0x10(%r14), %rsi
leaq 0x30(%rsp), %rdi
callq 0xdb7c
leaq 0xa0(%rsp), %rdi
movq %rsp, %rdx
movq %r13, %rsi
callq 0xdbac
leaq 0x20(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xe41c
movq 0x8(%r14), %rdi
movq 0x20(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x78(%rax)
leaq 0x68(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xdc00
movq 0x20(%rsp), %rdi
callq 0x93c0
movq 0x30(%rsp), %rdi
callq 0x93c0
movq (%rsp), %rdi
callq 0x93c0
movb $0x1, %al
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xd802
jmp 0xd802
jmp 0xd802
movq %rax, %rbx
movq 0x20(%rsp), %rdi
callq 0x93c0
jmp 0xd7ee
movq %rax, %rbx
movq 0x30(%rsp), %rdi
callq 0x93c0
jmp 0xd805
jmp 0xd802
jmp 0xd802
jmp 0xd802
jmp 0xd802
movq %rax, %rbx
movq (%rsp), %rdi
callq 0x93c0
movq %rbx, %rdi
callq 0x9640