; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/test/test_tick_count.ll (Z15TestSimpleDelayidd)

; 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.tbb::tick_count" = type { i64 }
%"class.tbb::tick_count::interval_t" = type { i64 }

@.str = external hidden unnamed_addr constant [91 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [44 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11ReportErrorPKciS0_S0_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #0

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local i64 @_ZN3tbbmiERKNS_10tick_countES2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK3tbb10tick_count10interval_t7secondsEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15TestSimpleDelayidd(i32 noundef %0, double noundef %1, double noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca %"class.tbb::tick_count", align 8
  %11 = alloca %"class.tbb::tick_count::interval_t", align 8
  %12 = alloca %"class.tbb::tick_count", align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store double 0.000000e+00, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 -1, ptr %9, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %48, %3
  %14 = load i32, ptr %9, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %51

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %19 = call i64 @_ZN3tbb10tick_count3nowEv()
  %20 = getelementptr inbounds %"class.tbb::tick_count", ptr %10, i32 0, i32 0
  store i64 %19, ptr %20, align 8
  %21 = load double, ptr %5, align 8, !tbaa !9
  %22 = fcmp une double %21, 0.000000e+00
  br i1 %22, label %23, label %25

23:                                               ; preds = %18
  %24 = load double, ptr %5, align 8, !tbaa !9
  call void @_ZL15WaitForDurationd(double noundef %24)
  br label %25

25:                                               ; preds = %23, %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %26 = call i64 @_ZN3tbb10tick_count3nowEv()
  %27 = getelementptr inbounds %"class.tbb::tick_count", ptr %12, i32 0, i32 0
  store i64 %26, ptr %27, align 8
  %28 = call i64 @_ZN3tbbmiERKNS_10tick_countES2_(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %29 = getelementptr inbounds %"class.tbb::tick_count::interval_t", ptr %11, i32 0, i32 0
  store i64 %28, ptr %29, align 8
  %30 = call noundef double @_ZNK3tbb10tick_count10interval_t7secondsEv(ptr noundef nonnull align 8 dereferenceable(8) %11)
  %31 = load double, ptr %5, align 8, !tbaa !9
  %32 = fsub double %30, %31
  store double %32, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = icmp sge i32 %33, 0
  br i1 %34, label %35, label %42

35:                                               ; preds = %25
  %36 = load double, ptr %8, align 8, !tbaa !9
  %37 = load double, ptr %6, align 8, !tbaa !9
  %38 = fcmp ogt double %36, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %35
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %7, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %39, %35, %25
  %43 = load double, ptr %8, align 8, !tbaa !9
  %44 = fcmp oge double %43, 0.000000e+00
  br i1 %44, label %45, label %46

45:                                               ; preds = %42
  br label %47

46:                                               ; preds = %42
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str, i32 noundef 75, ptr noundef @.str.22, ptr noundef @.str.23)
  br label %47

47:                                               ; preds = %46, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %48

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

51:                                               ; preds = %17
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sdiv i32 %53, 4
  %55 = icmp slt i32 %52, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %51
  br label %58

57:                                               ; preds = %51
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str, i32 noundef 77, ptr noundef @.str.24, ptr noundef @.str.25)
  br label %58

58:                                               ; preds = %57, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local i64 @_ZN3tbb10tick_count3nowEv() #2 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL15WaitForDurationd(double noundef) #0

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !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.tbb::tick_count" = type { i64 }
%"class.tbb::tick_count::interval_t" = type { i64 }

@.str = external hidden unnamed_addr constant [91 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [44 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11ReportErrorPKciS0_S0_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local i64 @_ZN3tbbmiERKNS_10tick_countES2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK3tbb10tick_count10interval_t7secondsEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15TestSimpleDelayidd(i32 noundef %0, double noundef %1, double noundef %2) local_unnamed_addr #0 {
  %4 = alloca %"class.tbb::tick_count", align 8
  %5 = alloca %"class.tbb::tick_count::interval_t", align 8
  %6 = alloca %"class.tbb::tick_count", align 8
  %7 = icmp sgt i32 %0, -1
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %8 = fcmp une double %1, 0.000000e+00
  br i1 %8, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %19
  %.016.us = phi i32 [ %20, %19 ], [ -1, %.lr.ph ]
  %.01215.us = phi i32 [ %.1.us, %19 ], [ 0, %.lr.ph ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %9 = call i64 @_ZN3tbb10tick_count3nowEv()
  store i64 %9, ptr %4, align 8
  call void @_ZL15WaitForDurationd(double noundef %1)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %10 = call i64 @_ZN3tbb10tick_count3nowEv()
  store i64 %10, ptr %6, align 8
  %11 = call i64 @_ZN3tbbmiERKNS_10tick_countES2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %4)
  store i64 %11, ptr %5, align 8
  %12 = call noundef double @_ZNK3tbb10tick_count10interval_t7secondsEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  %13 = fsub double %12, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  %14 = icmp sgt i32 %.016.us, -1
  %15 = fcmp ogt double %13, %2
  %or.cond.us = and i1 %14, %15
  %16 = zext i1 %or.cond.us to i32
  %.1.us = add nuw nsw i32 %.01215.us, %16
  %17 = fcmp ult double %13, 0.000000e+00
  br i1 %17, label %18, label %19

18:                                               ; preds = %.lr.ph.split.us
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str, i32 noundef 75, ptr noundef nonnull @.str.22, ptr noundef nonnull @.str.23)
  br label %19

19:                                               ; preds = %18, %.lr.ph.split.us
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  %20 = add nsw i32 %.016.us, 1
  %exitcond18.not = icmp eq i32 %20, %0
  br i1 %exitcond18.not, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !5

._crit_edge:                                      ; preds = %33, %19, %3
  %.012.lcssa = phi i32 [ 0, %3 ], [ %.1.us, %19 ], [ %.1, %33 ]
  %21 = sdiv i32 %0, 4
  %22 = icmp slt i32 %.012.lcssa, %21
  br i1 %22, label %36, label %35

.lr.ph.split:                                     ; preds = %.lr.ph, %33
  %.016 = phi i32 [ %34, %33 ], [ -1, %.lr.ph ]
  %.01215 = phi i32 [ %.1, %33 ], [ 0, %.lr.ph ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %23 = call i64 @_ZN3tbb10tick_count3nowEv()
  store i64 %23, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %24 = call i64 @_ZN3tbb10tick_count3nowEv()
  store i64 %24, ptr %6, align 8
  %25 = call i64 @_ZN3tbbmiERKNS_10tick_countES2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %4)
  store i64 %25, ptr %5, align 8
  %26 = call noundef double @_ZNK3tbb10tick_count10interval_t7secondsEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  %27 = fsub double %26, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  %28 = icmp sgt i32 %.016, -1
  %29 = fcmp ogt double %27, %2
  %or.cond = and i1 %28, %29
  %30 = zext i1 %or.cond to i32
  %.1 = add nuw nsw i32 %.01215, %30
  %31 = fcmp ult double %27, 0.000000e+00
  br i1 %31, label %32, label %33

32:                                               ; preds = %.lr.ph.split
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str, i32 noundef 75, ptr noundef nonnull @.str.22, ptr noundef nonnull @.str.23)
  br label %33

33:                                               ; preds = %.lr.ph.split, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  %34 = add nsw i32 %.016, 1
  %exitcond.not = icmp eq i32 %34, %0
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !5

35:                                               ; preds = %._crit_edge
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str, i32 noundef 77, ptr noundef nonnull @.str.24, ptr noundef nonnull @.str.25)
  br label %36

36:                                               ; preds = %._crit_edge, %35
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local i64 @_ZN3tbb10tick_count3nowEv() local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL15WaitForDurationd(double noundef) local_unnamed_addr #0

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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