// File: /workspace/github_c_makefile_star2_O1/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, 0x18(%rsp)
movl $0xfffffc1d, %eax       # imm = 0xFFFFFC1D
xorpd %xmm1, %xmm1
ucomisd (%r9), %xmm1
jae 0x4b88
movq %r9, %r12
movq %r8, %r14
movq %rcx, %r15
movq %rsi, %r13
movl %edi, %ebp
testl %edi, %edi
jle 0x49e8
xorl %eax, %eax
movsd (%r15,%rax,8), %xmm0
mulsd (%r14,%rax,8), %xmm0
addsd %xmm0, %xmm1
incq %rax
cmpq %rax, %rbp
jne 0x49d0
movl $0xfffffc1e, %eax       # imm = 0xFFFFFC1E
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
ja 0x4b88
movq 0x90(%rsp), %rcx
movq 0x70(%rsp), %rbx
movq 0x18(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x40(%rcx), %xmm0
movsd %xmm1, 0x10(%rsp)
mulsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %eax, %eax
movl %edi, 0xc(%rsp)
testl %edi, %edi
jle 0x4a4c
xorl %ecx, %ecx
movsd (%rbx,%rcx,8), %xmm0
movsd %xmm0, (%r13,%rcx,8)
incq %rcx
cmpq %rcx, %rbp
jne 0x4a38
movq %rax, 0x30(%rsp)
testl %edi, %edi
jle 0x4a7d
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 0x4a5d
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdi
movl (%rax), %ecx
movsd (%r12), %xmm0
movq %r13, %rsi
movq %r15, %rdx
callq *0x10(%rax)
movq 0x18(%rsp), %rax
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rax
incl %eax
movsd (%r12), %xmm1
movapd %xmm1, %xmm2
mulsd 0x20(%rsp), %xmm2
addsd 0x28(%rsp), %xmm2
ucomisd %xmm2, %xmm0
movsd 0x9584(%rip), %xmm2     # 0xe050
movq 0x90(%rsp), %rsi
ja 0x4b4b
movl 0x24(%rsi), %edx
cmpl $0x1, %edx
je 0x4b88
cmpl $0x0, 0xc(%rsp)
jle 0x4b09
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
movsd (%r15,%rcx,8), %xmm2
mulsd (%r14,%rcx,8), %xmm2
addsd %xmm2, %xmm0
incq %rcx
cmpq %rcx, %rbp
jne 0x4aef
jmp 0x4b0d
xorpd %xmm0, %xmm0
movsd 0x48(%rsi), %xmm3
movsd 0x10(%rsp), %xmm2
mulsd %xmm3, %xmm2
ucomisd %xmm0, %xmm2
movsd 0x9560(%rip), %xmm2     # 0xe088
ja 0x4b4b
cmpl $0x2, %edx
je 0x4b88
xorpd 0x9579(%rip), %xmm3     # 0xe0b0
mulsd 0x10(%rsp), %xmm3
ucomisd %xmm3, %xmm0
movsd 0x9507(%rip), %xmm2     # 0xe050
jbe 0x4b88
movsd 0x30(%rsi), %xmm0
ucomisd %xmm1, %xmm0
ja 0x4b75
ucomisd 0x38(%rsi), %xmm1
ja 0x4b7c
cmpl %eax, 0x28(%rsi)
jle 0x4b83
mulsd %xmm2, %xmm1
movsd %xmm1, (%r12)
movl 0xc(%rsp), %edi
jmp 0x4a32
movl $0xfffffc18, %eax       # imm = 0xFFFFFC18
jmp 0x4b88
movl $0xfffffc19, %eax       # imm = 0xFFFFFC19
jmp 0x4b88
movl $0xfffffc1a, %eax       # imm = 0xFFFFFC1A
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq