// File: /workspace/github_c_makefile_star2_O3/debbiemarkslab[P]plmc/src/lib/lbfgs.c
// Function: line_search_backtracking_owlqn
static int line_search_backtracking_owlqn(
    int n,
    lbfgsfloatval_t *x,
    lbfgsfloatval_t *f,
    lbfgsfloatval_t *g,
    lbfgsfloatval_t *s,
    lbfgsfloatval_t *stp,
    const lbfgsfloatval_t* xp,
    const lbfgsfloatval_t* gp,
    lbfgsfloatval_t *wp,
    callback_data_t *cd,
    const lbfgs_parameter_t *param
    )
{
    int i, count = 0;
    lbfgsfloatval_t width = 0.5, norm = 0.;
    lbfgsfloatval_t finit = *f, dgtest;

    /* Check the input parameters for errors. */
    if (*stp <= 0.) {
        return LBFGSERR_INVALIDPARAMETERS;
    }

    /* Choose the orthant for the new point. */
    for (i = 0;i < n;++i) {
        wp[i] = (xp[i] == 0.) ? -gp[i] : xp[i];
    }

    for (;;) {
        /* Update the current point. */
        veccpy(x, xp, n);
        vecadd(x, s, *stp, n);

        /* The current point is projected onto the orthant. */
        owlqn_project(x, wp, param->orthantwise_start, param->orthantwise_end);

        /* Evaluate the function and gradient values. */
        *f = cd->proc_evaluate(cd->instance, x, g, cd->n, *stp);

        /* Compute the L1 norm of the variables and add it to the object value. */
        norm = owlqn_x1norm(x, param->orthantwise_start, param->orthantwise_end);
        *f += norm * param->orthantwise_c;

        ++count;

        dgtest = 0.;
        for (i = 0;i < n;++i) {
            dgtest += (x[i] - xp[i]) * gp[i];
        }

        if (*f <= finit + param->ftol * dgtest) {
            /* The sufficient decrease condition. */
            return count;
        }

        if (*stp < param->min_step) {
            /* The step is the minimum value. */
            return LBFGSERR_MINIMUMSTEP;
        }
        if (*stp > param->max_step) {
            /* The step is the maximum value. */
            return LBFGSERR_MAXIMUMSTEP;
        }
        if (param->max_linesearch <= count) {
            /* Maximum number of iteration. */
            return LBFGSERR_MAXIMUMLINESEARCH;
        }

        (*stp) *= width;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x30(%rsp)
movl $0xfffffc1d, %eax       # imm = 0xFFFFFC1D
xorpd %xmm0, %xmm0
ucomisd (%r9), %xmm0
jae 0x3e8a
movq %r8, %r14
movq %rsi, %r13
movq 0x80(%rsp), %r12
movq 0x78(%rsp), %rbp
movq 0x70(%rsp), %rbx
movsd (%rdx), %xmm0
movsd %xmm0, 0x18(%rsp)
movl %edi, %r15d
testl %edi, %edi
jle 0x3cf4
xorl %eax, %eax
xorpd %xmm0, %xmm0
movapd 0x93e1(%rip), %xmm1     # 0xd0b0
movsd (%rbx,%rax,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x3ce6
jp 0x3ce6
movsd (%rbp,%rax,8), %xmm2
xorpd %xmm1, %xmm2
movsd %xmm2, (%r12,%rax,8)
incq %rax
cmpq %rax, %r15
jne 0x3ccf
movq 0x90(%rsp), %rsi
movq $0x0, 0x10(%rsp)
xorpd %xmm2, %xmm2
movq %r9, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movl %edi, 0xc(%rsp)
testl %edi, %edi
jle 0x3d58
xorl %eax, %eax
movsd (%rbx,%rax,8), %xmm0
movsd %xmm0, (%r13,%rax,8)
incq %rax
cmpq %rax, %r15
jne 0x3d1d
movsd (%r9), %xmm0
xorl %eax, %eax
movsd (%r14,%rax,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r13,%rax,8), %xmm1
movsd %xmm1, (%r13,%rax,8)
incq %rax
cmpq %rax, %r15
jne 0x3d38
movslq 0x68(%rsi), %rax
movslq 0x6c(%rsi), %rcx
cmpl %ecx, %eax
jge 0x3d88
movsd (%r13,%rax,8), %xmm0
mulsd (%r12,%rax,8), %xmm0
ucomisd %xmm0, %xmm2
jb 0x3d80
movq $0x0, (%r13,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x3d64
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdi
movl (%rax), %ecx
movsd (%r9), %xmm0
movq %r13, %rsi
movq 0x30(%rsp), %rdx
callq *0x10(%rax)
movq 0x20(%rsp), %rdx
movsd %xmm0, (%rdx)
movq 0x90(%rsp), %rsi
movslq 0x68(%rsi), %rax
movslq 0x6c(%rsi), %rcx
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
cmpl %ecx, %eax
movapd 0x92cf(%rip), %xmm4     # 0xd0a0
jge 0x3dea
movsd (%r13,%rax,8), %xmm3
andpd %xmm4, %xmm3
addsd %xmm3, %xmm2
incq %rax
cmpq %rax, %rcx
jne 0x3dd3
mulsd 0x60(%rsi), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, (%rdx)
movl 0xc(%rsp), %edi
testl %edi, %edi
jle 0x3e23
xorpd %xmm1, %xmm1
xorl %eax, %eax
movsd (%r13,%rax,8), %xmm0
subsd (%rbx,%rax,8), %xmm0
mulsd (%rbp,%rax,8), %xmm0
addsd %xmm0, %xmm1
incq %rax
cmpq %rax, %r15
jne 0x3e05
mulsd 0x40(%rsi), %xmm1
movq 0x10(%rsp), %rax
incl %eax
addsd 0x18(%rsp), %xmm1
ucomisd %xmm2, %xmm1
movq 0x28(%rsp), %r9
jae 0x3e8a
movsd (%r9), %xmm0
movsd 0x30(%rsi), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3e77
ucomisd 0x38(%rsi), %xmm0
ja 0x3e7e
cmpl %eax, 0x28(%rsi)
jle 0x3e85
movq %rax, 0x10(%rsp)
mulsd 0x91e7(%rip), %xmm0     # 0xd050
movsd %xmm0, (%r9)
xorpd %xmm2, %xmm2
jmp 0x3d17
movl $0xfffffc18, %eax       # imm = 0xFFFFFC18
jmp 0x3e8a
movl $0xfffffc19, %eax       # imm = 0xFFFFFC19
jmp 0x3e8a
movl $0xfffffc1a, %eax       # imm = 0xFFFFFC1A
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq