; LLVM IR from Dutta-SD/Numerical_Methods :: Equations (Bisection_Method)

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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @Bisection_Method(double noundef %0, double noundef %1) #0 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store double %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 1.000000e-04, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  %8 = load double, ptr %3, align 8, !tbaa !5
  %9 = load double, ptr %4, align 8, !tbaa !5
  %10 = fadd double %8, %9
  %11 = fdiv double %10, 2.000000e+00
  store double %11, ptr %6, align 8, !tbaa !5
  %12 = load double, ptr %6, align 8, !tbaa !5
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %12)
  br label %14

14:                                               ; preds = %48, %2
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp ne i32 %15, 30
  br i1 %16, label %17, label %49

17:                                               ; preds = %14
  %18 = load double, ptr %6, align 8, !tbaa !5
  %19 = call double @F(double noundef %18)
  %20 = load double, ptr %3, align 8, !tbaa !5
  %21 = call double @F(double noundef %20)
  %22 = fmul double %19, %21
  %23 = fcmp ogt double %22, 0.000000e+00
  br i1 %23, label %24, label %32

24:                                               ; preds = %17
  %25 = load double, ptr %6, align 8, !tbaa !5
  store double %25, ptr %3, align 8, !tbaa !5
  %26 = load double, ptr %3, align 8, !tbaa !5
  %27 = load double, ptr %4, align 8, !tbaa !5
  %28 = fadd double %26, %27
  %29 = fdiv double %28, 2.000000e+00
  store double %29, ptr %6, align 8, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %7, align 4, !tbaa !9
  br label %48

32:                                               ; preds = %17
  %33 = load double, ptr %6, align 8, !tbaa !5
  %34 = call double @F(double noundef %33)
  %35 = load double, ptr %3, align 8, !tbaa !5
  %36 = call double @F(double noundef %35)
  %37 = fmul double %34, %36
  %38 = fcmp olt double %37, 0.000000e+00
  br i1 %38, label %39, label %47

39:                                               ; preds = %32
  %40 = load double, ptr %6, align 8, !tbaa !5
  store double %40, ptr %4, align 8, !tbaa !5
  %41 = load double, ptr %3, align 8, !tbaa !5
  %42 = load double, ptr %4, align 8, !tbaa !5
  %43 = fadd double %41, %42
  %44 = fdiv double %43, 2.000000e+00
  store double %44, ptr %6, align 8, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %7, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %39, %32
  br label %48

48:                                               ; preds = %47, %24
  br label %14, !llvm.loop !11

49:                                               ; preds = %14
  %50 = load double, ptr %6, align 8, !tbaa !5
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %50)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/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"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @Bisection_Method(double noundef %0, double noundef %1) local_unnamed_addr #0 {
  %3 = fadd double %0, %1
  %4 = fmul double %3, 5.000000e-01
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %4)
  br label %6

6:                                                ; preds = %2, %24
  %.025 = phi i32 [ 0, %2 ], [ %.1, %24 ]
  %.01624 = phi double [ %4, %2 ], [ %.117, %24 ]
  %.01823 = phi double [ %0, %2 ], [ %.119, %24 ]
  %.02022 = phi double [ %1, %2 ], [ %.121, %24 ]
  %7 = tail call double @F(double noundef %.01624)
  %8 = tail call double @F(double noundef %.01823)
  %9 = fmul double %7, %8
  %10 = fcmp ogt double %9, 0.000000e+00
  br i1 %10, label %11, label %15

11:                                               ; preds = %6
  %12 = fadd double %.02022, %.01624
  %13 = fmul double %12, 5.000000e-01
  %14 = add nsw i32 %.025, 1
  br label %24

15:                                               ; preds = %6
  %16 = tail call double @F(double noundef %.01624)
  %17 = tail call double @F(double noundef %.01823)
  %18 = fmul double %16, %17
  %19 = fcmp olt double %18, 0.000000e+00
  br i1 %19, label %20, label %24

20:                                               ; preds = %15
  %21 = fadd double %.01823, %.01624
  %22 = fmul double %21, 5.000000e-01
  %23 = add nsw i32 %.025, 1
  br label %24

24:                                               ; preds = %15, %20, %11
  %.121 = phi double [ %.02022, %11 ], [ %.01624, %20 ], [ %.02022, %15 ]
  %.119 = phi double [ %.01624, %11 ], [ %.01823, %20 ], [ %.01823, %15 ]
  %.117 = phi double [ %13, %11 ], [ %22, %20 ], [ %.01624, %15 ]
  %.1 = phi i32 [ %14, %11 ], [ %23, %20 ], [ %.025, %15 ]
  %.not = icmp eq i32 %.1, 30
  br i1 %.not, label %25, label %6, !llvm.loop !5

25:                                               ; preds = %24
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %.117)
  ret void
}

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

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

!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,LoopRotatePass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass