#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
double sqrt(double);
int /*<<< orphan*/ trstep_ddl(double *, double *, int, double *, double,
                              double *, double *, double, double *, double *,
                              double *, double *);
int trupdate(double (*)(double *, int), double *, double *, double *, int,
             double *, double, int, double *, double *, double, int, double *,
             double *, double *);
int trsrch_ddl(double (*funcpt)(double *, int), double *xi, double *jac,
               double *sN, int N, double *dx, double maxstep, int iter,
               double *L, double *hess, double stol, double *ioval, double *x) {
  int retval, i, method;
  double nlen;
  double *temp, *step, *xprev, *ssd, *v;
  retval = 4;
  nlen = 0.0;
  ioval[7] = 1.0;
  method = 1;
  temp = (double *)malloc(sizeof(double) * N);
  step = (double *)malloc(sizeof(double) * N);
  xprev = (double *)malloc(sizeof(double) * N);
  ssd = (double *)malloc(sizeof(double) * N);
  v = (double *)malloc(sizeof(double) * N);
  for (i = 0; i < N; ++i) {
    nlen += dx[i] * sN[i] * dx[i] * sN[i];
  }
  nlen = sqrt(nlen);
  while (retval >= 2) {
    trstep_ddl(jac, sN, N, dx, maxstep, L, hess, nlen, ioval, ssd, v, step);
    retval = trupdate(funcpt, xi, jac, step, N, dx, maxstep, retval, L, hess,
                      stol, method, ioval, xprev, x);
  }
  free(temp);
  free(step);
  free(xprev);
  free(ssd);
  free(v);
  return retval;
}


x86 assembly (clang, -O0):
<trsrch_ddl>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc0,%rsp
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %rdx,-0x38(%rbp)
mov    %rcx,-0x40(%rbp)
mov    %r8d,-0x44(%rbp)
mov    %r9,-0x50(%rbp)
movsd  %xmm0,-0x58(%rbp)
movsd  %xmm1,-0x60(%rbp)
movl   $0x4,-0x64(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    0x28(%rbp),%rax
movsd  0xe4e(%rip),%xmm0
movsd  %xmm0,0x38(%rax)
movl   $0x1,-0x6c(%rbp)
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x80(%rbp)
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x88(%rbp)
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x90(%rbp)
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x98(%rbp)
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0xa0(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1290 <trsrch_ddl+0x140>
mov    -0x50(%rbp),%rax
movslq -0x68(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x68(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x50(%rbp),%rax
movslq -0x68(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x68(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x78(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1230 <trsrch_ddl+0xe0>
movsd  -0x78(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x78(%rbp)
cmpl   $0x2,-0x64(%rbp)
jl     136c <trsrch_ddl+0x21c>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
mov    -0x50(%rbp),%rcx
movsd  -0x58(%rbp),%xmm0
mov    0x18(%rbp),%r8
mov    0x20(%rbp),%r9
movsd  -0x78(%rbp),%xmm1
mov    0x28(%rbp),%rbx
mov    -0x98(%rbp),%r11
mov    -0xa0(%rbp),%r10
mov    -0x88(%rbp),%rax
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1040 <trstep_ddl@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x88(%rbp),%rcx
mov    -0x44(%rbp),%r8d
mov    -0x50(%rbp),%r9
movsd  -0x58(%rbp),%xmm0
mov    -0x64(%rbp),%r12d
mov    0x18(%rbp),%r15
mov    0x20(%rbp),%r14
movsd  -0x60(%rbp),%xmm1
mov    -0x6c(%rbp),%ebx
mov    0x28(%rbp),%r11
mov    -0x90(%rbp),%r10
mov    0x30(%rbp),%rax
mov    %r12d,(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %ebx,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %rax,0x30(%rsp)
call   1070 <trupdate@plt>
mov    %eax,-0x64(%rbp)
jmp    129f <trsrch_ddl+0x14f>
mov    -0x80(%rbp),%rdi
call   1030 <free@plt>
mov    -0x88(%rbp),%rdi
call   1030 <free@plt>
mov    -0x90(%rbp),%rdi
call   1030 <free@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
mov    -0xa0(%rbp),%rdi
call   1030 <free@plt>
mov    -0x64(%rbp),%eax
add    $0xc0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<trsrch_ddl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movsd  %xmm1,0x70(%rsp)
movsd  %xmm0,0x28(%rsp)
mov    %r9,%rbx
mov    %r8d,%r13d
mov    %rcx,%rbp
mov    %rdx,0x60(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
mov    0xc8(%rsp),%rcx
movabs $0x3ff0000000000000,%rax
mov    %rax,0x38(%rcx)
lea    0x0(,%r13,8),%r14d
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,0x30(%rsp)
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    %r14d,%edi
call   1050 <malloc@plt>
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
test   %r13d,%r13d
jle    127d <trsrch_ddl+0x12d>
mov    %r13d,%esi
cmp    $0x1,%r13d
jne    11fa <trsrch_ddl+0xaa>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
jmp    1258 <trsrch_ddl+0x108>
mov    %esi,%edx
and    $0xfffffffe,%edx
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%rbx,%rcx,8),%xmm2
movsd  0x8(%rbx,%rcx,8),%xmm3
movsd  0x0(%rbp,%rcx,8),%xmm4
movsd  0x8(%rbp,%rcx,8),%xmm5
movapd %xmm2,%xmm6
mulsd  %xmm4,%xmm6
mulsd  %xmm2,%xmm6
mulsd  %xmm4,%xmm6
addsd  %xmm0,%xmm6
movapd %xmm3,%xmm0
mulsd  %xmm5,%xmm0
mulsd  %xmm3,%xmm0
mulsd  %xmm5,%xmm0
addsd  %xmm6,%xmm0
add    $0x2,%rcx
cmp    %rcx,%rdx
jne    1210 <trsrch_ddl+0xc0>
test   $0x1,%sil
je     127d <trsrch_ddl+0x12d>
movsd  (%rbx,%rcx,8),%xmm2
movsd  0x0(%rbp,%rcx,8),%xmm3
movapd %xmm2,%xmm4
mulsd  %xmm3,%xmm4
mulsd  %xmm2,%xmm4
mulsd  %xmm3,%xmm4
addsd  %xmm4,%xmm0
ucomisd %xmm1,%xmm0
mov    %rbx,0x68(%rsp)
mov    %rax,0x8(%rsp)
jb     1293 <trsrch_ddl+0x143>
sqrtsd %xmm0,%xmm0
jmp    1298 <trsrch_ddl+0x148>
call   1060 <sqrt@plt>
mov    %r12,0x38(%rsp)
mov    %r15,0x40(%rsp)
mov    %r13,0x48(%rsp)
mov    %rbp,0x50(%rsp)
mov    $0x4,%ebx
movsd  %xmm0,0x58(%rsp)
mov    0x60(%rsp),%r14
mov    0x48(%rsp),%r15
mov    0x68(%rsp),%rbp
mov    0x20(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    0x50(%rsp),%rsi
mov    %r15d,%edx
mov    %rbp,%rcx
movsd  0x28(%rsp),%xmm0
mov    0xb8(%rsp),%r8
mov    %rbx,%r12
mov    0xc0(%rsp),%r9
movsd  0x58(%rsp),%xmm1
push   %r13
push   0x10(%rsp)
push   0x20(%rsp)
mov    0xe0(%rsp),%rbx
push   %rbx
call   1040 <trstep_ddl@plt>
add    $0x18,%rsp
mov    0x40(%rsp),%rdi
mov    0x48(%rsp),%rsi
mov    %r14,%rdx
mov    %r13,%rcx
mov    %r15d,%r8d
mov    %rbp,%r9
movsd  0x30(%rsp),%xmm0
movsd  0x78(%rsp),%xmm1
push   0xd8(%rsp)
push   0x28(%rsp)
push   %rbx
push   $0x1
push   0xe8(%rsp)
push   0xe8(%rsp)
push   %r12
call   1070 <trupdate@plt>
add    $0x40,%rsp
mov    %eax,%ebx
cmp    $0x1,%eax
jg     12d0 <trsrch_ddl+0x180>
mov    0x30(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @trsrch_ddl(double (double*, i32)* %0, double* %1, double* %2, double* %3, i32 %4, double* %5, double %6, i32 %7, double* %8, double* %9, double %10, double* %11, double* %12) {
%14 = alloca double (double*, i32)*
%15 = alloca double*
%16 = alloca double*
%17 = alloca double*
%18 = alloca i32
%19 = alloca double*
%20 = alloca double
%21 = alloca i32
%22 = alloca double*
%23 = alloca double*
%24 = alloca double
%25 = alloca double*
%26 = alloca double*
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
%30 = alloca double
%31 = alloca double*
%32 = alloca double*
%33 = alloca double*
%34 = alloca double*
%35 = alloca double*
store double (double*, i32)* %0, double (double*, i32)** %14
store double* %1, double** %15
store double* %2, double** %16
store double* %3, double** %17
store i32 %4, i32* %18
store double* %5, double** %19
store double %6, double* %20
store i32 %7, i32* %21
store double* %8, double** %22
store double* %9, double** %23
store double %10, double* %24
store double* %11, double** %25
store double* %12, double** %26
store i32 4, i32* %27
store double 0.000000e+00, double* %30
%36 = load double*, double** %25
%37 = getelementptr inbounds double, double* %36, i64 7
store double 1.000000e+00, double* %37
store i32 1, i32* %29
%38 = load i32, i32* %18
%39 = sext i32 %38 to i64
%40 = mul i64 8, %39
%41 = trunc i64 %40 to i32
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to double*
store double* %43, double** %31
%44 = load i32, i32* %18
%45 = sext i32 %44 to i64
%46 = mul i64 8, %45
%47 = trunc i64 %46 to i32
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to double*
store double* %49, double** %32
%50 = load i32, i32* %18
%51 = sext i32 %50 to i64
%52 = mul i64 8, %51
%53 = trunc i64 %52 to i32
%54 = call i64 @malloc(i32 %53)
%55 = inttoptr i64 %54 to double*
store double* %55, double** %33
%56 = load i32, i32* %18
%57 = sext i32 %56 to i64
%58 = mul i64 8, %57
%59 = trunc i64 %58 to i32
%60 = call i64 @malloc(i32 %59)
%61 = inttoptr i64 %60 to double*
store double* %61, double** %34
%62 = load i32, i32* %18
%63 = sext i32 %62 to i64
%64 = mul i64 8, %63
%65 = trunc i64 %64 to i32
%66 = call i64 @malloc(i32 %65)
%67 = inttoptr i64 %66 to double*
store double* %67, double** %35
store i32 0, i32* %28
br label %68
68: ; preds = %97, %13
%69 = load i32, i32* %28
%70 = load i32, i32* %18
%71 = icmp slt i32 %69, %70
br i1 %71, label %72, label %100
72: ; preds = %68
%73 = load double*, double** %19
%74 = load i32, i32* %28
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %73, i64 %75
%77 = load double, double* %76
%78 = load double*, double** %17
%79 = load i32, i32* %28
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds double, double* %78, i64 %80
%82 = load double, double* %81
%83 = fmul double %77, %82
%84 = load double*, double** %19
%85 = load i32, i32* %28
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %84, i64 %86
%88 = load double, double* %87
%89 = fmul double %83, %88
%90 = load double*, double** %17
%91 = load i32, i32* %28
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double, double* %90, i64 %92
%94 = load double, double* %93
%95 = load double, double* %30
%96 = call double @llvm.fmuladd.f64(double %89, double %94, double %95)
store double %96, double* %30
br label %97
97: ; preds = %72
%98 = load i32, i32* %28
%99 = add nsw i32 %98, 1
store i32 %99, i32* %28
br label %68
100: ; preds = %68
%101 = load double, double* %30
%102 = call double @sqrt(double %101)
store double %102, double* %30
br label %103
103: ; preds = %106, %100
%104 = load i32, i32* %27
%105 = icmp sge i32 %104, 2
br i1 %105, label %106, label %136
106: ; preds = %103
%107 = load double*, double** %16
%108 = load double*, double** %17
%109 = load i32, i32* %18
%110 = load double*, double** %19
%111 = load double, double* %20
%112 = load double*, double** %22
%113 = load double*, double** %23
%114 = load double, double* %30
%115 = load double*, double** %25
%116 = load double*, double** %34
%117 = load double*, double** %35
%118 = load double*, double** %32
%119 = call i32 @trstep_ddl(double* %107, double* %108, i32 %109, double* %110, double %111, double* %112, double* %113, double %114, double* %115, double* %116, double* %117, double* %118)
%120 = load double (double*, i32)*, double (double*, i32)** %14
%121 = load double*, double** %15
%122 = load double*, double** %16
%123 = load double*, double** %32
%124 = load i32, i32* %18
%125 = load double*, double** %19
%126 = load double, double* %20
%127 = load i32, i32* %27
%128 = load double*, double** %22
%129 = load double*, double** %23
%130 = load double, double* %24
%131 = load i32, i32* %29
%132 = load double*, double** %25
%133 = load double*, double** %33
%134 = load double*, double** %26
%135 = call i32 @trupdate(double (double*, i32)* %120, double* %121, double* %122, double* %123, i32 %124, double* %125, double %126, i32 %127, double* %128, double* %129, double %130, i32 %131, double* %132, double* %133, double* %134)
store i32 %135, i32* %27
br label %103
136: ; preds = %103
%137 = load double*, double** %31
%138 = call i32 @free(double* %137)
%139 = load double*, double** %32
%140 = call i32 @free(double* %139)
%141 = load double*, double** %33
%142 = call i32 @free(double* %141)
%143 = load double*, double** %34
%144 = call i32 @free(double* %143)
%145 = load double*, double** %35
%146 = call i32 @free(double* %145)
%147 = load i32, i32* %27
ret i32 %147
}

LLVM IR (-O2):
define i32 @trsrch_ddl(double (double*, i32)* %0, double* %1, double* %2, double* %3, i32 %4, double* %5, double %6, i32 %7, double* %8, double* %9, double %10, double* %11, double* %12) {
%14 = getelementptr inbounds double, double* %11, i64 7
store double 1.000000e+00, double* %14
%15 = shl i32 %4, 3
%16 = tail call i64 @malloc(i32 %15)
%17 = tail call i64 @malloc(i32 %15)
%18 = inttoptr i64 %17 to double*
%19 = tail call i64 @malloc(i32 %15)
%20 = inttoptr i64 %19 to double*
%21 = tail call i64 @malloc(i32 %15)
%22 = inttoptr i64 %21 to double*
%23 = tail call i64 @malloc(i32 %15)
%24 = inttoptr i64 %23 to double*
%25 = icmp sgt i32 %4, 0
br i1 %25, label %26, label %67
26: ; preds = %13
%27 = zext i32 %4 to i64
%28 = and i64 %27, 1
%29 = icmp eq i32 %4, 1
br i1 %29, label %54, label %30
30: ; preds = %26
%31 = and i64 %27, 4294967294
br label %32
32: ; preds = %32, %30
%33 = phi i64 [ 0, %30 ], [ %51, %32 ]
%34 = phi double [ 0.000000e+00, %30 ], [ %50, %32 ]
%35 = phi i64 [ 0, %30 ], [ %52, %32 ]
%36 = getelementptr inbounds double, double* %5, i64 %33
%37 = load double, double* %36
%38 = getelementptr inbounds double, double* %3, i64 %33
%39 = load double, double* %38
%40 = fmul double %37, %39
%41 = fmul double %37, %40
%42 = tail call double @llvm.fmuladd.f64(double %41, double %39, double %34)
%43 = or i64 %33, 1
%44 = getelementptr inbounds double, double* %5, i64 %43
%45 = load double, double* %44
%46 = getelementptr inbounds double, double* %3, i64 %43
%47 = load double, double* %46
%48 = fmul double %45, %47
%49 = fmul double %45, %48
%50 = tail call double @llvm.fmuladd.f64(double %49, double %47, double %42)
%51 = add nuw nsw i64 %33, 2
%52 = add i64 %35, 2
%53 = icmp eq i64 %52, %31
br i1 %53, label %54, label %32
54: ; preds = %32, %26
%55 = phi double [ undef, %26 ], [ %50, %32 ]
%56 = phi i64 [ 0, %26 ], [ %51, %32 ]
%57 = phi double [ 0.000000e+00, %26 ], [ %50, %32 ]
%58 = icmp eq i64 %28, 0
br i1 %58, label %67, label %59
59: ; preds = %54
%60 = getelementptr inbounds double, double* %5, i64 %56
%61 = load double, double* %60
%62 = getelementptr inbounds double, double* %3, i64 %56
%63 = load double, double* %62
%64 = fmul double %61, %63
%65 = fmul double %61, %64
%66 = tail call double @llvm.fmuladd.f64(double %65, double %63, double %57)
br label %67
67: ; preds = %59, %54, %13
%68 = phi double [ 0.000000e+00, %13 ], [ %55, %54 ], [ %66, %59 ]
%69 = tail call double @sqrt(double %68)
br label %70
70: ; preds = %67, %70
%71 = phi i32 [ 4, %67 ], [ %73, %70 ]
%72 = tail call i32 @trstep_ddl(double* %2, double* %3, i32 %4, double* %5, double %6, double* %8, double* %9, double %69, double* %11, double* %22, double* %24, double* %18)
%73 = tail call i32 @trupdate(double (double*, i32)* %0, double* %1, double* %2, double* %18, i32 %4, double* %5, double %6, i32 %71, double* %8, double* %9, double %10, i32 1, double* %11, double* %20, double* %12)
%74 = icmp sgt i32 %73, 1
br i1 %74, label %70, label %75
75: ; preds = %70
%76 = inttoptr i64 %16 to double*
%77 = tail call i32 @free(double* %76)
%78 = tail call i32 @free(double* %18)
%79 = tail call i32 @free(double* %20)
%80 = tail call i32 @free(double* %22)
%81 = tail call i32 @free(double* %24)
ret i32 %73
}