// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x78, %rsp
movq 0xa0(%rsp), %rax
movq 0x98(%rsp), %rax
movq 0x90(%rsp), %rax
movq 0x88(%rsp), %rax
movq 0x80(%rsp), %rax
movl %edi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rcx, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movq %r9, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x15596(%rip), %xmm0    # 0x19018
movsd %xmm0, 0x10(%rsp)
movsd 0x155e0(%rip), %xmm0    # 0x19070
movsd %xmm0, 0x8(%rsp)
movq 0x48(%rsp), %rax
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
jb 0x3ab1
movl $0xfffffc1d, 0x74(%rsp) # imm = 0xFFFFFC1D
jmp 0x3d16
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
movl 0x70(%rsp), %ecx
leaq 0x20(%rsp), %rdi
callq 0x4150
movsd 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3ae5
movl $0xfffffc1e, 0x74(%rsp) # imm = 0xFFFFFC1E
jmp 0x3d16
movq 0x60(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0xa0(%rsp), %rax
movsd 0x40(%rax), %xmm0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x68(%rsp), %rdi
movq 0x80(%rsp), %rsi
movl 0x70(%rsp), %edx
callq 0x40a0
movq 0x68(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rax
movsd (%rax), %xmm0
movl 0x70(%rsp), %edx
callq 0x41d0
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x98(%rsp), %rcx
movq 0x8(%rcx), %rdi
movq 0x68(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x98(%rsp), %rcx
movl (%rcx), %ecx
movq 0x48(%rsp), %r8
movsd (%r8), %xmm0
callq *%rax
movq 0x60(%rsp), %rax
movsd %xmm0, (%rax)
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
movq 0x60(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x28(%rsp), %xmm2
movq 0x48(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x18(%rsp), %xmm3
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3bca
movsd 0x15459(%rip), %xmm0    # 0x19018
movsd %xmm0, 0x38(%rsp)
jmp 0x3c9b
movq 0xa0(%rsp), %rax
cmpl $0x1, 0x24(%rax)
jne 0x3be5
movl 0x44(%rsp), %eax
movl %eax, 0x74(%rsp)
jmp 0x3d16
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
movl 0x70(%rsp), %ecx
leaq 0x30(%rsp), %rdi
callq 0x4150
movsd 0x30(%rsp), %xmm1
movq 0xa0(%rsp), %rax
movsd 0x48(%rax), %xmm0
mulsd 0x20(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3c2c
movsd 0x1544c(%rip), %xmm0    # 0x19070
movsd %xmm0, 0x38(%rsp)
jmp 0x3c99
movq 0xa0(%rsp), %rax
cmpl $0x2, 0x24(%rax)
jne 0x3c47
movl 0x44(%rsp), %eax
movl %eax, 0x74(%rsp)
jmp 0x3d16
movsd 0x30(%rsp), %xmm0
movq 0xa0(%rsp), %rax
movsd 0x48(%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd 0x20(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3c8d
movsd 0x15393(%rip), %xmm0    # 0x19018
movsd %xmm0, 0x38(%rsp)
jmp 0x3c97
movl 0x44(%rsp), %eax
movl %eax, 0x74(%rsp)
jmp 0x3d16
jmp 0x3c99
jmp 0x3c9b
movq 0x48(%rsp), %rax
movsd (%rax), %xmm1
movq 0xa0(%rsp), %rax
movsd 0x30(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3cc1
movl $0xfffffc18, 0x74(%rsp) # imm = 0xFFFFFC18
jmp 0x3d16
movq 0x48(%rsp), %rax
movsd (%rax), %xmm0
movq 0xa0(%rsp), %rax
ucomisd 0x38(%rax), %xmm0
jbe 0x3ce3
movl $0xfffffc19, 0x74(%rsp) # imm = 0xFFFFFC19
jmp 0x3d16
movq 0xa0(%rsp), %rax
movl 0x28(%rax), %eax
cmpl 0x44(%rsp), %eax
jg 0x3cfe
movl $0xfffffc1a, 0x74(%rsp) # imm = 0xFFFFFC1A
jmp 0x3d16
movsd 0x38(%rsp), %xmm0
movq 0x48(%rsp), %rax
mulsd (%rax), %xmm0
movsd %xmm0, (%rax)
jmp 0x3b0d
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nop