; LLVM IR from ahampriyanshu/algo-ds-101 :: Algorithms/Searching/Binary-Search (Binary_Search_CubicRoot)

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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@a = external dso_local global double, align 8
@b = external dso_local global double, align 8
@c = external dso_local global double, align 8
@d = external dso_local global double, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z1fd(double noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z9binsearchdd(double noundef, double 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: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %3 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @a)
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(8) @b)
  %5 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(8) @c)
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(8) @d)
  %7 = load double, ptr @a, align 8, !tbaa !5
  %8 = fcmp olt double %7, 0.000000e+00
  br i1 %8, label %9, label %18

9:                                                ; preds = %0
  %10 = load double, ptr @a, align 8, !tbaa !5
  %11 = fmul double %10, -1.000000e+00
  store double %11, ptr @a, align 8, !tbaa !5
  %12 = load double, ptr @b, align 8, !tbaa !5
  %13 = fmul double %12, -1.000000e+00
  store double %13, ptr @b, align 8, !tbaa !5
  %14 = load double, ptr @c, align 8, !tbaa !5
  %15 = fmul double %14, -1.000000e+00
  store double %15, ptr @c, align 8, !tbaa !5
  %16 = load double, ptr @d, align 8, !tbaa !5
  %17 = fmul double %16, -1.000000e+00
  store double %17, ptr @d, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %9, %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %29, %18
  %20 = load i32, ptr %2, align 4, !tbaa !9
  %21 = sitofp i32 %20 to double
  %22 = call noundef double @_Z1fd(double noundef %21)
  %23 = load i32, ptr %2, align 4, !tbaa !9
  %24 = sub nsw i32 0, %23
  %25 = sitofp i32 %24 to double
  %26 = call noundef double @_Z1fd(double noundef %25)
  %27 = fmul double %22, %26
  %28 = fcmp oge double %27, 0.000000e+00
  br i1 %28, label %29, label %32

29:                                               ; preds = %19
  %30 = load i32, ptr %2, align 4, !tbaa !9
  %31 = mul nsw i32 %30, 2
  store i32 %31, ptr %2, align 4, !tbaa !9
  br label %19, !llvm.loop !11

32:                                               ; preds = %19
  %33 = load i32, ptr %2, align 4, !tbaa !9
  %34 = sub nsw i32 0, %33
  %35 = sitofp i32 %34 to double
  %36 = load i32, ptr %2, align 4, !tbaa !9
  %37 = sitofp i32 %36 to double
  %38 = call noundef double @_Z9binsearchdd(double noundef %35, double noundef %37)
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %38)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

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

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 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress norecurse 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 #4 = { "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 = !{!"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"

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@a = external dso_local global double, align 8
@b = external dso_local global double, align 8
@c = external dso_local global double, align 8
@d = external dso_local global double, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z1fd(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z9binsearchdd(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @a)
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(8) @b)
  %3 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(8) @c)
  %4 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(8) @d)
  %5 = load double, ptr @a, align 8, !tbaa !5
  %6 = fcmp olt double %5, 0.000000e+00
  br i1 %6, label %7, label %.preheader

7:                                                ; preds = %0
  %8 = fneg double %5
  store double %8, ptr @a, align 8, !tbaa !5
  %9 = load double, ptr @b, align 8, !tbaa !5
  %10 = fneg double %9
  store double %10, ptr @b, align 8, !tbaa !5
  %11 = load double, ptr @c, align 8, !tbaa !5
  %12 = fneg double %11
  store double %12, ptr @c, align 8, !tbaa !5
  %13 = load double, ptr @d, align 8, !tbaa !5
  %14 = fneg double %13
  store double %14, ptr @d, align 8, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %7, %0
  br label %15

15:                                               ; preds = %.preheader, %15
  %.0 = phi i32 [ %23, %15 ], [ 1, %.preheader ]
  %16 = uitofp nneg i32 %.0 to double
  %17 = tail call noundef double @_Z1fd(double noundef %16)
  %18 = sub nsw i32 0, %.0
  %19 = sitofp i32 %18 to double
  %20 = tail call noundef double @_Z1fd(double noundef %19)
  %21 = fmul double %17, %20
  %22 = fcmp ult double %21, 0.000000e+00
  %23 = shl nsw i32 %.0, 1
  br i1 %22, label %24, label %15, !llvm.loop !9

24:                                               ; preds = %15
  %25 = tail call noundef double @_Z9binsearchdd(double noundef %19, double noundef %16)
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %25)
  ret i32 0
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

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

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 = { mustprogress 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 = { mustprogress norecurse 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 = { 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" }

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


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