; LLVM IR from rgolubtsov/nonlinear-optimization-algorithms-multilang :: nlp-unconstrained-cli/hooke-jeeves/c/src (hooke)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
define dso_local double @best_nearby(ptr noundef %0, ptr noundef %1, double noundef %2, i32 noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca [250 x double], align 16
  %13 = alloca double, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store double %2, ptr %8, align 8, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 2000, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %15 = load double, ptr %8, align 8, !tbaa !9
  store double %15, ptr %11, align 8, !tbaa !9
  store i32 0, ptr %14, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %29, %5
  %17 = load i32, ptr %14, align 4, !tbaa !11
  %18 = load i32, ptr %9, align 4, !tbaa !11
  %19 = icmp ult i32 %17, %18
  br i1 %19, label %20, label %32

20:                                               ; preds = %16
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %14, align 4, !tbaa !11
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %21, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !9
  %26 = load i32, ptr %14, align 4, !tbaa !11
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [250 x double], ptr %12, i64 0, i64 %27
  store double %25, ptr %28, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %20
  %30 = load i32, ptr %14, align 4, !tbaa !11
  %31 = add i32 %30, 1
  store i32 %31, ptr %14, align 4, !tbaa !11
  br label %16, !llvm.loop !13

32:                                               ; preds = %16
  store i32 0, ptr %14, align 4, !tbaa !11
  br label %33

33:                                               ; preds = %106, %32
  %34 = load i32, ptr %14, align 4, !tbaa !11
  %35 = load i32, ptr %9, align 4, !tbaa !11
  %36 = icmp ult i32 %34, %35
  br i1 %36, label %37, label %109

37:                                               ; preds = %33
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load i32, ptr %14, align 4, !tbaa !11
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %38, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load i32, ptr %14, align 4, !tbaa !11
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds double, ptr %43, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !9
  %48 = fadd double %42, %47
  %49 = load i32, ptr %14, align 4, !tbaa !11
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds [250 x double], ptr %12, i64 0, i64 %50
  store double %48, ptr %51, align 8, !tbaa !9
  %52 = getelementptr inbounds [250 x double], ptr %12, i64 0, i64 0
  %53 = load i32, ptr %9, align 4, !tbaa !11
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = call double @f(ptr noundef %52, i32 noundef %53, ptr noundef %54)
  store double %55, ptr %13, align 8, !tbaa !9
  %56 = load double, ptr %13, align 8, !tbaa !9
  %57 = load double, ptr %11, align 8, !tbaa !9
  %58 = fcmp olt double %56, %57
  br i1 %58, label %59, label %61

59:                                               ; preds = %37
  %60 = load double, ptr %13, align 8, !tbaa !9
  store double %60, ptr %11, align 8, !tbaa !9
  br label %105

61:                                               ; preds = %37
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load i32, ptr %14, align 4, !tbaa !11
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds double, ptr %62, i64 %64
  %66 = load double, ptr %65, align 8, !tbaa !9
  %67 = fsub double 0.000000e+00, %66
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load i32, ptr %14, align 4, !tbaa !11
  %70 = zext i32 %69 to i64
  %71 = getelementptr inbounds double, ptr %68, i64 %70
  store double %67, ptr %71, align 8, !tbaa !9
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load i32, ptr %14, align 4, !tbaa !11
  %74 = zext i32 %73 to i64
  %75 = getelementptr inbounds double, ptr %72, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !9
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = load i32, ptr %14, align 4, !tbaa !11
  %79 = zext i32 %78 to i64
  %80 = getelementptr inbounds double, ptr %77, i64 %79
  %81 = load double, ptr %80, align 8, !tbaa !9
  %82 = fadd double %76, %81
  %83 = load i32, ptr %14, align 4, !tbaa !11
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds [250 x double], ptr %12, i64 0, i64 %84
  store double %82, ptr %85, align 8, !tbaa !9
  %86 = getelementptr inbounds [250 x double], ptr %12, i64 0, i64 0
  %87 = load i32, ptr %9, align 4, !tbaa !11
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = call double @f(ptr noundef %86, i32 noundef %87, ptr noundef %88)
  store double %89, ptr %13, align 8, !tbaa !9
  %90 = load double, ptr %13, align 8, !tbaa !9
  %91 = load double, ptr %11, align 8, !tbaa !9
  %92 = fcmp olt double %90, %91
  br i1 %92, label %93, label %95

93:                                               ; preds = %61
  %94 = load double, ptr %13, align 8, !tbaa !9
  store double %94, ptr %11, align 8, !tbaa !9
  br label %104

95:                                               ; preds = %61
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = load i32, ptr %14, align 4, !tbaa !11
  %98 = zext i32 %97 to i64
  %99 = getelementptr inbounds double, ptr %96, i64 %98
  %100 = load double, ptr %99, align 8, !tbaa !9
  %101 = load i32, ptr %14, align 4, !tbaa !11
  %102 = zext i32 %101 to i64
  %103 = getelementptr inbounds [250 x double], ptr %12, i64 0, i64 %102
  store double %100, ptr %103, align 8, !tbaa !9
  br label %104

104:                                              ; preds = %95, %93
  br label %105

105:                                              ; preds = %104, %59
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %14, align 4, !tbaa !11
  %108 = add i32 %107, 1
  store i32 %108, ptr %14, align 4, !tbaa !11
  br label %33, !llvm.loop !15

109:                                              ; preds = %33
  store i32 0, ptr %14, align 4, !tbaa !11
  br label %110

110:                                              ; preds = %123, %109
  %111 = load i32, ptr %14, align 4, !tbaa !11
  %112 = load i32, ptr %9, align 4, !tbaa !11
  %113 = icmp ult i32 %111, %112
  br i1 %113, label %114, label %126

114:                                              ; preds = %110
  %115 = load i32, ptr %14, align 4, !tbaa !11
  %116 = zext i32 %115 to i64
  %117 = getelementptr inbounds [250 x double], ptr %12, i64 0, i64 %116
  %118 = load double, ptr %117, align 8, !tbaa !9
  %119 = load ptr, ptr %7, align 8, !tbaa !5
  %120 = load i32, ptr %14, align 4, !tbaa !11
  %121 = zext i32 %120 to i64
  %122 = getelementptr inbounds double, ptr %119, i64 %121
  store double %118, ptr %122, align 8, !tbaa !9
  br label %123

123:                                              ; preds = %114
  %124 = load i32, ptr %14, align 4, !tbaa !11
  %125 = add i32 %124, 1
  store i32 %125, ptr %14, align 4, !tbaa !11
  br label %110, !llvm.loop !16

126:                                              ; preds = %110
  %127 = load double, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 2000, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret double %127
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare double @f(ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
define dso_local double @best_nearby(ptr nocapture noundef %0, ptr nocapture noundef %1, double noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca [250 x double], align 16
  call void @llvm.lifetime.start.p0(i64 2000, ptr nonnull %6) #4
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph52.preheader

.lr.ph52.preheader:                               ; preds = %5
  %7 = zext i32 %3 to i64
  %8 = shl nuw nsw i64 %7, 3
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %6, ptr align 8 %1, i64 %8, i1 false), !tbaa !5
  %wide.trip.count = zext i32 %3 to i64
  br label %.lr.ph52

.preheader:                                       ; preds = %28
  br i1 %.not, label %._crit_edge, label %.lr.ph54.preheader

.lr.ph54.preheader:                               ; preds = %.preheader
  %9 = zext i32 %3 to i64
  %10 = shl nuw nsw i64 %9, 3
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %1, ptr nonnull align 16 %6, i64 %10, i1 false), !tbaa !5
  br label %._crit_edge

.lr.ph52:                                         ; preds = %.lr.ph52.preheader, %28
  %indvars.iv = phi i64 [ 0, %.lr.ph52.preheader ], [ %indvars.iv.next, %28 ]
  %.04350 = phi double [ %2, %.lr.ph52.preheader ], [ %.144, %28 ]
  %11 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = fadd double %12, %14
  %16 = getelementptr inbounds [250 x double], ptr %6, i64 0, i64 %indvars.iv
  store double %15, ptr %16, align 8, !tbaa !5
  %17 = call double @f(ptr noundef nonnull %6, i32 noundef %3, ptr noundef %4) #4
  %18 = fcmp olt double %17, %.04350
  br i1 %18, label %28, label %19

19:                                               ; preds = %.lr.ph52
  %20 = load double, ptr %13, align 8, !tbaa !5
  %21 = fsub double 0.000000e+00, %20
  store double %21, ptr %13, align 8, !tbaa !5
  %22 = load double, ptr %11, align 8, !tbaa !5
  %23 = fadd double %21, %22
  store double %23, ptr %16, align 8, !tbaa !5
  %24 = call double @f(ptr noundef nonnull %6, i32 noundef %3, ptr noundef %4) #4
  %25 = fcmp olt double %24, %.04350
  br i1 %25, label %28, label %26

26:                                               ; preds = %19
  %27 = load double, ptr %11, align 8, !tbaa !5
  store double %27, ptr %16, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %19, %.lr.ph52, %26
  %.144 = phi double [ %.04350, %26 ], [ %17, %.lr.ph52 ], [ %24, %19 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.lr.ph52, !llvm.loop !9

._crit_edge:                                      ; preds = %5, %.lr.ph54.preheader, %.preheader
  %.043.lcssa63 = phi double [ %.144, %.lr.ph54.preheader ], [ %.144, %.preheader ], [ %2, %5 ]
  call void @llvm.lifetime.end.p0(i64 2000, ptr nonnull %6) #4
  ret double %.043.lcssa63
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare double @f(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass