; LLVM IR from radualexandrub/Optimization-Algorithms-Find-local-minimum :: 2D_Derivative_NonQuadratic_CostFunctions (goldsearch)

; 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: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @Vec_scale(i32 noundef, double noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

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

; Function Attrs: nounwind uwtable
declare dso_local double @Vec_norm(i32 noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #0

; Function Attrs: nounwind uwtable
define dso_local double @goldsearch(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, double noundef %4, ptr noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca ptr, align 8
  %13 = alloca double, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  %21 = alloca double, align 8
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store double %4, ptr %11, align 8, !tbaa !11
  store ptr %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %22 = call double @sqrt(double noundef 5.000000e+00) #4
  %23 = fadd double 1.000000e+00, %22
  %24 = fdiv double %23, 2.000000e+00
  store double %24, ptr %13, align 8, !tbaa !11
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = zext i32 %25 to i64
  %27 = call ptr @llvm.stacksave.p0()
  store ptr %27, ptr %14, align 8
  %28 = alloca double, i64 %26, align 16
  store i64 %26, ptr %15, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %29 = load double, ptr %13, align 8, !tbaa !11
  %30 = fdiv double 1.000000e+00, %29
  store double %30, ptr %16, align 8, !tbaa !11
  %31 = load double, ptr %16, align 8, !tbaa !11
  %32 = load ptr, ptr %9, align 8, !tbaa !9
  call void @Vec_scale(i32 noundef 2, double noundef %31, ptr noundef %32, ptr noundef %28)
  %33 = load ptr, ptr %10, align 8, !tbaa !9
  %34 = load ptr, ptr %12, align 8, !tbaa !9
  call void @Vec_add(i32 noundef 2, ptr noundef %33, ptr noundef %28, ptr noundef %34)
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = load ptr, ptr %12, align 8, !tbaa !9
  %37 = getelementptr inbounds double, ptr %36, i64 0
  %38 = load double, ptr %37, align 8, !tbaa !11
  %39 = load ptr, ptr %12, align 8, !tbaa !9
  %40 = getelementptr inbounds double, ptr %39, i64 1
  %41 = load double, ptr %40, align 8, !tbaa !11
  %42 = call double %35(double noundef %38, double noundef %41)
  store double %42, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %43 = load double, ptr %13, align 8, !tbaa !11
  %44 = load double, ptr %13, align 8, !tbaa !11
  %45 = fmul double %43, %44
  %46 = fdiv double 1.000000e+00, %45
  store double %46, ptr %18, align 8, !tbaa !11
  %47 = load double, ptr %18, align 8, !tbaa !11
  %48 = load ptr, ptr %9, align 8, !tbaa !9
  call void @Vec_scale(i32 noundef 2, double noundef %47, ptr noundef %48, ptr noundef %28)
  %49 = load ptr, ptr %10, align 8, !tbaa !9
  %50 = load ptr, ptr %12, align 8, !tbaa !9
  call void @Vec_add(i32 noundef 2, ptr noundef %49, ptr noundef %28, ptr noundef %50)
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  %52 = load ptr, ptr %12, align 8, !tbaa !9
  %53 = getelementptr inbounds double, ptr %52, i64 0
  %54 = load double, ptr %53, align 8, !tbaa !11
  %55 = load ptr, ptr %12, align 8, !tbaa !9
  %56 = getelementptr inbounds double, ptr %55, i64 1
  %57 = load double, ptr %56, align 8, !tbaa !11
  %58 = call double %51(double noundef %54, double noundef %57)
  store double %58, ptr %19, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %59 = load ptr, ptr %9, align 8, !tbaa !9
  %60 = call double @Vec_norm(i32 noundef 2, ptr noundef %59)
  store double %60, ptr %20, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  %61 = load double, ptr %16, align 8, !tbaa !11
  %62 = load double, ptr %18, align 8, !tbaa !11
  %63 = fsub double %61, %62
  store double %63, ptr %21, align 8, !tbaa !11
  br label %64

64:                                               ; preds = %115, %6
  %65 = load double, ptr %20, align 8, !tbaa !11
  %66 = load double, ptr %21, align 8, !tbaa !11
  %67 = fmul double %65, %66
  %68 = load double, ptr %11, align 8, !tbaa !11
  %69 = fcmp ogt double %67, %68
  br i1 %69, label %70, label %116

70:                                               ; preds = %64
  %71 = load double, ptr %16, align 8, !tbaa !11
  %72 = load double, ptr %18, align 8, !tbaa !11
  %73 = fsub double %71, %72
  %74 = load double, ptr %13, align 8, !tbaa !11
  %75 = fdiv double %73, %74
  store double %75, ptr %21, align 8, !tbaa !11
  %76 = load double, ptr %17, align 8, !tbaa !11
  %77 = load double, ptr %19, align 8, !tbaa !11
  %78 = fcmp ogt double %76, %77
  br i1 %78, label %79, label %97

79:                                               ; preds = %70
  %80 = load double, ptr %18, align 8, !tbaa !11
  store double %80, ptr %16, align 8, !tbaa !11
  %81 = load double, ptr %19, align 8, !tbaa !11
  store double %81, ptr %17, align 8, !tbaa !11
  %82 = load double, ptr %21, align 8, !tbaa !11
  %83 = load double, ptr %18, align 8, !tbaa !11
  %84 = fsub double %83, %82
  store double %84, ptr %18, align 8, !tbaa !11
  %85 = load double, ptr %18, align 8, !tbaa !11
  %86 = load ptr, ptr %9, align 8, !tbaa !9
  call void @Vec_scale(i32 noundef 2, double noundef %85, ptr noundef %86, ptr noundef %28)
  %87 = load ptr, ptr %10, align 8, !tbaa !9
  %88 = load ptr, ptr %12, align 8, !tbaa !9
  call void @Vec_add(i32 noundef 2, ptr noundef %87, ptr noundef %28, ptr noundef %88)
  %89 = load ptr, ptr %8, align 8, !tbaa !9
  %90 = load ptr, ptr %12, align 8, !tbaa !9
  %91 = getelementptr inbounds double, ptr %90, i64 0
  %92 = load double, ptr %91, align 8, !tbaa !11
  %93 = load ptr, ptr %12, align 8, !tbaa !9
  %94 = getelementptr inbounds double, ptr %93, i64 1
  %95 = load double, ptr %94, align 8, !tbaa !11
  %96 = call double %89(double noundef %92, double noundef %95)
  store double %96, ptr %19, align 8, !tbaa !11
  br label %115

97:                                               ; preds = %70
  %98 = load double, ptr %16, align 8, !tbaa !11
  store double %98, ptr %18, align 8, !tbaa !11
  %99 = load double, ptr %17, align 8, !tbaa !11
  store double %99, ptr %19, align 8, !tbaa !11
  %100 = load double, ptr %21, align 8, !tbaa !11
  %101 = load double, ptr %16, align 8, !tbaa !11
  %102 = fadd double %101, %100
  store double %102, ptr %16, align 8, !tbaa !11
  %103 = load double, ptr %16, align 8, !tbaa !11
  %104 = load ptr, ptr %9, align 8, !tbaa !9
  call void @Vec_scale(i32 noundef 2, double noundef %103, ptr noundef %104, ptr noundef %28)
  %105 = load ptr, ptr %10, align 8, !tbaa !9
  %106 = load ptr, ptr %12, align 8, !tbaa !9
  call void @Vec_add(i32 noundef 2, ptr noundef %105, ptr noundef %28, ptr noundef %106)
  %107 = load ptr, ptr %8, align 8, !tbaa !9
  %108 = load ptr, ptr %12, align 8, !tbaa !9
  %109 = getelementptr inbounds double, ptr %108, i64 0
  %110 = load double, ptr %109, align 8, !tbaa !11
  %111 = load ptr, ptr %12, align 8, !tbaa !9
  %112 = getelementptr inbounds double, ptr %111, i64 1
  %113 = load double, ptr %112, align 8, !tbaa !11
  %114 = call double %107(double noundef %110, double noundef %113)
  store double %114, ptr %17, align 8, !tbaa !11
  br label %115

115:                                              ; preds = %97, %79
  br label %64, !llvm.loop !13

116:                                              ; preds = %64
  %117 = load double, ptr %18, align 8, !tbaa !11
  %118 = load double, ptr %16, align 8, !tbaa !11
  %119 = fadd double %117, %118
  %120 = fdiv double %119, 2.000000e+00
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  %121 = load ptr, ptr %14, align 8
  call void @llvm.stackrestore.p0(ptr %121)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  ret double %120
}

; Function Attrs: nounwind uwtable
declare dso_local void @Vec_add(i32 noundef, ptr noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nounwind "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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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
declare dso_local void @Vec_scale(i32 noundef, double noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local double @Vec_norm(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local double @goldsearch(i32 noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr noundef %3, double noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = zext i32 %0 to i64
  %8 = alloca double, i64 %7, align 16
  call void @Vec_scale(i32 noundef 2, double noundef 0x3FE3C6EF372FE94F, ptr noundef %2, ptr noundef nonnull %8)
  call void @Vec_add(i32 noundef 2, ptr noundef %3, ptr noundef nonnull %8, ptr noundef %5)
  %9 = load double, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = call double %1(double noundef %9, double noundef %11) #1
  call void @Vec_scale(i32 noundef 2, double noundef 0x3FD8722191A02D61, ptr noundef %2, ptr noundef nonnull %8)
  call void @Vec_add(i32 noundef 2, ptr noundef %3, ptr noundef nonnull %8, ptr noundef nonnull %5)
  %13 = load double, ptr %5, align 8, !tbaa !5
  %14 = load double, ptr %10, align 8, !tbaa !5
  %15 = call double %1(double noundef %13, double noundef %14) #1
  %16 = call double @Vec_norm(i32 noundef 2, ptr noundef %2)
  %17 = fmul double %16, 0x3FCE3779B97F4A7A
  %18 = fcmp ogt double %17, %4
  br i1 %18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6, %32
  %.05363 = phi double [ %.1, %32 ], [ 0x3FE3C6EF372FE94F, %6 ]
  %.05462 = phi double [ %.155, %32 ], [ %15, %6 ]
  %.05661 = phi double [ %.157, %32 ], [ 0x3FD8722191A02D61, %6 ]
  %.05860 = phi double [ %.159, %32 ], [ %12, %6 ]
  %19 = fsub double %.05363, %.05661
  %20 = fdiv double %19, 0x3FF9E3779B97F4A8
  %21 = fcmp ogt double %.05860, %.05462
  br i1 %21, label %22, label %27

22:                                               ; preds = %.lr.ph
  %23 = fsub double %.05661, %20
  call void @Vec_scale(i32 noundef 2, double noundef %23, ptr noundef %2, ptr noundef nonnull %8)
  call void @Vec_add(i32 noundef 2, ptr noundef %3, ptr noundef nonnull %8, ptr noundef nonnull %5)
  %24 = load double, ptr %5, align 8, !tbaa !5
  %25 = load double, ptr %10, align 8, !tbaa !5
  %26 = call double %1(double noundef %24, double noundef %25) #1
  br label %32

27:                                               ; preds = %.lr.ph
  %28 = fadd double %.05363, %20
  call void @Vec_scale(i32 noundef 2, double noundef %28, ptr noundef %2, ptr noundef nonnull %8)
  call void @Vec_add(i32 noundef 2, ptr noundef %3, ptr noundef nonnull %8, ptr noundef nonnull %5)
  %29 = load double, ptr %5, align 8, !tbaa !5
  %30 = load double, ptr %10, align 8, !tbaa !5
  %31 = call double %1(double noundef %29, double noundef %30) #1
  br label %32

32:                                               ; preds = %27, %22
  %.159 = phi double [ %.05462, %22 ], [ %31, %27 ]
  %.157 = phi double [ %23, %22 ], [ %.05363, %27 ]
  %.155 = phi double [ %26, %22 ], [ %.05860, %27 ]
  %.1 = phi double [ %.05661, %22 ], [ %28, %27 ]
  %33 = fmul double %16, %20
  %34 = fcmp ogt double %33, %4
  br i1 %34, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %32
  %35 = fadd double %.157, %.1
  %36 = fmul double %35, 5.000000e-01
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %6
  %37 = phi double [ 5.000000e-01, %6 ], [ %36, %._crit_edge.loopexit ]
  ret double %37
}

; Function Attrs: nounwind uwtable
declare dso_local void @Vec_add(i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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 = { 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: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass