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

; 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.Harness::internal::Tracer" = type <{ i32, [4 x i8], ptr, ptr, i64, [8 x i8] }>
%"class.tbb::tick_count::interval_t" = type { i64 }

@.str = external hidden unnamed_addr constant [91 x i8], align 1
@_ZN7Harness8internalL6tracerE = external hidden global %"class.Harness::internal::Tracer", align 8
@_ZL7Verbose = external hidden global i8, align 1
@_ZZ14TestResolutionvE12target_value = external hidden global double, align 8
@_ZZ14TestResolutionvE10step_value = external hidden global double, align 8
@_ZZ14TestResolutionvE11range_value = external hidden global i32, align 4
@.str.32 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [35 x i8], align 1
@__FUNCTION__._Z14TestResolutionv = external hidden unnamed_addr constant [15 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [42 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: 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 nounwind uwtable
declare dso_local noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33), i32 noundef, ptr noundef, i64 noundef, ptr noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, ...) #0 align 2

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

9:                                                ; preds = %48, %0
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = load i32, ptr @_ZZ14TestResolutionvE11range_value, align 4, !tbaa !9
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %15 = load double, ptr @_ZZ14TestResolutionvE12target_value, align 8, !tbaa !5
  %16 = load double, ptr @_ZZ14TestResolutionvE10step_value, align 8, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = sitofp i32 %17 to double
  %19 = call double @llvm.fmuladd.f64(double %16, double %18, double %15)
  store double %19, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %20 = load double, ptr %4, align 8, !tbaa !5
  call void @_ZN3tbb10tick_count10interval_tC2Ed(ptr noundef nonnull align 8 dereferenceable(8) %5, double noundef %20)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %21 = call noundef double @_ZNK3tbb10tick_count10interval_t7secondsEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  store double %21, ptr %6, align 8, !tbaa !5
  %22 = load double, ptr %4, align 8, !tbaa !5
  %23 = load double, ptr %6, align 8, !tbaa !5
  %24 = fsub double %22, %23
  %25 = load double, ptr %1, align 8, !tbaa !5
  %26 = fadd double %25, %24
  store double %26, ptr %1, align 8, !tbaa !5
  %27 = load double, ptr %2, align 8, !tbaa !5
  %28 = load double, ptr %4, align 8, !tbaa !5
  %29 = load double, ptr %6, align 8, !tbaa !5
  %30 = fsub double %28, %29
  %31 = fcmp olt double %27, %30
  br i1 %31, label %32, label %36

32:                                               ; preds = %14
  %33 = load double, ptr %4, align 8, !tbaa !5
  %34 = load double, ptr %6, align 8, !tbaa !5
  %35 = fsub double %33, %34
  store double %35, ptr %2, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %32, %14
  %37 = load double, ptr %6, align 8, !tbaa !5
  %38 = fcmp oge double %37, 0.000000e+00
  br i1 %38, label %39, label %46

39:                                               ; preds = %36
  %40 = load double, ptr %4, align 8, !tbaa !5
  %41 = load double, ptr %6, align 8, !tbaa !5
  %42 = fsub double %40, %41
  %43 = call noundef double @_ZN3tbb10tick_count10resolutionEv()
  %44 = fcmp olt double %42, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %39
  br label %47

46:                                               ; preds = %39, %36
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str, i32 noundef 166, ptr noundef @.str.32, ptr noundef @.str.33)
  br label %47

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

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

51:                                               ; preds = %13
  %52 = load double, ptr %1, align 8, !tbaa !5
  %53 = load i32, ptr @_ZZ14TestResolutionvE11range_value, align 4, !tbaa !9
  %54 = mul nsw i32 2, %53
  %55 = add nsw i32 %54, 1
  %56 = sitofp i32 %55 to double
  %57 = fdiv double %52, %56
  %58 = call noundef double @_ZN3tbb10tick_count10resolutionEv()
  %59 = fdiv double %57, %58
  store double %59, ptr %1, align 8, !tbaa !5
  %60 = call noundef double @_ZN3tbb10tick_count10resolutionEv()
  %61 = load double, ptr %2, align 8, !tbaa !5
  %62 = fdiv double %61, %60
  store double %62, ptr %2, align 8, !tbaa !5
  %63 = load i8, ptr @_ZL7Verbose, align 1, !tbaa !13, !range !15, !noundef !16
  %64 = trunc i8 %63 to i1
  br i1 %64, label %66, label %65

65:                                               ; preds = %51
  br label %70

66:                                               ; preds = %51
  %67 = call noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33) @_ZN7Harness8internalL6tracerE, i32 noundef 0, ptr noundef @.str, i64 noundef 170, ptr noundef @__FUNCTION__._Z14TestResolutionv)
  %68 = load double, ptr %1, align 8, !tbaa !5
  %69 = load double, ptr %2, align 8, !tbaa !5
  call void (ptr, ptr, ...) @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33) %67, ptr noundef @.str.34, double noundef %68, double noundef %69)
  br label %70

70:                                               ; preds = %66, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret void
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3tbb10tick_count10resolutionEv() #3 align 2

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 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}


; 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.Harness::internal::Tracer" = type <{ i32, [4 x i8], ptr, ptr, i64, [8 x i8] }>
%"class.tbb::tick_count::interval_t" = type { i64 }

@.str = external hidden unnamed_addr constant [91 x i8], align 1
@_ZN7Harness8internalL6tracerE = external hidden global %"class.Harness::internal::Tracer", align 8
@_ZL7Verbose = external hidden local_unnamed_addr global i8, align 1
@_ZZ14TestResolutionvE12target_value = external hidden local_unnamed_addr global double, align 8
@_ZZ14TestResolutionvE10step_value = external hidden local_unnamed_addr global double, align 8
@_ZZ14TestResolutionvE11range_value = external hidden local_unnamed_addr global i32, align 4
@.str.32 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [35 x i8], align 1
@__FUNCTION__._Z14TestResolutionv = external hidden unnamed_addr constant [15 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [42 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: 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 nounwind uwtable
declare dso_local noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33), i32 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, ...) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14TestResolutionv() local_unnamed_addr #0 {
  %1 = alloca %"class.tbb::tick_count::interval_t", align 8
  %2 = load i32, ptr @_ZZ14TestResolutionvE11range_value, align 4, !tbaa !5
  %.not22 = icmp slt i32 %2, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %3 = sub nsw i32 0, %2
  br label %.lr.ph

._crit_edge:                                      ; preds = %21, %0
  %.018.lcssa = phi double [ 0.000000e+00, %0 ], [ %.1, %21 ]
  %.0.lcssa = phi double [ 0.000000e+00, %0 ], [ %14, %21 ]
  %.lcssa = phi i32 [ %2, %0 ], [ %23, %21 ]
  %4 = call noundef double @_ZN3tbb10tick_count10resolutionEv()
  %5 = call noundef double @_ZN3tbb10tick_count10resolutionEv()
  %6 = load i8, ptr @_ZL7Verbose, align 1, !tbaa !9, !range !11, !noundef !12
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %24, label %32

.lr.ph:                                           ; preds = %.lr.ph.preheader, %21
  %.025 = phi double [ %14, %21 ], [ 0.000000e+00, %.lr.ph.preheader ]
  %.01824 = phi double [ %.1, %21 ], [ 0.000000e+00, %.lr.ph.preheader ]
  %.01923 = phi i32 [ %22, %21 ], [ %3, %.lr.ph.preheader ]
  %8 = load double, ptr @_ZZ14TestResolutionvE12target_value, align 8, !tbaa !13
  %9 = load double, ptr @_ZZ14TestResolutionvE10step_value, align 8, !tbaa !13
  %10 = sitofp i32 %.01923 to double
  %11 = call double @llvm.fmuladd.f64(double %9, double %10, double %8)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  call void @_ZN3tbb10tick_count10interval_tC2Ed(ptr noundef nonnull align 8 dereferenceable(8) %1, double noundef %11)
  %12 = call noundef double @_ZNK3tbb10tick_count10interval_t7secondsEv(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %13 = fsub double %11, %12
  %14 = fadd double %.025, %13
  %15 = fcmp olt double %.01824, %13
  %.1 = select i1 %15, double %13, double %.01824
  %16 = fcmp ult double %12, 0.000000e+00
  br i1 %16, label %20, label %17

17:                                               ; preds = %.lr.ph
  %18 = call noundef double @_ZN3tbb10tick_count10resolutionEv()
  %19 = fcmp olt double %13, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %17, %.lr.ph
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str, i32 noundef 166, ptr noundef nonnull @.str.32, ptr noundef nonnull @.str.33)
  br label %21

21:                                               ; preds = %17, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  %22 = add nsw i32 %.01923, 1
  %23 = load i32, ptr @_ZZ14TestResolutionvE11range_value, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.01923, %23
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !15

24:                                               ; preds = %._crit_edge
  %25 = fdiv double %.018.lcssa, %5
  %26 = shl nsw i32 %.lcssa, 1
  %27 = or disjoint i32 %26, 1
  %28 = sitofp i32 %27 to double
  %29 = fdiv double %.0.lcssa, %28
  %30 = fdiv double %29, %4
  %31 = call noundef ptr @_ZN7Harness8internal6Tracer14set_trace_infoEiPKcmS3_(ptr noundef nonnull align 8 dereferenceable(33) @_ZN7Harness8internalL6tracerE, i32 noundef 0, ptr noundef nonnull @.str, i64 noundef 170, ptr noundef nonnull @__FUNCTION__._Z14TestResolutionv)
  call void (ptr, ptr, ...) @_ZN7Harness8internal6Tracer5traceEPKcz(ptr noundef nonnull align 8 dereferenceable(33) %31, ptr noundef nonnull @.str.34, double noundef %30, double noundef %25)
  br label %32

32:                                               ; preds = %._crit_edge, %24
  ret void
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3tbb10tick_count10resolutionEv() local_unnamed_addr #3 align 2

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 = { 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 #4 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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