// File: pitzl[P]bobyqa/bobyqa.cc
// Function: bobyqa(long, long, double (*)(long, double const*, void*), void*, double*, double const*, double const*, double, double, long, long, double*)
int
bobyqa( const INTEGER n, const INTEGER npt,
	bobyqa_objfun* objfun, void* data,
	REAL* x, const REAL* xl, const REAL* xu,
	const REAL rhobeg, const REAL rhoend,
	const INTEGER iprint, const INTEGER maxfun, REAL* w )
{
  /* Constants. */
  const REAL zero = 0.0;

  /* Local variables. */
  REAL temp, tempa, tempb;
  INTEGER ibmat, id, ifv, igo, ihq, ipq, isl, isu, ivl, iw, ixa, ixb, ixn,
    ixo, ixp, izmat, j, jsl, jsu, ndim, np;

  /* Parameter adjustments to comply with FORTRAN indexing. */
  w  -= 1;
  xu -= 1;
  xl -= 1;
  x  -= 1;

  /* Return if the value of NPT is unacceptable. */
  np = n + 1;
  if( npt < n + 2 || npt > (n + 2)*np/2 ) {
    print_error("NPT is not in the required interval");
    return BOBYQA_BAD_NPT;
  }

  /* Partition the working space array, so that different parts of it can
     be treated separately during the calculation of BOBYQB.  The partition
     requires the first (NPT+2)*(NPT+N)+3*N*(N+5)/2 elements of W plus the
     space that is taken by the last array in the argument list of
     BOBYQB. */
  ndim = npt + n;
  ixb = 1;
  ixp = ixb + n;
  ifv = ixp + n*npt;
  ixo = ifv + npt;
  igo = ixo + n;
  ihq = igo + n;
  ipq = ihq + n*np/2;
  ibmat = ipq + npt;
  izmat = ibmat + ndim*n;
  isl = izmat + npt*(npt - np);
  isu = isl + n;
  ixn = isu + n;
  ixa = ixn + n;
  id = ixa + n;
  ivl = id + n;
  iw = ivl + ndim;

  /* Return if there is insufficient space between the bounds.  Modify the
     initial X if necessary in order to avoid conflicts between the bounds and
     the construction of the first quadratic model.  The lower and upper bounds
     on moves from the updated X are set now, in the ISL and ISU partitions of
     W, in order to provide useful and exact information about components of X
     that become within distance RHOBEG from their bounds. */
  LOOP(j,n ) {
    temp = xu[j] - xl[j];
    if( temp < rhobeg + rhobeg ) {
      print_error("one of the differences XU(I)-XL(I) is less than 2*RHOBEG");
      return BOBYQA_TOO_CLOSE;
    }
    jsl = isl + j - 1;
    jsu = jsl + n;
    w[jsl] = xl[j] - x[j];
    w[jsu] = xu[j] - x[j];
    if( w[jsl] >= -rhobeg ) {
      if( w[jsl] >= zero ) {
        x[j] = xl[j];
        w[jsl] = zero;
        w[jsu] = temp;
      }
      else {
        x[j] = xl[j] + rhobeg;
        w[jsl] = -rhobeg;
        temp = xu[j] - x[j];
        w[jsu] = MAX(temp,rhobeg);
      }
    }
    else if( w[jsu] <= rhobeg ) {
      if( w[jsu] <= zero ) {
        x[j] = xu[j];
        w[jsl] = -temp;
        w[jsu] = zero;
      }
      else {
        x[j] = xu[j] - rhobeg;
        tempa = xl[j] - x[j];
        tempb = -rhobeg;
        w[jsl] = MIN(tempa,tempb);
        w[jsu] = rhobeg;
      }
    }
  }

  /* Make the call of BOBYQB. */
  return bobyqb(n, npt, objfun, data, &x[1], &xl[1], &xu[1],
                rhobeg, rhoend, iprint, maxfun,
                &w[ixb], &w[ixp], &w[ifv], &w[ixo], &w[igo],
                &w[ihq], &w[ipq], &w[ibmat], &w[izmat],
                ndim, &w[isl], &w[isu], &w[ixn], &w[ixa],
                &w[id], &w[ivl], &w[iw]);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq 0x288(%rsp), %rax
movq 0x280(%rsp), %rax
movq 0x278(%rsp), %rax
movq 0x270(%rsp), %rax
movq %rdi, 0x228(%rsp)
movq %rsi, 0x220(%rsp)
movq %rdx, 0x218(%rsp)
movq %rcx, 0x210(%rsp)
movq %r8, 0x208(%rsp)
movq %r9, 0x200(%rsp)
movsd %xmm0, 0x1f8(%rsp)
movsd %xmm1, 0x1f0(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x1e8(%rsp)
movq 0x288(%rsp), %rax
addq $-0x8, %rax
movq %rax, 0x288(%rsp)
movq 0x270(%rsp), %rax
addq $-0x8, %rax
movq %rax, 0x270(%rsp)
movq 0x200(%rsp), %rax
addq $-0x8, %rax
movq %rax, 0x200(%rsp)
movq 0x208(%rsp), %rax
addq $-0x8, %rax
movq %rax, 0x208(%rsp)
movq 0x228(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x128(%rsp)
movq 0x220(%rsp), %rax
movq 0x228(%rsp), %rcx
addq $0x2, %rcx
cmpq %rcx, %rax
jl 0x125b
movq 0x220(%rsp), %rax
movq %rax, 0x120(%rsp)
movq 0x228(%rsp), %rax
addq $0x2, %rax
imulq 0x128(%rsp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq 0x120(%rsp), %rax
cmpq %rcx, %rax
jle 0x1277
leaq 0xfe5e(%rip), %rdi      # 0x110c0
callq 0x1c90
movl $0xffffffff, 0x234(%rsp) # imm = 0xFFFFFFFF
jmp 0x1c68
movq 0x220(%rsp), %rax
addq 0x228(%rsp), %rax
movq %rax, 0x130(%rsp)
movq $0x1, 0x170(%rsp)
movq 0x170(%rsp), %rax
addq 0x228(%rsp), %rax
movq %rax, 0x158(%rsp)
movq 0x158(%rsp), %rax
movq 0x228(%rsp), %rcx
imulq 0x220(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x1b8(%rsp)
movq 0x1b8(%rsp), %rax
addq 0x220(%rsp), %rax
movq %rax, 0x160(%rsp)
movq 0x160(%rsp), %rax
addq 0x228(%rsp), %rax
movq %rax, 0x1b0(%rsp)
movq 0x1b0(%rsp), %rax
addq 0x228(%rsp), %rax
movq %rax, 0x1a8(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x228(%rsp), %rax
imulq 0x128(%rsp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq 0x118(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x1a0(%rsp)
movq 0x1a0(%rsp), %rax
addq 0x220(%rsp), %rax
movq %rax, 0x1c8(%rsp)
movq 0x1c8(%rsp), %rax
movq 0x130(%rsp), %rcx
imulq 0x228(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x150(%rsp)
movq 0x150(%rsp), %rax
movq 0x220(%rsp), %rcx
movq 0x220(%rsp), %rdx
subq 0x128(%rsp), %rdx
imulq %rdx, %rcx
addq %rcx, %rax
movq %rax, 0x198(%rsp)
movq 0x198(%rsp), %rax
addq 0x228(%rsp), %rax
movq %rax, 0x190(%rsp)
movq 0x190(%rsp), %rax
addq 0x228(%rsp), %rax
movq %rax, 0x168(%rsp)
movq 0x168(%rsp), %rax
addq 0x228(%rsp), %rax
movq %rax, 0x178(%rsp)
movq 0x178(%rsp), %rax
addq 0x228(%rsp), %rax
movq %rax, 0x1c0(%rsp)
movq 0x1c0(%rsp), %rax
addq 0x228(%rsp), %rax
movq %rax, 0x188(%rsp)
movq 0x188(%rsp), %rax
addq 0x130(%rsp), %rax
movq %rax, 0x180(%rsp)
movq $0x1, 0x148(%rsp)
movq 0x148(%rsp), %rax
cmpq 0x228(%rsp), %rax
jg 0x193f
movq 0x270(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x200(%rsp), %rax
movq 0x148(%rsp), %rcx
subsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x1e0(%rsp)
movsd 0x1e0(%rsp), %xmm1
movsd 0x1f8(%rsp), %xmm0
addsd 0x1f8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x14ed
leaq 0xfc0c(%rip), %rdi      # 0x110e4
callq 0x1c90
movl $0xfffffffe, 0x234(%rsp) # imm = 0xFFFFFFFE
jmp 0x1c68
movq 0x198(%rsp), %rax
addq 0x148(%rsp), %rax
subq $0x1, %rax
movq %rax, 0x140(%rsp)
movq 0x140(%rsp), %rax
addq 0x228(%rsp), %rax
movq %rax, 0x138(%rsp)
movq 0x200(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x208(%rsp), %rax
movq 0x148(%rsp), %rcx
subsd (%rax,%rcx,8), %xmm0
movq 0x288(%rsp), %rax
movq 0x140(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x270(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x208(%rsp), %rax
movq 0x148(%rsp), %rcx
subsd (%rax,%rcx,8), %xmm0
movq 0x288(%rsp), %rax
movq 0x138(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x288(%rsp), %rax
movq 0x140(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x1f8(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1759
movq 0x288(%rsp), %rax
movq 0x140(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1661
movq 0x200(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x208(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x288(%rsp), %rax
movq 0x140(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movsd 0x1e0(%rsp), %xmm0
movq 0x288(%rsp), %rax
movq 0x138(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x1754
movq 0x200(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd 0x1f8(%rsp), %xmm0
movq 0x208(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x1f8(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq 0x288(%rsp), %rax
movq 0x140(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x270(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x208(%rsp), %rax
movq 0x148(%rsp), %rcx
subsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x1e0(%rsp)
movsd 0x1e0(%rsp), %xmm0
ucomisd 0x1f8(%rsp), %xmm0
jb 0x1724
movsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x110(%rsp)
jmp 0x1736
movsd 0x1f8(%rsp), %xmm0
movsd %xmm0, 0x110(%rsp)
movsd 0x110(%rsp), %xmm0
movq 0x288(%rsp), %rax
movq 0x138(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x1924
movq 0x288(%rsp), %rax
movq 0x138(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x1f8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x1922
movq 0x288(%rsp), %rax
movq 0x138(%rsp), %rcx
xorps %xmm0, %xmm0
ucomisd (%rax,%rcx,8), %xmm0
jb 0x1817
movq 0x270(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x208(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x1e0(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq 0x288(%rsp), %rax
movq 0x140(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x288(%rsp), %rax
movq 0x138(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x1920
movq 0x270(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd 0x1f8(%rsp), %xmm0
movq 0x208(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x200(%rsp), %rax
movq 0x148(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x208(%rsp), %rax
movq 0x148(%rsp), %rcx
subsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x1d8(%rsp)
movsd 0x1f8(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x1d0(%rsp)
movsd 0x1d8(%rsp), %xmm1
movsd 0x1d0(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x18d2
movsd 0x1d8(%rsp), %xmm0
movsd %xmm0, 0x108(%rsp)
jmp 0x18e4
movsd 0x1d0(%rsp), %xmm0
movsd %xmm0, 0x108(%rsp)
movsd 0x108(%rsp), %xmm0
movq 0x288(%rsp), %rax
movq 0x140(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x1f8(%rsp), %xmm0
movq 0x288(%rsp), %rax
movq 0x138(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x1922
jmp 0x1924
jmp 0x1926
movq 0x148(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x148(%rsp)
jmp 0x1467
movq 0x228(%rsp), %rdi
movq 0x220(%rsp), %rsi
movq 0x218(%rsp), %rdx
movq 0x210(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x208(%rsp), %r8
addq $0x8, %r8
movq 0x200(%rsp), %r9
addq $0x8, %r9
movq 0x270(%rsp), %rax
addq $0x8, %rax
movq %rax, 0xa8(%rsp)
movsd 0x1f8(%rsp), %xmm0
movsd 0x1f0(%rsp), %xmm1
movq 0x278(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0x280(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x288(%rsp), %rax
movq 0x170(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xc0(%rsp)
movq 0x288(%rsp), %rax
movq 0x158(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xc8(%rsp)
movq 0x288(%rsp), %rax
movq 0x1b8(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xd0(%rsp)
movq 0x288(%rsp), %rax
movq 0x160(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xd8(%rsp)
movq 0x288(%rsp), %rax
movq 0x1b0(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xe0(%rsp)
movq 0x288(%rsp), %rax
movq 0x1a8(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xe8(%rsp)
movq 0x288(%rsp), %rax
movq 0x1a0(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xf0(%rsp)
movq 0x288(%rsp), %rax
movq 0x1c8(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xf8(%rsp)
movq 0x288(%rsp), %rbp
movq 0x150(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rbp
movq 0x130(%rsp), %r13
movq 0x288(%rsp), %r12
movq 0x198(%rsp), %rax
shlq $0x3, %rax
addq %rax, %r12
movq 0x288(%rsp), %r15
movq 0x190(%rsp), %rax
shlq $0x3, %rax
addq %rax, %r15
movq 0x288(%rsp), %r14
movq 0x168(%rsp), %rax
shlq $0x3, %rax
addq %rax, %r14
movq 0x288(%rsp), %rbx
movq 0x178(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rbx
movq 0x288(%rsp), %r11
movq 0x1c0(%rsp), %rax
shlq $0x3, %rax
addq %rax, %r11
movq 0x288(%rsp), %r10
movq 0x188(%rsp), %rax
shlq $0x3, %rax
addq %rax, %r10
movq 0x288(%rsp), %rax
movq 0x180(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq 0xa0(%rsp), %rcx
movq %rax, 0x100(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, (%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x100(%rsp), %rax
movq %rbp, 0x58(%rsp)
movq %r13, 0x60(%rsp)
movq %r12, 0x68(%rsp)
movq %r15, 0x70(%rsp)
movq %r14, 0x78(%rsp)
movq %rbx, 0x80(%rsp)
movq %r11, 0x88(%rsp)
movq %r10, 0x90(%rsp)
movq %rax, 0x98(%rsp)
callq 0x1cc0
movl %eax, 0x234(%rsp)
movl 0x234(%rsp), %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)