// File: /workspace/github_c_makefile_star2_O3/debbiemarkslab[P]plmc/src/lib/lbfgs.c
// Function: line_search_backtracking
static int line_search_backtracking(
    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 count = 0;
    lbfgsfloatval_t width, dg;
    lbfgsfloatval_t finit, dginit = 0., dgtest;
    const lbfgsfloatval_t dec = 0.5, inc = 2.1;

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

    /* Compute the initial gradient in the search direction. */
    vecdot(&dginit, g, s, n);

    /* Make sure that s points to a descent direction. */
    if (0 < dginit) {
        return LBFGSERR_INCREASEGRADIENT;
    }

    /* The initial value of the objective function. */
    finit = *f;
    dgtest = param->ftol * dginit;

    for (;;) {
        veccpy(x, xp, n);
        vecadd(x, s, *stp, n);

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

        ++count;

        if (*f > finit + *stp * dgtest) {
            width = dec;
        } else {
            /* The sufficient decrease condition (Armijo condition). */
            if (param->linesearch == LBFGS_LINESEARCH_BACKTRACKING_ARMIJO) {
                /* Exit with the Armijo condition. */
                return count;
	        }

	        /* Check the Wolfe condition. */
	        vecdot(&dg, g, s, n);
	        if (dg < param->wolfe * dginit) {
    		    width = inc;
	        } else {
		        if(param->linesearch == LBFGS_LINESEARCH_BACKTRACKING_WOLFE) {
		            /* Exit with the regular Wolfe condition. */
		            return count;
		        }

		        /* Check the strong Wolfe condition. */
		        if(dg > -param->wolfe * dginit) {
		            width = dec;
		        } else {
		            /* Exit with the strong Wolfe 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 %rdx, 0x10(%rsp)
movsd (%r9), %xmm0
movl $0xfffffc1d, %eax       # imm = 0xFFFFFC1D
xorpd %xmm4, %xmm4
ucomisd %xmm0, %xmm4
jae 0x4092
movq %r9, %r12
movq %r8, %r14
movq %rcx, %r15
movq %rsi, %r13
movl %edi, %ebp
testl %edi, %edi
jle 0x3f03
xorl %eax, %eax
movsd (%r15,%rax,8), %xmm1
mulsd (%r14,%rax,8), %xmm1
addsd %xmm1, %xmm4
incq %rax
cmpq %rax, %rbp
jne 0x3ed8
movl $0xfffffc1e, %eax       # imm = 0xFFFFFC1E
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm4
ja 0x4092
movq 0x90(%rsp), %rcx
movq 0x70(%rsp), %rbx
movq 0x10(%rsp), %rax
movsd (%rax), %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x40(%rcx), %xmm1
mulsd %xmm4, %xmm1
movsd %xmm1, 0x18(%rsp)
xorl %eax, %eax
movl %edi, 0xc(%rsp)
movsd %xmm4, 0x28(%rsp)
movq %rax, 0x30(%rsp)
testl %edi, %edi
jle 0x3f87
xorl %eax, %eax
movsd (%rbx,%rax,8), %xmm0
movsd %xmm0, (%r13,%rax,8)
incq %rax
cmpq %rax, %rbp
jne 0x3f45
movsd (%r12), %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, %rbp
jne 0x3f61
movsd (%r12), %xmm0
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdi
movl (%rax), %ecx
movq %r13, %rsi
movq %r15, %rdx
callq *0x10(%rax)
movapd %xmm0, %xmm1
movq 0x10(%rsp), %rax
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rax
incl %eax
movsd (%r12), %xmm0
movapd %xmm0, %xmm2
mulsd 0x18(%rsp), %xmm2
addsd 0x20(%rsp), %xmm2
ucomisd %xmm2, %xmm1
movsd 0x907c(%rip), %xmm2     # 0xd050
movsd 0x28(%rsp), %xmm4
movq 0x90(%rsp), %rsi
ja 0x4055
movl 0x24(%rsi), %edx
cmpl $0x1, %edx
je 0x4092
cmpl $0x0, 0xc(%rsp)
jle 0x4017
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
movsd (%r15,%rcx,8), %xmm2
mulsd (%r14,%rcx,8), %xmm2
addsd %xmm2, %xmm1
incq %rcx
cmpq %rcx, %rbp
jne 0x3ffd
jmp 0x401b
xorpd %xmm1, %xmm1
movsd 0x48(%rsi), %xmm3
movapd %xmm4, %xmm2
mulsd %xmm3, %xmm2
ucomisd %xmm1, %xmm2
movsd 0x9054(%rip), %xmm2     # 0xd088
ja 0x4055
cmpl $0x2, %edx
je 0x4092
xorpd 0x906d(%rip), %xmm3     # 0xd0b0
mulsd %xmm4, %xmm3
ucomisd %xmm3, %xmm1
movsd 0x8ffd(%rip), %xmm2     # 0xd050
jbe 0x4092
movsd 0x30(%rsi), %xmm1
ucomisd %xmm0, %xmm1
ja 0x407f
ucomisd 0x38(%rsi), %xmm0
ja 0x4086
cmpl %eax, 0x28(%rsi)
jle 0x408d
mulsd %xmm2, %xmm0
movsd %xmm0, (%r12)
movl 0xc(%rsp), %edi
jmp 0x3f3a
movl $0xfffffc18, %eax       # imm = 0xFFFFFC18
jmp 0x4092
movl $0xfffffc19, %eax       # imm = 0xFFFFFC19
jmp 0x4092
movl $0xfffffc1a, %eax       # imm = 0xFFFFFC1A
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq