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

; 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 } @_Z12hybridMethodPdiddd(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
  %14 = alloca i32, align 4
  %15 = alloca double, align 8
  %16 = 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 %17

17:                                               ; preds = %55, %5
  %18 = load i32, ptr %12, align 4, !tbaa !9
  %19 = icmp sle i32 %18, 2
  br i1 %19, label %20, label %58

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

38:                                               ; preds = %20
  %39 = load double, ptr %13, align 8, !tbaa !11
  store double %39, ptr %9, align 8, !tbaa !11
  br label %42

40:                                               ; preds = %20
  %41 = load double, ptr %13, align 8, !tbaa !11
  store double %41, ptr %10, align 8, !tbaa !11
  br label %42

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

49:                                               ; preds = %42
  %50 = 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)
  %51 = getelementptr inbounds { i32, double }, ptr %6, i32 0, i32 0
  %52 = extractvalue { i32, double } %50, 0
  store i32 %52, ptr %51, align 8
  %53 = getelementptr inbounds { i32, double }, ptr %6, i32 0, i32 1
  %54 = extractvalue { i32, double } %50, 1
  store double %54, ptr %53, align 8
  store i32 1, ptr %14, align 4
  br label %103

55:                                               ; preds = %42
  %56 = load i32, ptr %12, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %12, align 4, !tbaa !9
  br label %17, !llvm.loop !13

58:                                               ; preds = %17
  br label %59

59:                                               ; preds = %96, %58
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = icmp slt i32 %60, 10000
  br i1 %61, label %62, label %97

62:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = load double, ptr %9, align 8, !tbaa !11
  %66 = call noundef double @_Z9getYvaluePdid(ptr noundef %63, i32 noundef %64, double noundef %65)
  store double %66, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = load double, ptr %10, align 8, !tbaa !11
  %70 = call noundef double @_Z9getYvaluePdid(ptr noundef %67, i32 noundef %68, double noundef %69)
  store double %70, ptr %16, align 8, !tbaa !11
  %71 = load double, ptr %10, align 8, !tbaa !11
  %72 = load double, ptr %16, align 8, !tbaa !11
  %73 = load double, ptr %10, align 8, !tbaa !11
  %74 = load double, ptr %9, align 8, !tbaa !11
  %75 = fsub double %73, %74
  %76 = fmul double %72, %75
  %77 = load double, ptr %16, align 8, !tbaa !11
  %78 = load double, ptr %15, align 8, !tbaa !11
  %79 = fsub double %77, %78
  %80 = fdiv double %76, %79
  %81 = fsub double %71, %80
  store double %81, ptr %13, align 8, !tbaa !11
  %82 = load double, ptr %13, align 8, !tbaa !11
  %83 = load double, ptr %10, align 8, !tbaa !11
  %84 = fsub double %82, %83
  %85 = call double @llvm.fabs.f64(double %84)
  %86 = load double, ptr %11, align 8, !tbaa !11
  %87 = fcmp ole double %85, %86
  br i1 %87, label %88, label %89

88:                                               ; preds = %62
  store i32 5, ptr %14, align 4
  br label %94

89:                                               ; preds = %62
  %90 = load double, ptr %10, align 8, !tbaa !11
  store double %90, ptr %9, align 8, !tbaa !11
  %91 = load double, ptr %13, align 8, !tbaa !11
  store double %91, ptr %10, align 8, !tbaa !11
  %92 = load i32, ptr %12, align 4, !tbaa !9
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %12, align 4, !tbaa !9
  store i32 0, ptr %14, align 4
  br label %94

94:                                               ; preds = %89, %88
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  %95 = load i32, ptr %14, align 4
  switch i32 %95, label %105 [
    i32 0, label %96
    i32 5, label %97
  ]

96:                                               ; preds = %94
  br label %59, !llvm.loop !15

97:                                               ; preds = %94, %59
  %98 = 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)
  %99 = getelementptr inbounds { i32, double }, ptr %6, i32 0, i32 0
  %100 = extractvalue { i32, double } %98, 0
  store i32 %100, ptr %99, align 8
  %101 = getelementptr inbounds { i32, double }, ptr %6, i32 0, i32 1
  %102 = extractvalue { i32, double } %98, 1
  store double %102, ptr %101, align 8
  store i32 1, ptr %14, align 4
  br label %103

103:                                              ; preds = %97, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %104 = load { i32, double }, ptr %6, align 8
  ret { i32, double } %104

105:                                              ; preds = %94
  unreachable
}

; 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"}
!15 = distinct !{!15, !14}


; 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 } @_Z12hybridMethodPdiddd(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
  %8 = fsub double %3, %2
  %9 = fmul double %8, 5.000000e-01
  %10 = fadd double %9, %2
  %11 = tail call noundef double @_Z9getYvaluePdid(ptr noundef %0, i32 noundef %1, double noundef %2)
  %12 = tail call noundef i32 @_Z3sgnIdEiT_(double noundef %11)
  %13 = tail call noundef double @_Z9getYvaluePdid(ptr noundef %0, i32 noundef %1, double noundef %10)
  %14 = tail call noundef i32 @_Z3sgnIdEiT_(double noundef %13)
  %15 = icmp eq i32 %12, %14
  %.128 = select i1 %15, double %3, double %10
  %.1 = select i1 %15, double %10, double %2
  %16 = fsub double %.128, %.1
  %17 = tail call double @llvm.fabs.f64(double %16)
  %18 = fcmp ugt double %17, %4
  br i1 %18, label %19, label %.thread

19:                                               ; preds = %5
  %20 = fmul double %16, 5.000000e-01
  %21 = fadd double %.1, %20
  %22 = tail call noundef double @_Z9getYvaluePdid(ptr noundef %0, i32 noundef %1, double noundef %.1)
  %23 = tail call noundef i32 @_Z3sgnIdEiT_(double noundef %22)
  %24 = tail call noundef double @_Z9getYvaluePdid(ptr noundef %0, i32 noundef %1, double noundef %21)
  %25 = tail call noundef i32 @_Z3sgnIdEiT_(double noundef %24)
  %26 = icmp eq i32 %23, %25
  %.128.1 = select i1 %26, double %.128, double %21
  %.1.1 = select i1 %26, double %21, double %.1
  %27 = fsub double %.128.1, %.1.1
  %28 = tail call double @llvm.fabs.f64(double %27)
  %29 = fcmp ugt double %28, %4
  br i1 %29, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %19, %41
  %.248 = phi double [ %.22947, %41 ], [ %.1.1, %19 ]
  %.22947 = phi double [ %37, %41 ], [ %.128.1, %19 ]
  %30 = phi i32 [ %42, %41 ], [ 3, %19 ]
  %31 = tail call noundef double @_Z9getYvaluePdid(ptr noundef %0, i32 noundef %1, double noundef %.248)
  %32 = tail call noundef double @_Z9getYvaluePdid(ptr noundef %0, i32 noundef %1, double noundef %.22947)
  %33 = fsub double %.22947, %.248
  %34 = fmul double %33, %32
  %35 = fsub double %32, %31
  %36 = fdiv double %34, %35
  %37 = fsub double %.22947, %36
  %38 = fsub double %37, %.22947
  %39 = tail call double @llvm.fabs.f64(double %38)
  %40 = fcmp ugt double %39, %4
  br i1 %40, label %41, label %.thread

41:                                               ; preds = %.lr.ph
  %42 = add nuw nsw i32 %30, 1
  %exitcond.not = icmp eq i32 %42, 10000
  br i1 %exitcond.not, label %.thread, label %.lr.ph

.thread:                                          ; preds = %.lr.ph, %41, %5, %19
  %storemerge60 = phi double [ %10, %5 ], [ %21, %19 ], [ %37, %41 ], [ %37, %.lr.ph ]
  %storemerge = phi i32 [ 1, %5 ], [ 2, %19 ], [ %30, %.lr.ph ], [ 10000, %41 ]
  store double %storemerge60, ptr %7, align 8
  store i32 %storemerge, ptr %6, align 4, !tbaa !5
  %43 = 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 } %43
}

; 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 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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