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

; 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_dichotomy = 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 @dichotomy(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
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %12 = load double, ptr %8, align 8, !tbaa !9
  %13 = fdiv double %12, 4.000000e+00
  store double %13, ptr %11, align 8, !tbaa !9
  br label %14

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

21:                                               ; preds = %14
  %22 = load double, ptr %6, align 8, !tbaa !9
  %23 = load double, ptr %7, align 8, !tbaa !9
  %24 = fadd double %22, %23
  %25 = fdiv double %24, 2.000000e+00
  %26 = load double, ptr %11, align 8, !tbaa !9
  %27 = fsub double %25, %26
  store double %27, ptr %9, align 8, !tbaa !9
  %28 = load double, ptr %6, align 8, !tbaa !9
  %29 = load double, ptr %7, align 8, !tbaa !9
  %30 = fadd double %28, %29
  %31 = fdiv double %30, 2.000000e+00
  %32 = load double, ptr %11, align 8, !tbaa !9
  %33 = fadd double %31, %32
  store double %33, ptr %10, align 8, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load double, ptr %9, align 8, !tbaa !9
  %36 = call double %34(double noundef %35)
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load double, ptr %10, align 8, !tbaa !9
  %39 = call double %37(double noundef %38)
  %40 = fcmp ogt double %36, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %21
  %42 = load double, ptr %9, align 8, !tbaa !9
  store double %42, ptr %6, align 8, !tbaa !9
  br label %45

43:                                               ; preds = %21
  %44 = load double, ptr %10, align 8, !tbaa !9
  store double %44, ptr %7, align 8, !tbaa !9
  br label %45

45:                                               ; preds = %43, %41
  %46 = load ptr, ptr @logfile_dichotomy, align 8, !tbaa !5
  %47 = load double, ptr %6, align 8, !tbaa !9
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load double, ptr %6, align 8, !tbaa !9
  %50 = call double %48(double noundef %49)
  %51 = load double, ptr %7, align 8, !tbaa !9
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load double, ptr %7, align 8, !tbaa !9
  %54 = call double %52(double noundef %53)
  %55 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str.9, double noundef %47, double noundef %50, double noundef %51, double noundef %54) #4
  br label %14, !llvm.loop !11

56:                                               ; preds = %14
  %57 = load double, ptr %6, align 8, !tbaa !9
  %58 = load double, ptr %7, align 8, !tbaa !9
  %59 = fadd double %57, %58
  %60 = fdiv double %59, 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 %60
}

; 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

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_dichotomy = 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 @dichotomy(ptr nocapture noundef readonly %0, double noundef %1, double noundef %2, double noundef %3) local_unnamed_addr #0 {
  %5 = fmul double %3, 2.500000e-01
  %6 = fsub double %1, %2
  %7 = tail call double @llvm.fabs.f64(double %6)
  %8 = fcmp ogt double %7, %3
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.027 = phi double [ %..0, %.lr.ph ], [ %1, %4 ]
  %.02426 = phi double [ %.024., %.lr.ph ], [ %2, %4 ]
  %9 = fadd double %.02426, %.027
  %10 = fmul double %9, 5.000000e-01
  %11 = fsub double %10, %5
  %12 = fadd double %5, %10
  %13 = tail call double %0(double noundef %11) #3
  %14 = tail call double %0(double noundef %12) #3
  %15 = fcmp ogt double %13, %14
  %.024. = select i1 %15, double %.02426, double %12
  %..0 = select i1 %15, double %11, double %.027
  %16 = load ptr, ptr @logfile_dichotomy, align 8, !tbaa !5
  %17 = tail call double %0(double noundef %..0) #3
  %18 = tail call double %0(double noundef %.024.) #3
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.9, double noundef %..0, double noundef %17, double noundef %.024., double noundef %18) #3
  %20 = fsub double %..0, %.024.
  %21 = tail call double @llvm.fabs.f64(double %20)
  %22 = fcmp ogt double %21, %3
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.024.lcssa = phi double [ %2, %4 ], [ %.024., %.lr.ph ]
  %.0.lcssa = phi double [ %1, %4 ], [ %..0, %.lr.ph ]
  %23 = fadd double %.024.lcssa, %.0.lcssa
  %24 = fmul double %23, 5.000000e-01
  ret double %24
}

; 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