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

; 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 } @_Z12secantMethodPdiddd(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 double, align 8
  %15 = alloca double, align 8
  %16 = alloca i32, align 4
  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) #3
  store i32 1, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  br label %17

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

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load double, ptr %9, align 8, !tbaa !11
  %24 = call noundef double @_Z9getYvaluePdid(ptr noundef %21, i32 noundef %22, double noundef %23)
  store double %24, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = load double, ptr %10, align 8, !tbaa !11
  %28 = call noundef double @_Z9getYvaluePdid(ptr noundef %25, i32 noundef %26, double noundef %27)
  store double %28, ptr %15, align 8, !tbaa !11
  %29 = load double, ptr %10, align 8, !tbaa !11
  %30 = load double, ptr %15, align 8, !tbaa !11
  %31 = load double, ptr %10, align 8, !tbaa !11
  %32 = load double, ptr %9, align 8, !tbaa !11
  %33 = fsub double %31, %32
  %34 = fmul double %30, %33
  %35 = load double, ptr %15, align 8, !tbaa !11
  %36 = load double, ptr %14, align 8, !tbaa !11
  %37 = fsub double %35, %36
  %38 = fdiv double %34, %37
  %39 = fsub double %29, %38
  store double %39, ptr %13, align 8, !tbaa !11
  %40 = load double, ptr %13, align 8, !tbaa !11
  %41 = load double, ptr %10, 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 = %20
  store i32 3, ptr %16, align 4
  br label %52

47:                                               ; preds = %20
  %48 = load double, ptr %10, align 8, !tbaa !11
  store double %48, ptr %9, align 8, !tbaa !11
  %49 = load double, ptr %13, align 8, !tbaa !11
  store double %49, ptr %10, align 8, !tbaa !11
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %12, align 4, !tbaa !9
  store i32 0, ptr %16, align 4
  br label %52

52:                                               ; preds = %47, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %53 = load i32, ptr %16, align 4
  switch i32 %53, label %62 [
    i32 0, label %54
    i32 3, label %55
  ]

54:                                               ; preds = %52
  br label %17, !llvm.loop !13

55:                                               ; preds = %52, %17
  %56 = 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)
  %57 = getelementptr inbounds { i32, double }, ptr %6, i32 0, i32 0
  %58 = extractvalue { i32, double } %56, 0
  store i32 %58, ptr %57, align 8
  %59 = getelementptr inbounds { i32, double }, ptr %6, i32 0, i32 1
  %60 = extractvalue { i32, double } %56, 1
  store double %60, ptr %59, align 8
  store i32 1, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %61 = load { i32, double }, ptr %6, align 8
  ret { i32, double } %61

62:                                               ; preds = %52
  unreachable
}

; 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) #2

; 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"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 } @_Z12secantMethodPdiddd(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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  br label %9

thread-pre-split:                                 ; preds = %9
  %8 = add nuw nsw i32 %10, 1
  %exitcond.not = icmp eq i32 %8, 10000
  br i1 %exitcond.not, label %21, label %9

9:                                                ; preds = %5, %thread-pre-split
  %.01526 = phi double [ %2, %5 ], [ %.01625, %thread-pre-split ]
  %.01625 = phi double [ %3, %5 ], [ %17, %thread-pre-split ]
  %10 = phi i32 [ 1, %5 ], [ %8, %thread-pre-split ]
  %11 = tail call noundef double @_Z9getYvaluePdid(ptr noundef %0, i32 noundef %1, double noundef %.01526)
  %12 = tail call noundef double @_Z9getYvaluePdid(ptr noundef %0, i32 noundef %1, double noundef %.01625)
  %13 = fsub double %.01625, %.01526
  %14 = fmul double %13, %12
  %15 = fsub double %12, %11
  %16 = fdiv double %14, %15
  %17 = fsub double %.01625, %16
  %18 = fsub double %17, %.01625
  %19 = tail call double @llvm.fabs.f64(double %18)
  %20 = fcmp ugt double %19, %4
  br i1 %20, label %thread-pre-split, label %21

21:                                               ; preds = %9, %thread-pre-split
  %.lcssa = phi i32 [ %10, %9 ], [ 10000, %thread-pre-split ]
  store double %17, ptr %7, align 8, !tbaa !5
  store i32 %.lcssa, ptr %6, align 4, !tbaa !9
  %22 = 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) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  ret { i32, double } %22
}

; 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) #2

; 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


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