; LLVM IR from arasgungore/EE242-projects :: SecantAndBisectionMethods/main.ll (Z15bisectionMethodPdiddd)

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

%"struct.std::pair" = type { i32, double }

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

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

; Function Attrs: mustprogress uwtable
define dso_local { i32, double } @_Z15bisectionMethodPdiddd(ptr noundef %0, i32 noundef %1, double noundef %2, double noundef %3, double noundef %4) #1 {
  %6 = alloca %"struct.std::pair", align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store double %2, ptr %9, align 8, !tbaa !11
  store double %3, ptr %10, align 8, !tbaa !11
  store double %4, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 1, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  br label %14

14:                                               ; preds = %47, %5
  %15 = load i32, ptr %12, align 4, !tbaa !9
  %16 = icmp slt i32 %15, 10000
  br i1 %16, label %17, label %50

17:                                               ; preds = %14
  %18 = load double, ptr %9, align 8, !tbaa !11
  %19 = load double, ptr %10, align 8, !tbaa !11
  %20 = load double, ptr %9, align 8, !tbaa !11
  %21 = fsub double %19, %20
  %22 = fdiv double %21, 2.000000e+00
  %23 = fadd double %18, %22
  store double %23, ptr %13, align 8, !tbaa !11
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = load double, ptr %9, align 8, !tbaa !11
  %27 = call noundef double @_Z9getYvaluePdid(ptr noundef %24, i32 noundef %25, double noundef %26)
  %28 = call noundef i32 @_Z3sgnIdEiT_(double noundef %27)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = load double, ptr %13, align 8, !tbaa !11
  %32 = call noundef double @_Z9getYvaluePdid(ptr noundef %29, i32 noundef %30, double noundef %31)
  %33 = call noundef i32 @_Z3sgnIdEiT_(double noundef %32)
  %34 = icmp eq i32 %28, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %17
  %36 = load double, ptr %13, align 8, !tbaa !11
  store double %36, ptr %9, align 8, !tbaa !11
  br label %39

37:                                               ; preds = %17
  %38 = load double, ptr %13, align 8, !tbaa !11
  store double %38, ptr %10, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %37, %35
  %40 = load double, ptr %10, align 8, !tbaa !11
  %41 = load double, ptr %9, align 8, !tbaa !11
  %42 = fsub double %40, %41
  %43 = call double @llvm.fabs.f64(double %42)
  %44 = load double, ptr %11, align 8, !tbaa !11
  %45 = fcmp ole double %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %39
  br label %50

47:                                               ; preds = %39
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %12, align 4, !tbaa !9
  br label %14, !llvm.loop !13

50:                                               ; preds = %46, %14
  %51 = call { i32, double } @_ZSt9make_pairIRiRdESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4) %12, ptr noundef nonnull align 8 dereferenceable(8) %13)
  %52 = getelementptr inbounds { i32, double }, ptr %6, i32 0, i32 0
  %53 = extractvalue { i32, double } %51, 0
  store i32 %53, ptr %52, align 8
  %54 = getelementptr inbounds { i32, double }, ptr %6, i32 0, i32 1
  %55 = extractvalue { i32, double } %51, 1
  store double %55, ptr %54, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %56 = load { i32, double }, ptr %6, align 8
  ret { i32, double } %56
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sgnIdEiT_(double noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z9getYvaluePdid(ptr noundef, i32 noundef, double noundef) #1

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

; Function Attrs: mustprogress uwtable
declare dso_local { i32, double } @_ZSt9make_pairIRiRdESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 8 dereferenceable(8)) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local { i32, double } @_Z15bisectionMethodPdiddd(ptr noundef %0, i32 noundef %1, double noundef %2, double noundef %3, double noundef %4) local_unnamed_addr #1 {
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  br label %8

8:                                                ; preds = %5, %21
  %.014 = phi double [ %2, %5 ], [ %.1, %21 ]
  %.01013 = phi double [ %3, %5 ], [ %.111, %21 ]
  %9 = phi i32 [ 1, %5 ], [ %22, %21 ]
  %10 = fsub double %.01013, %.014
  %11 = fmul double %10, 5.000000e-01
  %12 = fadd double %.014, %11
  %13 = tail call noundef double @_Z9getYvaluePdid(ptr noundef %0, i32 noundef %1, double noundef %.014)
  %14 = tail call noundef i32 @_Z3sgnIdEiT_(double noundef %13)
  %15 = tail call noundef double @_Z9getYvaluePdid(ptr noundef %0, i32 noundef %1, double noundef %12)
  %16 = tail call noundef i32 @_Z3sgnIdEiT_(double noundef %15)
  %17 = icmp eq i32 %14, %16
  %.111 = select i1 %17, double %.01013, double %12
  %.1 = select i1 %17, double %12, double %.014
  %18 = fsub double %.111, %.1
  %19 = tail call double @llvm.fabs.f64(double %18)
  %20 = fcmp ugt double %19, %4
  br i1 %20, label %21, label %23

21:                                               ; preds = %8
  %22 = add nuw nsw i32 %9, 1
  %exitcond.not = icmp eq i32 %22, 10000
  br i1 %exitcond.not, label %23, label %8, !llvm.loop !5

23:                                               ; preds = %8, %21
  %.lcssa = phi i32 [ %9, %8 ], [ 10000, %21 ]
  store double %12, ptr %7, align 8
  store i32 %.lcssa, ptr %6, align 4, !tbaa !7
  %24 = call { i32, double } @_ZSt9make_pairIRiRdESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 8 dereferenceable(8) %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  ret { i32, double } %24
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sgnIdEiT_(double noundef) local_unnamed_addr #2

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

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

; Function Attrs: mustprogress uwtable
declare dso_local { i32, double } @_ZSt9make_pairIRiRdESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { mustprogress 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass