; LLVM IR from UtkarshPathrabe/Competitive-Coding :: SPOJ Solutions/CUBEROO2.ll (Z12binarySearchddd)

; 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: mustprogress nounwind uwtable
define dso_local noundef double @_Z12binarySearchddd(double noundef %0, double noundef %1, double noundef %2) #0 {
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  store double %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !5
  store double %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 80, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  br label %10

10:                                               ; preds = %36, %34, %25, %3
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr %7, align 4, !tbaa !9
  %13 = icmp ne i32 %11, 0
  br i1 %13, label %14, label %38

14:                                               ; preds = %10
  %15 = load double, ptr %4, align 8, !tbaa !5
  %16 = load double, ptr %5, align 8, !tbaa !5
  %17 = fadd double %15, %16
  %18 = fdiv double %17, 2.000000e+00
  store double %18, ptr %9, align 8, !tbaa !5
  %19 = load double, ptr %9, align 8, !tbaa !5
  %20 = load double, ptr %9, align 8, !tbaa !5
  %21 = fmul double %19, %20
  store double %21, ptr %8, align 8, !tbaa !5
  %22 = load double, ptr %8, align 8, !tbaa !5
  %23 = load double, ptr %6, align 8, !tbaa !5
  %24 = fcmp ogt double %22, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %14
  %26 = load double, ptr %9, align 8, !tbaa !5
  store double %26, ptr %5, align 8, !tbaa !5
  br label %10, !llvm.loop !11

27:                                               ; preds = %14
  %28 = load double, ptr %8, align 8, !tbaa !5
  %29 = load double, ptr %9, align 8, !tbaa !5
  %30 = fmul double %28, %29
  store double %30, ptr %8, align 8, !tbaa !5
  %31 = load double, ptr %8, align 8, !tbaa !5
  %32 = load double, ptr %6, align 8, !tbaa !5
  %33 = fcmp ogt double %31, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %27
  %35 = load double, ptr %9, align 8, !tbaa !5
  store double %35, ptr %5, align 8, !tbaa !5
  br label %10, !llvm.loop !11

36:                                               ; preds = %27
  %37 = load double, ptr %9, align 8, !tbaa !5
  store double %37, ptr %4, align 8, !tbaa !5
  br label %10, !llvm.loop !11

38:                                               ; preds = %10
  %39 = load double, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret double %39
}

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

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

attributes #0 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef double @_Z12binarySearchddd(double noundef %0, double noundef %1, double noundef %2) local_unnamed_addr #0 {
  br label %.outer

.outer:                                           ; preds = %11, %3
  %.015.ph = phi double [ %..015, %11 ], [ %1, %3 ]
  %.014.ph = phi i32 [ %6, %11 ], [ 80, %3 ]
  %.0.ph = phi double [ %.0., %11 ], [ %0, %3 ]
  br label %4

4:                                                ; preds = %.outer, %5
  %.015 = phi double [ %8, %5 ], [ %.015.ph, %.outer ]
  %.014 = phi i32 [ %6, %5 ], [ %.014.ph, %.outer ]
  %.not = icmp eq i32 %.014, 0
  br i1 %.not, label %14, label %5

5:                                                ; preds = %4
  %6 = add nsw i32 %.014, -1
  %7 = fadd double %.015, %.0.ph
  %8 = fmul double %7, 5.000000e-01
  %9 = fmul double %8, %8
  %10 = fcmp ogt double %9, %2
  br i1 %10, label %4, label %11, !llvm.loop !5

11:                                               ; preds = %5
  %12 = fmul double %8, %9
  %13 = fcmp ogt double %12, %2
  %..015 = select i1 %13, double %8, double %.015
  %.0. = select i1 %13, double %.0.ph, double %8
  br label %.outer, !llvm.loop !5

14:                                               ; preds = %4
  ret double %.0.ph
}

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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