; LLVM IR from radualexandrub/Optimization-Algorithms-Find-local-minimum :: 1D_DerivativeFree_Algorithms (golden_ratio)

; 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"

@logfile_golden_ratio = external dso_local global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [17 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local double @golden_ratio(ptr noundef %0, double noundef %1, double noundef %2, double noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store double %2, ptr %7, align 8, !tbaa !9
  store double %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %12 = call double @sqrt(double noundef 5.000000e+00) #4
  %13 = fadd double 1.000000e+00, %12
  %14 = fdiv double %13, 2.000000e+00
  store double %14, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %15 = load double, ptr %6, align 8, !tbaa !9
  %16 = load double, ptr %7, align 8, !tbaa !9
  %17 = load double, ptr %6, align 8, !tbaa !9
  %18 = fsub double %16, %17
  %19 = load double, ptr %9, align 8, !tbaa !9
  %20 = fdiv double %18, %19
  %21 = fadd double %15, %20
  store double %21, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %22 = load double, ptr %7, align 8, !tbaa !9
  %23 = load double, ptr %7, align 8, !tbaa !9
  %24 = load double, ptr %6, align 8, !tbaa !9
  %25 = fsub double %23, %24
  %26 = load double, ptr %9, align 8, !tbaa !9
  %27 = fdiv double %25, %26
  %28 = fsub double %22, %27
  store double %28, ptr %11, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %65, %4
  %30 = load double, ptr %6, align 8, !tbaa !9
  %31 = load double, ptr %7, align 8, !tbaa !9
  %32 = fsub double %30, %31
  %33 = call double @llvm.fabs.f64(double %32)
  %34 = fdiv double %33, 2.000000e+00
  %35 = load double, ptr %8, align 8, !tbaa !9
  %36 = fcmp ogt double %34, %35
  br i1 %36, label %37, label %76

37:                                               ; preds = %29
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load double, ptr %10, align 8, !tbaa !9
  %40 = call double %38(double noundef %39)
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load double, ptr %11, align 8, !tbaa !9
  %43 = call double %41(double noundef %42)
  %44 = fcmp olt double %40, %43
  br i1 %44, label %45, label %55

45:                                               ; preds = %37
  %46 = load double, ptr %11, align 8, !tbaa !9
  store double %46, ptr %6, align 8, !tbaa !9
  %47 = load double, ptr %10, align 8, !tbaa !9
  store double %47, ptr %11, align 8, !tbaa !9
  %48 = load double, ptr %6, align 8, !tbaa !9
  %49 = load double, ptr %7, align 8, !tbaa !9
  %50 = load double, ptr %6, align 8, !tbaa !9
  %51 = fsub double %49, %50
  %52 = load double, ptr %9, align 8, !tbaa !9
  %53 = fdiv double %51, %52
  %54 = fadd double %48, %53
  store double %54, ptr %10, align 8, !tbaa !9
  br label %65

55:                                               ; preds = %37
  %56 = load double, ptr %10, align 8, !tbaa !9
  store double %56, ptr %7, align 8, !tbaa !9
  %57 = load double, ptr %11, align 8, !tbaa !9
  store double %57, ptr %10, align 8, !tbaa !9
  %58 = load double, ptr %7, align 8, !tbaa !9
  %59 = load double, ptr %7, align 8, !tbaa !9
  %60 = load double, ptr %6, align 8, !tbaa !9
  %61 = fsub double %59, %60
  %62 = load double, ptr %9, align 8, !tbaa !9
  %63 = fdiv double %61, %62
  %64 = fsub double %58, %63
  store double %64, ptr %11, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %55, %45
  %66 = load ptr, ptr @logfile_golden_ratio, align 8, !tbaa !5
  %67 = load double, ptr %6, align 8, !tbaa !9
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load double, ptr %6, align 8, !tbaa !9
  %70 = call double %68(double noundef %69)
  %71 = load double, ptr %7, align 8, !tbaa !9
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load double, ptr %7, align 8, !tbaa !9
  %74 = call double %72(double noundef %73)
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %66, ptr noundef @.str.9, double noundef %67, double noundef %70, double noundef %71, double noundef %74) #4
  br label %29, !llvm.loop !11

76:                                               ; preds = %29
  %77 = load double, ptr %6, align 8, !tbaa !9
  %78 = load double, ptr %7, align 8, !tbaa !9
  %79 = fadd double %77, %78
  %80 = fdiv double %79, 2.000000e+00
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret double %80
}

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"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"

@logfile_golden_ratio = external dso_local local_unnamed_addr global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local double @golden_ratio(ptr nocapture noundef readonly %0, double noundef %1, double noundef %2, double noundef %3) local_unnamed_addr #0 {
  %5 = fsub double %1, %2
  %6 = tail call double @llvm.fabs.f64(double %5)
  %7 = fmul double %6, 5.000000e-01
  %8 = fcmp ogt double %7, %3
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %9 = fsub double %2, %1
  %10 = fdiv double %9, 0x3FF9E3779B97F4A8
  %11 = fsub double %2, %10
  %12 = fadd double %10, %1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %24
  %.044 = phi double [ %.1, %24 ], [ %11, %.lr.ph.preheader ]
  %.03543 = phi double [ %.136, %24 ], [ %12, %.lr.ph.preheader ]
  %.03742 = phi double [ %.138, %24 ], [ %1, %.lr.ph.preheader ]
  %.03941 = phi double [ %.140, %24 ], [ %2, %.lr.ph.preheader ]
  %13 = tail call double %0(double noundef %.03543) #3
  %14 = tail call double %0(double noundef %.044) #3
  %15 = fcmp olt double %13, %14
  br i1 %15, label %16, label %20

16:                                               ; preds = %.lr.ph
  %17 = fsub double %.03941, %.044
  %18 = fdiv double %17, 0x3FF9E3779B97F4A8
  %19 = fadd double %.044, %18
  br label %24

20:                                               ; preds = %.lr.ph
  %21 = fsub double %.03543, %.03742
  %22 = fdiv double %21, 0x3FF9E3779B97F4A8
  %23 = fsub double %.03543, %22
  br label %24

24:                                               ; preds = %20, %16
  %.140 = phi double [ %.03941, %16 ], [ %.03543, %20 ]
  %.138 = phi double [ %.044, %16 ], [ %.03742, %20 ]
  %.136 = phi double [ %19, %16 ], [ %.044, %20 ]
  %.1 = phi double [ %.03543, %16 ], [ %23, %20 ]
  %25 = load ptr, ptr @logfile_golden_ratio, align 8, !tbaa !5
  %26 = tail call double %0(double noundef %.138) #3
  %27 = tail call double %0(double noundef %.140) #3
  %28 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.9, double noundef %.138, double noundef %26, double noundef %.140, double noundef %27) #3
  %29 = fsub double %.138, %.140
  %30 = tail call double @llvm.fabs.f64(double %29)
  %31 = fmul double %30, 5.000000e-01
  %32 = fcmp ogt double %31, %3
  br i1 %32, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %24, %4
  %.039.lcssa = phi double [ %2, %4 ], [ %.140, %24 ]
  %.037.lcssa = phi double [ %1, %4 ], [ %.138, %24 ]
  %33 = fadd double %.039.lcssa, %.037.lcssa
  %34 = fmul double %33, 5.000000e-01
  ret double %34
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #2

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 = { nofree 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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