// File: pitzl[P]bobyqa/bobyqa.cc
// Function: update(long, long, double*, double*, long, double*, double, double, long, double*)
static void
update(const INTEGER n, const INTEGER npt, REAL* bmat,
       REAL* zmat, const INTEGER ndim, REAL* vlag, const REAL beta,
       const REAL denom, const INTEGER knew, REAL* w)
{
  /* The arrays BMAT and ZMAT are updated, as required by the new position of
     the interpolation point that has the index KNEW.  The vector VLAG has
     N+NPT components, set on entry to the first NPT and last N components of
     the product Hw in equation (4.11) of the Powell (2006) paper on NEWUOA.
     Further, BETA is set on entry to the value of the parameter with that
     name, and DENOM is set to the denominator of the updating formula.
     Elements of ZMAT may be treated as zero if their moduli are at most ZTEST.
     The first NDIM elements of W are used for working space. */

  /* Constants. */
  const REAL one = 1.0;
  const REAL zero = 0.0;

  /* Local variables. */
  REAL alpha, tau, temp, tempa, tempb, ztest;
  INTEGER i, j, jp, k, nptm;

  /* Parameter adjustments to comply with FORTRAN indexing. */
  zmat -= 1 + npt;
  bmat -= 1 + ndim;
  vlag -= 1;
  w    -= 1;
#define BMAT(a1,a2) bmat[(a2)*ndim + a1]
#define ZMAT(a1,a2) zmat[(a2)*npt + a1]

  /* Initialization. */
  nptm = npt - n - 1;
  ztest = zero;
  LOOP(k,npt ) {
    LOOP(j,nptm ) {
      temp = ABS(ZMAT(k,j));
      ztest = MAX(ztest, temp);
    }
  }
  ztest *= 1e-20;

  /* Apply the rotations that put zeros in the KNEW-th row of ZMAT. */
  for( j = 2; j <= nptm; ++j ) {
    if( ABS(ZMAT(knew,j)) > ztest ) {
      tempa = ZMAT(knew,1);
      tempb = ZMAT(knew,j);
      temp = SQRT(tempa*tempa + tempb*tempb);
      tempa /= temp;
      tempb /= temp;
      LOOP(i,npt ) {
        temp = tempa*ZMAT(i,1) + tempb*ZMAT(i,j);
        ZMAT(i,j) = tempa*ZMAT(i,j) - tempb*ZMAT(i,1);
        ZMAT(i,1) = temp;
      }
    }
    ZMAT(knew, j) = zero;
  }

  /* Put the first NPT components of the KNEW-th column of HLAG into W, and
     calculate the parameters of the updating formula. */
  LOOP(i,npt ) {
    w[i] = ZMAT(knew,1)*ZMAT(i,1);
  }
  alpha = w[knew];
  tau = vlag[knew];
  vlag[knew] -= one;

  /* Complete the updating of ZMAT. */
  temp = SQRT(denom);
  tempb = ZMAT(knew,1)/temp;
  tempa = tau/temp;
  LOOP(i,npt ) {
    ZMAT(i,1) = tempa*ZMAT(i,1) - tempb*vlag[i];
  }

  /* Finally, update the matrix BMAT. */
  LOOP(j,n ) {
    jp = npt + j;
    w[jp] = BMAT(knew, j);
    tempa = (alpha*vlag[jp] - tau*w[jp])/denom;
    tempb = (-beta*w[jp] - tau*vlag[jp])/denom;
    LOOP(i,jp ) {
      BMAT(i,j) = BMAT(i,j) + tempa*vlag[i] + tempb*w[i];
      if( i > npt ) {
        BMAT(jp, i - npt) = BMAT(i,j);
      }
    }
  }
}

// Assembly:
subq $0xb8, %rsp
movq 0xc8(%rsp), %rax
movq 0xc0(%rsp), %rax
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movq %rcx, 0x98(%rsp)
movq %r8, 0x90(%rsp)
movq %r9, 0x88(%rsp)
movsd %xmm0, 0x80(%rsp)
movsd %xmm1, 0x78(%rsp)
movsd 0x140a(%rip), %xmm0     # 0x11018
movsd %xmm0, 0x70(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
movq 0xa8(%rsp), %rdx
addq $0x1, %rdx
movq 0x98(%rsp), %rax
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x98(%rsp)
movq 0x90(%rsp), %rdx
addq $0x1, %rdx
movq 0xa0(%rsp), %rax
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xa0(%rsp)
movq 0x88(%rsp), %rax
addq $-0x8, %rax
movq %rax, 0x88(%rsp)
movq 0xc8(%rsp), %rax
addq $-0x8, %rax
movq %rax, 0xc8(%rsp)
movq 0xa8(%rsp), %rax
subq 0xb0(%rsp), %rax
subq $0x1, %rax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movq $0x1, 0x18(%rsp)
movq 0x18(%rsp), %rax
cmpq 0xa8(%rsp), %rax
jg 0xfd75
movq $0x1, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x10(%rsp), %rax
jg 0xfd60
movq 0x98(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq 0xa8(%rsp), %rcx
addq 0x18(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movaps 0x13a1(%rip), %xmm1     # 0x110b0
pand %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x38(%rsp), %xmm0
ucomisd 0x50(%rsp), %xmm0
jb 0xfd35
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0xfd41
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0xfcdc
jmp 0xfd62
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x18(%rsp)
jmp 0xfcc0
movsd 0x132b(%rip), %xmm0     # 0x110a8
mulsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq $0x2, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x10(%rsp), %rax
jg 0xfff2
movq 0x98(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq 0xa8(%rsp), %rcx
addq 0xc0(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movaps 0x12e4(%rip), %xmm1     # 0x110b0
pand %xmm1, %xmm0
ucomisd 0x38(%rsp), %xmm0
jbe 0xffb9
movq 0x98(%rsp), %rax
movq 0xa8(%rsp), %rcx
shlq $0x0, %rcx
addq 0xc0(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x98(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq 0xa8(%rsp), %rcx
addq 0xc0(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x48(%rsp), %xmm0
movsd 0x48(%rsp), %xmm2
movsd 0x40(%rsp), %xmm1
mulsd 0x40(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x1030
movsd %xmm0, 0x50(%rsp)
movsd 0x50(%rsp), %xmm1
movsd 0x48(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x50(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq $0x1, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0xa8(%rsp), %rax
jg 0xffb7
movsd 0x48(%rsp), %xmm0
movq 0x98(%rsp), %rax
movq 0xa8(%rsp), %rcx
shlq $0x0, %rcx
addq 0x30(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd 0x40(%rsp), %xmm1
movq 0x98(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq 0xa8(%rsp), %rcx
addq 0x30(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x48(%rsp), %xmm0
movq 0x98(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq 0xa8(%rsp), %rcx
addq 0x30(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd 0x40(%rsp), %xmm1
movq 0x98(%rsp), %rax
movq 0xa8(%rsp), %rcx
shlq $0x0, %rcx
addq 0x30(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x98(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq 0xa8(%rsp), %rcx
addq 0x30(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x50(%rsp), %xmm0
movq 0x98(%rsp), %rax
movq 0xa8(%rsp), %rcx
shlq $0x0, %rcx
addq 0x30(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0xfe8c
jmp 0xffb9
movq 0x98(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq 0xa8(%rsp), %rcx
addq 0xc0(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0xfd92
movq $0x1, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0xa8(%rsp), %rax
jg 0x1006b
movq 0x98(%rsp), %rax
movq 0xa8(%rsp), %rcx
shlq $0x0, %rcx
addq 0xc0(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x98(%rsp), %rax
movq 0xa8(%rsp), %rcx
shlq $0x0, %rcx
addq 0x30(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movq 0xc8(%rsp), %rax
movq 0x30(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0xfffb
movq 0xc8(%rsp), %rax
movq 0xc0(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x88(%rsp), %rax
movq 0xc0(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0x88(%rsp), %rax
movq 0xc0(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0xf5a(%rip), %xmm1      # 0x11018
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movsd 0x78(%rsp), %xmm0
callq 0x1030
movsd %xmm0, 0x50(%rsp)
movq 0x98(%rsp), %rax
movq 0xa8(%rsp), %rcx
shlq $0x0, %rcx
addq 0xc0(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x58(%rsp), %xmm0
divsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movq $0x1, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0xa8(%rsp), %rax
jg 0x101bf
movsd 0x48(%rsp), %xmm0
movq 0x98(%rsp), %rax
movq 0xa8(%rsp), %rcx
shlq $0x0, %rcx
addq 0x30(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd 0x40(%rsp), %xmm1
movq 0x88(%rsp), %rax
movq 0x30(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x98(%rsp), %rax
movq 0xa8(%rsp), %rcx
shlq $0x0, %rcx
addq 0x30(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x10120
movq $0x1, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0xb0(%rsp), %rax
jg 0x1040c
movq 0xa8(%rsp), %rax
addq 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xa0(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq 0x90(%rsp), %rcx
addq 0xc0(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0xc8(%rsp), %rax
movq 0x20(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x60(%rsp), %xmm0
movq 0x88(%rsp), %rax
movq 0x20(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd 0x58(%rsp), %xmm1
movq 0xc8(%rsp), %rax
movq 0x20(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x80(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq 0xc8(%rsp), %rax
movq 0x20(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd 0x58(%rsp), %xmm1
movq 0x88(%rsp), %rax
movq 0x20(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movq $0x1, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0x20(%rsp), %rax
jg 0x103f7
movq 0xa0(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq 0x90(%rsp), %rcx
addq 0x30(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x48(%rsp), %xmm1
movq 0x88(%rsp), %rax
movq 0x30(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x40(%rsp), %xmm0
movq 0xc8(%rsp), %rax
movq 0x30(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0xa0(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq 0x90(%rsp), %rcx
addq 0x30(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x30(%rsp), %rax
cmpq 0xa8(%rsp), %rax
jle 0x103e2
movq 0xa0(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq 0x90(%rsp), %rcx
addq 0x30(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0xa0(%rsp), %rax
movq 0x30(%rsp), %rcx
subq 0xa8(%rsp), %rcx
imulq 0x90(%rsp), %rcx
addq 0x20(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x103e4
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x102fb
jmp 0x103f9
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x101c8
addq $0xb8, %rsp
retq