// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq %rdx, 0x80(%rsp)
movq %rcx, 0x78(%rsp)
movq %r8, 0x70(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x5b56(%rip), %xmm0     # 0xd180
movsd %xmm0, 0x60(%rsp)
movsd 0x4660(%rip), %xmm0     # 0xbc98
movsd %xmm0, 0x58(%rsp)
movq 0x90(%rsp), %rax
movl 0x10(%rax), %eax
movl %eax, 0x54(%rsp)
movq 0x90(%rsp), %rax
movsd 0x18(%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x90(%rsp), %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x90(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x90(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x90(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
movq 0x90(%rsp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x7851
movl 0x54(%rsp), %edi
movq 0x88(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x6950
movl 0x54(%rsp), %edi
movsd 0x58(%rsp), %xmm0
movq 0x80(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x6a90
movq 0x38(%rsp), %rax
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq *%rax
movsd %xmm0, 0x18(%rsp)
movq 0x30(%rsp), %rax
movq 0x88(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq *%rax
movl 0x54(%rsp), %edi
movq 0x28(%rsp), %rsi
movq 0x80(%rsp), %rdx
callq 0x6b10
movsd %xmm0, 0x10(%rsp)
movq 0x38(%rsp), %rax
movq 0x88(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq *%rax
addsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x18(%rsp), %xmm0
ucomisd 0x8(%rsp), %xmm0
jbe 0x779d
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x68(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
movsd 0x55f2(%rip), %xmm1     # 0xcd80
mulsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
jmp 0x783f
movq 0x30(%rsp), %rax
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq *%rax
movl 0x54(%rsp), %edi
movq 0x28(%rsp), %rsi
movq 0x80(%rsp), %rdx
callq 0x6b10
movsd %xmm0, (%rsp)
movsd (%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
mulsd 0x10(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x783b
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x60(%rsp), %xmm0
movsd 0x5511(%rip), %xmm1     # 0xcd10
ucomisd %xmm1, %xmm0
jbe 0x781b
movsd 0x3dab(%rip), %xmm0     # 0xb5b8
mulsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
jmp 0x7839
movsd 0x68(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
movsd 0x5551(%rip), %xmm1     # 0xcd80
mulsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
jmp 0x783d
jmp 0x7851
jmp 0x783f
jmp 0x7841
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x76ad
addq $0x98, %rsp
retq
nopl (%rax)