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

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

@logfile4 = external dso_local global ptr, align 8
@.str.15 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [16 x i8], align 1

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

declare i32 @printf(ptr noundef, ...) #1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local double @falsi(ptr noundef %0, ptr noundef %1, double noundef %2, double noundef %3, double noundef %4) #4 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, 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 %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store double %2, ptr %8, align 8, !tbaa !9
  store double %3, ptr %9, align 8, !tbaa !9
  store double %4, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr @logfile4, align 8, !tbaa !5
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef @.str.15) #5
  br label %14

14:                                               ; preds = %64, %5
  %15 = load double, ptr %8, align 8, !tbaa !9
  %16 = load double, ptr %9, align 8, !tbaa !9
  %17 = fsub double %15, %16
  %18 = call double @llvm.fabs.f64(double %17)
  %19 = load double, ptr %10, align 8, !tbaa !9
  %20 = fcmp ogt double %18, %19
  br i1 %20, label %21, label %88

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %22 = load double, ptr %8, align 8, !tbaa !9
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load double, ptr %8, align 8, !tbaa !9
  %25 = call double %23(double noundef %24)
  %26 = load double, ptr %8, align 8, !tbaa !9
  %27 = load double, ptr %9, align 8, !tbaa !9
  %28 = fsub double %26, %27
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load double, ptr %8, align 8, !tbaa !9
  %31 = call double %29(double noundef %30)
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load double, ptr %9, align 8, !tbaa !9
  %34 = call double %32(double noundef %33)
  %35 = fsub double %31, %34
  %36 = fdiv double %28, %35
  %37 = fneg double %25
  %38 = call double @llvm.fmuladd.f64(double %37, double %36, double %22)
  store double %38, ptr %11, align 8, !tbaa !9
  %39 = load double, ptr %11, align 8, !tbaa !9
  %40 = load double, ptr %8, align 8, !tbaa !9
  %41 = load double, ptr %10, align 8, !tbaa !9
  %42 = fadd double %40, %41
  %43 = fcmp ole double %39, %42
  br i1 %43, label %50, label %44

44:                                               ; preds = %21
  %45 = load double, ptr %11, align 8, !tbaa !9
  %46 = load double, ptr %9, align 8, !tbaa !9
  %47 = load double, ptr %10, align 8, !tbaa !9
  %48 = fsub double %46, %47
  %49 = fcmp ogt double %45, %48
  br i1 %49, label %50, label %55

50:                                               ; preds = %44, %21
  %51 = load double, ptr %8, align 8, !tbaa !9
  %52 = load double, ptr %9, align 8, !tbaa !9
  %53 = fadd double %51, %52
  %54 = fdiv double %53, 2.000000e+00
  store double %54, ptr %11, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %50, %44
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load double, ptr %11, align 8, !tbaa !9
  %58 = call double %56(double noundef %57)
  %59 = fcmp olt double %58, 0.000000e+00
  br i1 %59, label %60, label %62

60:                                               ; preds = %55
  %61 = load double, ptr %11, align 8, !tbaa !9
  store double %61, ptr %8, align 8, !tbaa !9
  br label %64

62:                                               ; preds = %55
  %63 = load double, ptr %11, align 8, !tbaa !9
  store double %63, ptr %9, align 8, !tbaa !9
  br label %64

64:                                               ; preds = %62, %60
  %65 = load double, ptr %8, align 8, !tbaa !9
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load double, ptr %8, align 8, !tbaa !9
  %68 = call double %66(double noundef %67)
  %69 = load double, ptr %9, align 8, !tbaa !9
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = load double, ptr %9, align 8, !tbaa !9
  %72 = call double %70(double noundef %71)
  %73 = load double, ptr %8, align 8, !tbaa !9
  %74 = load double, ptr %9, align 8, !tbaa !9
  %75 = fadd double %73, %74
  %76 = fdiv double %75, 2.000000e+00
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.16, double noundef %65, double noundef %68, double noundef %69, double noundef %72, double noundef %76)
  %78 = load ptr, ptr @logfile4, align 8, !tbaa !5
  %79 = load double, ptr %8, align 8, !tbaa !9
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = load double, ptr %8, align 8, !tbaa !9
  %82 = call double %80(double noundef %81)
  %83 = load double, ptr %9, align 8, !tbaa !9
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = load double, ptr %9, align 8, !tbaa !9
  %86 = call double %84(double noundef %85)
  %87 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %78, ptr noundef @.str.17, double noundef %79, double noundef %82, double noundef %83, double noundef %86) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %14, !llvm.loop !11

88:                                               ; preds = %14
  %89 = load double, ptr %8, align 8, !tbaa !9
  %90 = load double, ptr %9, align 8, !tbaa !9
  %91 = fadd double %89, %90
  %92 = fdiv double %91, 2.000000e+00
  ret double %92
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #5 = { 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"

@logfile4 = external dso_local local_unnamed_addr global ptr, align 8
@.str.15 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [16 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(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) #0

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

; Function Attrs: nounwind uwtable
define dso_local double @falsi(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, double noundef %2, double noundef %3, double noundef %4) local_unnamed_addr #2 {
  %6 = load ptr, ptr @logfile4, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str.15) #3
  %8 = fsub double %2, %3
  %9 = tail call double @llvm.fabs.f64(double %8)
  %10 = fcmp ogt double %9, %4
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %.lr.ph
  %11 = phi double [ %36, %.lr.ph ], [ %8, %5 ]
  %.04047 = phi double [ %.1, %.lr.ph ], [ %2, %5 ]
  %.04146 = phi double [ %.142, %.lr.ph ], [ %3, %5 ]
  %12 = tail call double %1(double noundef %.04047) #3
  %13 = tail call double %1(double noundef %.04047) #3
  %14 = tail call double %1(double noundef %.04146) #3
  %15 = fsub double %13, %14
  %16 = fdiv double %11, %15
  %17 = fneg double %12
  %18 = tail call double @llvm.fmuladd.f64(double %17, double %16, double %.04047)
  %19 = fadd double %.04047, %4
  %20 = fcmp ole double %18, %19
  %21 = fsub double %.04146, %4
  %22 = fcmp ogt double %18, %21
  %or.cond = select i1 %20, i1 true, i1 %22
  %23 = fadd double %.04146, %.04047
  %24 = fmul double %23, 5.000000e-01
  %.0 = select i1 %or.cond, double %24, double %18
  %25 = tail call double %1(double noundef %.0) #3
  %26 = fcmp olt double %25, 0.000000e+00
  %.142 = select i1 %26, double %.04146, double %.0
  %.1 = select i1 %26, double %.0, double %.04047
  %27 = tail call double %0(double noundef %.1) #3
  %28 = tail call double %0(double noundef %.142) #3
  %29 = fadd double %.1, %.142
  %30 = fmul double %29, 5.000000e-01
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, double noundef %.1, double noundef %27, double noundef %.142, double noundef %28, double noundef %30)
  %32 = load ptr, ptr @logfile4, align 8, !tbaa !5
  %33 = tail call double %0(double noundef %.1) #3
  %34 = tail call double %0(double noundef %.142) #3
  %35 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull @.str.17, double noundef %.1, double noundef %33, double noundef %.142, double noundef %34) #3
  %36 = fsub double %.1, %.142
  %37 = tail call double @llvm.fabs.f64(double %36)
  %38 = fcmp ogt double %37, %4
  br i1 %38, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.041.lcssa = phi double [ %3, %5 ], [ %.142, %.lr.ph ]
  %.040.lcssa = phi double [ %2, %5 ], [ %.1, %.lr.ph ]
  %39 = fadd double %.041.lcssa, %.040.lcssa
  %40 = fmul double %39, 5.000000e-01
  ret double %40
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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 }

!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