; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/rml/test/test_rml_mixed.ll (ZN19ThreadLevelRecorder4dumpEv)

; 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::interval_t" = type { i64 }
%class.ThreadLevelRecorder = type { %"struct.tbb::atomic", %"struct.tbb::atomic.0", [1048576 x %"struct.ThreadLevelRecorder::record"] }
%"struct.tbb::atomic" = type { %"struct.tbb::internal::atomic_impl_with_arithmetic" }
%"struct.tbb::internal::atomic_impl_with_arithmetic" = type { %"struct.tbb::internal::atomic_impl" }
%"struct.tbb::internal::atomic_impl" = type { %"struct.tbb::internal::aligned_storage" }
%"struct.tbb::internal::aligned_storage" = type { i32 }
%"struct.tbb::atomic.0" = type { %"struct.tbb::internal::atomic_impl_with_arithmetic.1" }
%"struct.tbb::internal::atomic_impl_with_arithmetic.1" = type { %"struct.tbb::internal::atomic_impl.2" }
%"struct.tbb::internal::atomic_impl.2" = type { %"struct.tbb::internal::aligned_storage.3" }
%"struct.tbb::internal::aligned_storage.3" = type { i32 }
%"struct.ThreadLevelRecorder::record" = type <{ %"class.tbb::tick_count", i32, [4 x i8] }>
%"class.tbb::tick_count" = type { i64 }

@.str.17 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [7 x i8], align 1

; 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 void @_ZN19ThreadLevelRecorder4dumpEv(ptr noundef nonnull align 8 dereferenceable(16777224) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %"class.tbb::tick_count::interval_t", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %8 = call noalias ptr @fopen(ptr noundef @.str.17, ptr noundef @.str.18)
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %1
  call void @perror(ptr noundef @.str.19)
  call void @exit(i32 noundef 1) #7
  unreachable

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %13 = getelementptr inbounds %class.ThreadLevelRecorder, ptr %7, i32 0, i32 1
  %14 = call noundef i32 @_ZNVK3tbb8internal11atomic_implIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %13)
  store i32 %14, ptr %4, align 4, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = icmp ugt i32 %15, 1048576
  br i1 %16, label %17, label %20

17:                                               ; preds = %12
  %18 = getelementptr inbounds %class.ThreadLevelRecorder, ptr %7, i32 0, i32 1
  %19 = call noundef i32 @_ZNVK3tbb8internal11atomic_implIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %18)
  store i32 %19, ptr %4, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %17, %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %46, %20
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = icmp ult i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %49

26:                                               ; preds = %21
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %28 = getelementptr inbounds %class.ThreadLevelRecorder, ptr %7, i32 0, i32 2
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds [1048576 x %"struct.ThreadLevelRecorder::record"], ptr %28, i64 0, i64 %30
  %32 = getelementptr inbounds %"struct.ThreadLevelRecorder::record", ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds %class.ThreadLevelRecorder, ptr %7, i32 0, i32 2
  %34 = getelementptr inbounds [1048576 x %"struct.ThreadLevelRecorder::record"], ptr %33, i64 0, i64 0
  %35 = getelementptr inbounds %"struct.ThreadLevelRecorder::record", ptr %34, i32 0, i32 0
  %36 = call i64 @_ZN3tbbmiERKNS_10tick_countES2_(ptr noundef nonnull align 8 dereferenceable(8) %32, ptr noundef nonnull align 8 dereferenceable(8) %35)
  %37 = getelementptr inbounds %"class.tbb::tick_count::interval_t", ptr %6, i32 0, i32 0
  store i64 %36, ptr %37, align 8
  %38 = call noundef double @_ZNK3tbb10tick_count10interval_t7secondsEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %39 = getelementptr inbounds %class.ThreadLevelRecorder, ptr %7, i32 0, i32 2
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds [1048576 x %"struct.ThreadLevelRecorder::record"], ptr %39, i64 0, i64 %41
  %43 = getelementptr inbounds %"struct.ThreadLevelRecorder::record", ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !11
  %45 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str.20, double noundef %38, i32 noundef %44) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %46

46:                                               ; preds = %26
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = add i32 %47, 1
  store i32 %48, ptr %5, align 4, !tbaa !9
  br label %21, !llvm.loop !15

49:                                               ; preds = %25
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = call i32 @fclose(ptr noundef %50)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret void
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

declare void @perror(ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNVK3tbb8internal11atomic_implIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #4

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

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

declare i32 @fclose(ptr noundef) #2

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 = { "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 = { noreturn nounwind "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 = { nounwind "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 #5 = { 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 #6 = { nounwind }
attributes #7 = { noreturn 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, !10, i64 8}
!12 = !{!"_ZTSN19ThreadLevelRecorder6recordE", !13, i64 0, !10, i64 8}
!13 = !{!"_ZTSN3tbb10tick_countE", !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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::interval_t" = type { i64 }
%"struct.ThreadLevelRecorder::record" = type <{ %"class.tbb::tick_count", i32, [4 x i8] }>
%"class.tbb::tick_count" = type { i64 }

@.str.17 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [7 x i8], align 1

; 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 void @_ZN19ThreadLevelRecorder4dumpEv(ptr noundef nonnull align 8 dereferenceable(16777224) %0) local_unnamed_addr #1 align 2 {
  %2 = alloca %"class.tbb::tick_count::interval_t", align 8
  %3 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.17, ptr noundef nonnull @.str.18)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %1
  tail call void @perror(ptr noundef nonnull @.str.19) #5
  tail call void @exit(i32 noundef 1) #6
  unreachable

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = tail call noundef i32 @_ZNVK3tbb8internal11atomic_implIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %6)
  %8 = icmp ugt i32 %7, 1048576
  br i1 %8, label %9, label %11

9:                                                ; preds = %5
  %10 = tail call noundef i32 @_ZNVK3tbb8internal11atomic_implIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %6)
  br label %11

11:                                               ; preds = %9, %5
  %.09 = phi i32 [ %10, %9 ], [ %7, %5 ]
  %.not13 = icmp eq i32 %.09, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %wide.trip.count = zext i32 %.09 to i64
  br label %14

._crit_edge:                                      ; preds = %14, %11
  %13 = call i32 @fclose(ptr noundef nonnull %3)
  ret void

14:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #7
  %15 = getelementptr inbounds [1048576 x %"struct.ThreadLevelRecorder::record"], ptr %12, i64 0, i64 %indvars.iv
  %16 = call i64 @_ZN3tbbmiERKNS_10tick_countES2_(ptr noundef nonnull align 8 dereferenceable(8) %15, ptr noundef nonnull align 8 dereferenceable(8) %12)
  store i64 %16, ptr %2, align 8
  %17 = call noundef double @_ZNK3tbb10tick_count10interval_t7secondsEv(ptr noundef nonnull align 8 dereferenceable(8) %2)
  %18 = getelementptr inbounds i8, ptr %15, i64 8
  %19 = load i32, ptr %18, align 8, !tbaa !5
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.20, double noundef %17, i32 noundef %19) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %14, !llvm.loop !12
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNVK3tbb8internal11atomic_implIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; 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 #4

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

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 = { nofree nounwind "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 = { noreturn nounwind "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 = { 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 #5 = { cold }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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, !11, i64 8}
!6 = !{!"_ZTSN19ThreadLevelRecorder6recordE", !7, i64 0, !11, i64 8}
!7 = !{!"_ZTSN3tbb10tick_countE", !8, i64 0}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass