; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/old/test_concurrent_vector_v2.ll (Z8TestMainv)

; 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::task_scheduler_init" = type { ptr }

@_ZL9MinThread = external hidden global i32, align 4
@.str.43 = external hidden unnamed_addr constant [45 x i8], align 1
@_ZL9MaxThread = external hidden global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z17TestResizeAndCopyv() #0

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

declare i32 @__gxx_personality_v0(...)

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

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z12TestCapacityv() #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z8TestMainv() #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca %"class.tbb::task_scheduler_init", align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = load i32, ptr @_ZL9MinThread, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 1
  br i1 %6, label %7, label %10

7:                                                ; preds = %0
  %8 = load i32, ptr @_ZL9MinThread, align 4, !tbaa !5
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str.43, i32 noundef %8)
  br label %10

10:                                               ; preds = %7, %0
  call void @_Z18TestIteratorTraitsIN3tbb8internal15vector_iteratorINS0_17concurrent_vectorI3FooEES4_EES4_Evv()
  call void @_Z18TestIteratorTraitsIN3tbb8internal15vector_iteratorINS0_17concurrent_vectorI3FooEEKS4_EES6_Evv()
  call void @_Z17TestSequentialForIN3tbb17concurrent_vectorI3FooEEEvv()
  call void @_Z17TestResizeAndCopyv()
  call void @_Z10TestAssignv()
  call void @_Z12TestCapacityv()
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  %11 = load i32, ptr @_ZL9MinThread, align 4, !tbaa !5
  store i32 %11, ptr %1, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %24, %10
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = load i32, ptr @_ZL9MaxThread, align 4, !tbaa !5
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %31

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %18 = load i32, ptr %1, align 4, !tbaa !5
  call void @_ZN3tbb19task_scheduler_initC2Eim(ptr noundef nonnull align 8 dereferenceable(8) %2, i32 noundef %18, i64 noundef 0)
  %19 = load i32, ptr %1, align 4, !tbaa !5
  invoke void @_Z15TestParallelFori(i32 noundef %19)
          to label %20 unwind label %27

20:                                               ; preds = %17
  invoke void @_Z27TestConcurrentGrowToAtLeastv()
          to label %21 unwind label %27

21:                                               ; preds = %20
  %22 = load i32, ptr %1, align 4, !tbaa !5
  invoke void @_Z20TestConcurrentGrowByi(i32 noundef %22)
          to label %23 unwind label %27

23:                                               ; preds = %21
  call void @_ZN3tbb19task_scheduler_initD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  br label %24

24:                                               ; preds = %23
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %1, align 4, !tbaa !5
  br label %12, !llvm.loop !9

27:                                               ; preds = %21, %20, %17
  %28 = landingpad { ptr, i32 }
          cleanup
  %29 = extractvalue { ptr, i32 } %28, 0
  store ptr %29, ptr %3, align 8
  %30 = extractvalue { ptr, i32 } %28, 1
  store i32 %30, ptr %4, align 4
  call void @_ZN3tbb19task_scheduler_initD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %32

31:                                               ; preds = %16
  call void @_ZL14TestFindPrimesv()
  call void @_Z8TestSortv()
  ret i32 0

32:                                               ; preds = %27
  %33 = load ptr, ptr %3, align 8
  %34 = load i32, ptr %4, align 4
  %35 = insertvalue { ptr, i32 } poison, ptr %33, 0
  %36 = insertvalue { ptr, i32 } %35, i32 %34, 1
  resume { ptr, i32 } %36
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z27TestConcurrentGrowToAtLeastv() #0

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z10TestAssignv() #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8TestSortv() #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z18TestIteratorTraitsIN3tbb8internal15vector_iteratorINS0_17concurrent_vectorI3FooEES4_EES4_Evv() #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z18TestIteratorTraitsIN3tbb8internal15vector_iteratorINS0_17concurrent_vectorI3FooEEKS4_EES6_Evv() #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z17TestSequentialForIN3tbb17concurrent_vectorI3FooEEEvv() #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb19task_scheduler_initC2Eim(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef, i64 noundef) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3tbb19task_scheduler_initD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL14TestFindPrimesv() #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 = { "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 = { 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 = distinct !{!9, !10}
!10 = !{!"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::task_scheduler_init" = type { ptr }

@_ZL9MinThread = external hidden local_unnamed_addr global i32, align 4
@.str.43 = external hidden unnamed_addr constant [45 x i8], align 1
@_ZL9MaxThread = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z17TestResizeAndCopyv() 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

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z12TestCapacityv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z8TestMainv() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.tbb::task_scheduler_init", align 8
  %2 = load i32, ptr @_ZL9MinThread, align 4, !tbaa !5
  %3 = icmp slt i32 %2, 1
  br i1 %3, label %4, label %6

4:                                                ; preds = %0
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.43, i32 noundef %2)
  br label %6

6:                                                ; preds = %4, %0
  tail call void @_Z18TestIteratorTraitsIN3tbb8internal15vector_iteratorINS0_17concurrent_vectorI3FooEES4_EES4_Evv()
  tail call void @_Z18TestIteratorTraitsIN3tbb8internal15vector_iteratorINS0_17concurrent_vectorI3FooEEKS4_EES6_Evv()
  tail call void @_Z17TestSequentialForIN3tbb17concurrent_vectorI3FooEEEvv()
  tail call void @_Z17TestResizeAndCopyv()
  tail call void @_Z10TestAssignv()
  tail call void @_Z12TestCapacityv()
  %7 = load i32, ptr @_ZL9MinThread, align 4, !tbaa !5
  %8 = load i32, ptr @_ZL9MaxThread, align 4, !tbaa !5
  %.not7 = icmp sgt i32 %7, %8
  br i1 %.not7, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %11, %6
  call void @_ZL14TestFindPrimesv()
  call void @_Z8TestSortv()
  ret i32 0

.lr.ph:                                           ; preds = %6, %11
  %.08 = phi i32 [ %12, %11 ], [ %7, %6 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  call void @_ZN3tbb19task_scheduler_initC2Eim(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %.08, i64 noundef 0)
  invoke void @_Z15TestParallelFori(i32 noundef %.08)
          to label %9 unwind label %14

9:                                                ; preds = %.lr.ph
  invoke void @_Z27TestConcurrentGrowToAtLeastv()
          to label %10 unwind label %14

10:                                               ; preds = %9
  invoke void @_Z20TestConcurrentGrowByi(i32 noundef %.08)
          to label %11 unwind label %14

11:                                               ; preds = %10
  call void @_ZN3tbb19task_scheduler_initD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %1) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  %12 = add nsw i32 %.08, 1
  %13 = load i32, ptr @_ZL9MaxThread, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.08, %13
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

14:                                               ; preds = %10, %9, %.lr.ph
  %15 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN3tbb19task_scheduler_initD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %1) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  resume { ptr, i32 } %15
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z27TestConcurrentGrowToAtLeastv() local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z10TestAssignv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8TestSortv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z18TestIteratorTraitsIN3tbb8internal15vector_iteratorINS0_17concurrent_vectorI3FooEES4_EES4_Evv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z18TestIteratorTraitsIN3tbb8internal15vector_iteratorINS0_17concurrent_vectorI3FooEEKS4_EES6_Evv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z17TestSequentialForIN3tbb17concurrent_vectorI3FooEEEvv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb19task_scheduler_initC2Eim(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef, i64 noundef) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3tbb19task_scheduler_initD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL14TestFindPrimesv() 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 = { 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 = { 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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