// File: /workspace/github_c_makefile_star2_O1/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 %rdx, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdi, 0x28(%rsp)
cmpl $0x0, 0x14(%rdi)
jle 0x5313
movq %r8, %rbx
movq %rcx, %r13
movq 0x28(%rsp), %rax
movl 0x10(%rax), %r12d
movsd 0x20(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq (%rax), %rcx
movq %rcx, 0x48(%rsp)
movq 0x8(%rax), %rcx
movq 0x28(%rax), %r15
xorl %edx, %edx
movsd 0x367d(%rip), %xmm1     # 0x87f0
movsd 0x367d(%rip), %xmm0     # 0x87f8
movsd %xmm0, 0x18(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rcx, 0x30(%rsp)
movl %r12d, 0x4(%rsp)
movq %r8, 0x20(%rsp)
movsd %xmm1, 0x10(%rsp)
movl %edx, (%rsp)
movl %r12d, %edi
movq %r13, %rbp
movq 0x50(%rsp), %r13
movq %r13, %rsi
movq %rbx, %rdx
callq 0x4b04
movl %r12d, %edi
movsd 0x10(%rsp), %xmm0
movq 0x58(%rsp), %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0x4b8b
movq %rbx, %rdi
movq %rbp, %rsi
movq 0x48(%rsp), %rbx
callq *%rbx
movsd %xmm0, 0x60(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq *0x30(%rsp)
movl %r12d, %edi
movq %r14, %r12
movq %r15, %rsi
movq %r14, %rdx
callq 0x4ba8
movsd %xmm0, 0x38(%rsp)
movq %r13, %rdi
movq %rbp, %r13
movq %rbp, %rsi
callq *%rbx
movsd 0x38(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd 0x60(%rsp), %xmm2
ucomisd %xmm0, %xmm2
jbe 0x525c
movsd 0x10(%rsp), %xmm0
movapd %xmm0, %xmm1
addsd 0x8(%rsp), %xmm1
mulsd 0x31ae(%rip), %xmm1     # 0x83f0
xorl %eax, %eax
movsd %xmm0, 0x18(%rsp)
movq 0x20(%rsp), %rbx
movl 0x4(%rsp), %r12d
movl (%rsp), %edx
jmp 0x52ff
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq 0x30(%rsp), %r14
callq *%r14
movl 0x4(%rsp), %ebp
movl %ebp, %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x4ba8
movsd 0x38(%rsp), %xmm6
mulsd 0x40(%rsp), %xmm6
movl $0x2, %eax
ucomisd %xmm0, %xmm6
movl %ebp, %r12d
jbe 0x52e2
movsd 0x10(%rsp), %xmm5
movapd %xmm5, %xmm2
addsd %xmm5, %xmm2
movapd %xmm5, %xmm3
movsd 0x18(%rsp), %xmm4
addsd %xmm4, %xmm3
mulsd 0x312f(%rip), %xmm3     # 0x83f0
movsd 0x30a7(%rip), %xmm1     # 0x8370
cmpltsd %xmm4, %xmm1
movapd %xmm1, %xmm4
andnpd %xmm3, %xmm4
andpd %xmm2, %xmm1
orpd %xmm4, %xmm1
xorl %eax, %eax
jmp 0x52ee
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm5
movl (%rsp), %edx
ucomisd %xmm0, %xmm6
jbe 0x52f9
xorl %eax, %eax
movsd %xmm5, 0x8(%rsp)
testl %eax, %eax
jne 0x5313
incl %edx
movq 0x28(%rsp), %rax
cmpl 0x14(%rax), %edx
jl 0x519a
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop