// File: /workspace/github_c_makefile_star2_O2/aligusnet[P]morpheus/src/wolfe.c
// Function: morpheus_wolfe
void morpheus_wolfe(const morheus_wolfe_params_t *params,
                    const double *x,
                    const double *direction,
                    void *data,
                    double *values) {
  double alpha = 0;
  double beta = BIG_VALUE*10;
  double step = 5;
  int n = params->num_variables;
  double c1 = params->c1;
  double c2 = params->c2;
  morpheus_f f = params->f;
  morpheus_df df = params->df;
  double *grad = params->memory_buffer;

  for (int i = 0; i < params->max_iters; ++i) {
    morpheus_dcopy(n, x, values);
    morpheus_daxpy(n, step, direction, values);
    double left = f(values, data);
    df(x, data, grad);
    double grad_ddot_direction = morpheus_ddot(n, grad, direction);
    double right = f(x, data) + grad_ddot_direction;
    if (left > right) {
      beta = step;
      step = (alpha + beta) * 0.5;
    } else {
      df(values, data, grad);
      double grad_next_ddot_direction = morpheus_ddot(n, grad, direction);
      if (grad_next_ddot_direction < c2*grad_ddot_direction) {
        alpha = step;
        if (beta > BIG_VALUE) {
          step = 2*alpha;
        } else {
          step = (alpha + beta) * 0.5;
        }
      } else {
        break;
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, %r15
movq %rcx, %r13
movq %rdx, 0x30(%rsp)
movq %rsi, 0x50(%rsp)
movl 0x10(%rdi), %ebp
movsd 0x20(%rdi), %xmm0
movsd %xmm0, 0x40(%rsp)
movq (%rdi), %rax
movq %rax, 0x48(%rsp)
movq 0x8(%rdi), %rax
movq %rax, 0x28(%rsp)
movq %rdi, 0x58(%rsp)
movq 0x28(%rdi), %rbx
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x3aa9(%rip), %xmm0     # 0x87e0
movsd %xmm0, 0x18(%rsp)
movsd 0x3aa3(%rip), %xmm0     # 0x87e8
xorl %edx, %edx
movl %ebp, (%rsp)
movq %r8, 0x20(%rsp)
movq 0x30(%rsp), %r14
movq 0x58(%rsp), %rax
cmpl 0x14(%rax), %edx
jge 0x4ea2
movl %edx, 0x4(%rsp)
movl %ebp, %edi
movl %ebp, %r12d
movq %r13, %rbp
movq 0x50(%rsp), %r13
movq %r13, %rsi
movq %r15, %rdx
movsd %xmm0, 0x8(%rsp)
callq 0x46fa
movl %r12d, %edi
movsd 0x8(%rsp), %xmm0
movq %r14, %rsi
movq %r15, %rdx
callq 0x4770
movq %r15, %rdi
movq %rbp, %rsi
movq 0x48(%rsp), %r15
callq *%r15
movsd %xmm0, 0x60(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq *0x28(%rsp)
movl %r12d, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4786
movsd %xmm0, 0x38(%rsp)
movq %r13, %rdi
movq %rbp, %r13
movq %rbp, %rsi
callq *%r15
addsd 0x38(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x4e1a
movsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm0
addsd 0x10(%rsp), %xmm0
mulsd 0x35dd(%rip), %xmm0     # 0x83e0
movsd %xmm1, 0x18(%rsp)
movq 0x20(%rsp), %r15
movl (%rsp), %ebp
movl 0x4(%rsp), %edx
jmp 0x4e9b
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq *0x28(%rsp)
movl (%rsp), %ebp
movl %ebp, %edi
movq %rbx, %rsi
movq 0x30(%rsp), %rdx
callq 0x4786
movsd 0x38(%rsp), %xmm1
mulsd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movl 0x4(%rsp), %edx
movsd 0x8(%rsp), %xmm4
jbe 0x4ea2
movapd %xmm4, %xmm1
addsd %xmm4, %xmm1
movapd %xmm4, %xmm2
movsd 0x18(%rsp), %xmm3
addsd %xmm3, %xmm2
mulsd 0x3568(%rip), %xmm2     # 0x83e0
movsd 0x34e0(%rip), %xmm0     # 0x8360
cmpltsd %xmm3, %xmm0
movapd %xmm0, %xmm3
andnpd %xmm2, %xmm3
andpd %xmm1, %xmm0
orpd %xmm3, %xmm0
movsd %xmm4, 0x10(%rsp)
incl %edx
jmp 0x4d54
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)