// File: /workspace/github_c_makefile_star2_O1/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 0x4986
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 0x47ec
xorl %eax, %eax
xorpd %xmm0, %xmm0
movapd 0x98e9(%rip), %xmm1     # 0xe0b0
movsd (%rbx,%rax,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x47de
jp 0x47de
movsd (%rbp,%rax,8), %xmm2
xorpd %xmm1, %xmm2
movsd %xmm2, (%r12,%rax,8)
incq %rax
cmpq %rax, %r15
jne 0x47c7
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 0x4829
xorl %eax, %eax
movsd (%rbx,%rax,8), %xmm0
movsd %xmm0, (%r13,%rax,8)
incq %rax
cmpq %rax, %r15
jne 0x4815
testl %edi, %edi
jle 0x4854
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 0x4834
movslq 0x68(%rsi), %rax
movslq 0x6c(%rsi), %rcx
cmpl %ecx, %eax
jge 0x4884
movsd (%r13,%rax,8), %xmm0
mulsd (%r12,%rax,8), %xmm0
ucomisd %xmm0, %xmm2
jb 0x487c
movq $0x0, (%r13,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x4860
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 0x97d3(%rip), %xmm4     # 0xe0a0
jge 0x48e6
movsd (%r13,%rax,8), %xmm3
andpd %xmm4, %xmm3
addsd %xmm3, %xmm2
incq %rax
cmpq %rax, %rcx
jne 0x48cf
mulsd 0x60(%rsi), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, (%rdx)
movl 0xc(%rsp), %edi
testl %edi, %edi
jle 0x491f
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 0x4901
mulsd 0x40(%rsi), %xmm1
movq 0x10(%rsp), %rax
incl %eax
addsd 0x18(%rsp), %xmm1
ucomisd %xmm2, %xmm1
movq 0x28(%rsp), %r9
jae 0x4986
movsd (%r9), %xmm0
movsd 0x30(%rsi), %xmm1
ucomisd %xmm0, %xmm1
ja 0x4973
ucomisd 0x38(%rsi), %xmm0
ja 0x497a
cmpl %eax, 0x28(%rsi)
jle 0x4981
movq %rax, 0x10(%rsp)
mulsd 0x96eb(%rip), %xmm0     # 0xe050
movsd %xmm0, (%r9)
xorpd %xmm2, %xmm2
jmp 0x480f
movl $0xfffffc18, %eax       # imm = 0xFFFFFC18
jmp 0x4986
movl $0xfffffc19, %eax       # imm = 0xFFFFFC19
jmp 0x4986
movl $0xfffffc1a, %eax       # imm = 0xFFFFFC1A
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq