// File: /workspace/github_c_makefile_star2_O3/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 $0x78, %rsp
movq %rcx, 0x58(%rsp)
movq %rdx, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq %rdi, 0x30(%rsp)
cmpl $0x0, 0x14(%rdi)
jle 0x52f0
movq %r8, %rbx
movq 0x30(%rsp), %rax
movl 0x10(%rax), %r14d
movsd 0x20(%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq (%rax), %rcx
movq %rcx, 0x50(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x38(%rsp)
movq 0x28(%rax), %r15
xorl %ecx, %ecx
movsd 0x3662(%rip), %xmm1     # 0x87e0
movsd 0x3662(%rip), %xmm0     # 0x87e8
movsd %xmm0, 0x20(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movl %r14d, 0x8(%rsp)
movq %r8, 0x28(%rsp)
movq 0x60(%rsp), %rbp
movq 0x68(%rsp), %r12
movq 0x58(%rsp), %r13
movsd %xmm1, 0x10(%rsp)
movl %ecx, 0xc(%rsp)
movl %r14d, %edi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x4ad4
movl %r14d, %edi
movsd 0x10(%rsp), %xmm0
movq %r12, %rsi
movq %rbx, %rdx
callq 0x4b5b
movq %rbx, %rdi
movq %r13, %rsi
movq 0x50(%rsp), %rbx
callq *%rbx
movsd %xmm0, 0x70(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq *0x38(%rsp)
movl %r14d, %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x4b78
movsd %xmm0, 0x40(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq *%rbx
addsd 0x40(%rsp), %xmm0
movsd 0x70(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x525a
movsd 0x10(%rsp), %xmm1
movapd %xmm1, %xmm0
addsd 0x18(%rsp), %xmm0
mulsd 0x319f(%rip), %xmm0     # 0x83e0
movsd %xmm1, 0x20(%rsp)
movq 0x28(%rsp), %rbx
movl 0x8(%rsp), %r14d
movl 0xc(%rsp), %ecx
jmp 0x52dc
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq *0x38(%rsp)
movl 0x8(%rsp), %r14d
movl %r14d, %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x4b78
movsd 0x40(%rsp), %xmm1
mulsd 0x48(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movl 0xc(%rsp), %ecx
movsd 0x10(%rsp), %xmm4
jbe 0x52f0
movapd %xmm4, %xmm1
addsd %xmm4, %xmm1
movapd %xmm4, %xmm2
movsd 0x20(%rsp), %xmm3
addsd %xmm3, %xmm2
mulsd 0x3127(%rip), %xmm2     # 0x83e0
movsd 0x309f(%rip), %xmm0     # 0x8360
cmpltsd %xmm3, %xmm0
movapd %xmm0, %xmm3
andnpd %xmm2, %xmm3
andpd %xmm1, %xmm0
orpd %xmm3, %xmm0
movsd %xmm4, 0x18(%rsp)
incl %ecx
movapd %xmm0, %xmm1
movq 0x30(%rsp), %rax
cmpl 0x14(%rax), %ecx
jl 0x51af
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop