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

; 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::concurrent_vector" = type { %"class.tbb::internal::concurrent_vector_base" }
%"class.tbb::internal::concurrent_vector_base" = type { %"struct.tbb::atomic.0", %"struct.tbb::atomic.4", [2 x %"struct.tbb::internal::concurrent_vector_base::segment_t"] }
%"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 { i64 }
%"struct.tbb::atomic.4" = type { %"struct.tbb::internal::atomic_impl_with_arithmetic.5" }
%"struct.tbb::internal::atomic_impl_with_arithmetic.5" = type { %"struct.tbb::internal::atomic_impl.6" }
%"struct.tbb::internal::atomic_impl.6" = type { %"struct.tbb::internal::aligned_storage.7" }
%"struct.tbb::internal::aligned_storage.7" = type { ptr }
%"struct.tbb::internal::concurrent_vector_base::segment_t" = type { ptr }
%"class.tbb::blocked_range.12" = type { i64, i64, i64 }
%class.GrowToAtLeast = type { ptr }

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb17concurrent_vectorI3FooEC2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1 align 2

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) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z27TestConcurrentGrowToAtLeastv() #1 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.tbb::concurrent_vector", align 8
  %2 = alloca i64, align 8
  %3 = alloca %"class.tbb::blocked_range.12", align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %class.GrowToAtLeast, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr %1) #3
  call void @_ZN3tbb17concurrent_vectorI3FooEC2Ev(ptr noundef nonnull align 8 dereferenceable(32) %1)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 1, ptr %2, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %15, %0
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = icmp ult i64 %8, 1000
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %27

11:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #3
  invoke void @_ZN3tbb13blocked_rangeImEC2Emmm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef 0, i64 noundef 1000000, i64 noundef 100)
          to label %12 unwind label %18

12:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  invoke void @_ZN13GrowToAtLeastC2ERN3tbb17concurrent_vectorI3FooEE(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(32) %1)
          to label %13 unwind label %22

13:                                               ; preds = %12
  invoke void @_ZN3tbb12parallel_forINS_13blocked_rangeImEE13GrowToAtLeastEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(8) %6)
          to label %14 unwind label %22

14:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #3
  br label %15

15:                                               ; preds = %14
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = mul i64 %16, 10
  store i64 %17, ptr %2, align 8, !tbaa !5
  br label %7, !llvm.loop !9

18:                                               ; preds = %11
  %19 = landingpad { ptr, i32 }
          cleanup
  %20 = extractvalue { ptr, i32 } %19, 0
  store ptr %20, ptr %4, align 8
  %21 = extractvalue { ptr, i32 } %19, 1
  store i32 %21, ptr %5, align 4
  br label %26

22:                                               ; preds = %13, %12
  %23 = landingpad { ptr, i32 }
          cleanup
  %24 = extractvalue { ptr, i32 } %23, 0
  store ptr %24, ptr %4, align 8
  %25 = extractvalue { ptr, i32 } %23, 1
  store i32 %25, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %26

26:                                               ; preds = %22, %18
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @_ZN3tbb17concurrent_vectorI3FooED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %1) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %1) #3
  br label %28

27:                                               ; preds = %10
  call void @_ZN3tbb17concurrent_vectorI3FooED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %1) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %1) #3
  ret void

28:                                               ; preds = %26
  %29 = load ptr, ptr %4, align 8
  %30 = load i32, ptr %5, align 4
  %31 = insertvalue { ptr, i32 } poison, ptr %29, 0
  %32 = insertvalue { ptr, i32 } %31, i32 %30, 1
  resume { ptr, i32 } %32
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb12parallel_forINS_13blocked_rangeImEE13GrowToAtLeastEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(8)) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3tbb13blocked_rangeImEC2Emmm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, i64 noundef, i64 noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN13GrowToAtLeastC2ERN3tbb17concurrent_vectorI3FooEE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 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 = { 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 #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 = !{!"long", !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::concurrent_vector" = type { %"class.tbb::internal::concurrent_vector_base" }
%"class.tbb::internal::concurrent_vector_base" = type { %"struct.tbb::atomic.0", %"struct.tbb::atomic.4", [2 x %"struct.tbb::internal::concurrent_vector_base::segment_t"] }
%"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 { i64 }
%"struct.tbb::atomic.4" = type { %"struct.tbb::internal::atomic_impl_with_arithmetic.5" }
%"struct.tbb::internal::atomic_impl_with_arithmetic.5" = type { %"struct.tbb::internal::atomic_impl.6" }
%"struct.tbb::internal::atomic_impl.6" = type { %"struct.tbb::internal::aligned_storage.7" }
%"struct.tbb::internal::aligned_storage.7" = type { ptr }
%"struct.tbb::internal::concurrent_vector_base::segment_t" = type { ptr }
%"class.tbb::blocked_range.12" = type { i64, i64, i64 }
%class.GrowToAtLeast = type { ptr }

; 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 uwtable
declare dso_local void @_ZN3tbb17concurrent_vectorI3FooEC2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1 align 2

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) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z27TestConcurrentGrowToAtLeastv() local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.tbb::concurrent_vector", align 8
  %2 = alloca %"class.tbb::blocked_range.12", align 8
  %3 = alloca %class.GrowToAtLeast, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #3
  call void @_ZN3tbb17concurrent_vectorI3FooEC2Ev(ptr noundef nonnull align 8 dereferenceable(32) %1)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #3
  call void @_ZN3tbb13blocked_rangeImEC2Emmm(ptr noundef nonnull align 8 dereferenceable(24) %2, i64 noundef 0, i64 noundef 1000000, i64 noundef 100)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @_ZN13GrowToAtLeastC2ERN3tbb17concurrent_vectorI3FooEE(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(32) %1)
  invoke void @_ZN3tbb12parallel_forINS_13blocked_rangeImEE13GrowToAtLeastEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
          to label %4 unwind label %7

4:                                                ; preds = %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #3
  call void @_ZN3tbb13blocked_rangeImEC2Emmm(ptr noundef nonnull align 8 dereferenceable(24) %2, i64 noundef 0, i64 noundef 1000000, i64 noundef 100)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @_ZN13GrowToAtLeastC2ERN3tbb17concurrent_vectorI3FooEE(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(32) %1)
  invoke void @_ZN3tbb12parallel_forINS_13blocked_rangeImEE13GrowToAtLeastEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
          to label %5 unwind label %7

5:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #3
  call void @_ZN3tbb13blocked_rangeImEC2Emmm(ptr noundef nonnull align 8 dereferenceable(24) %2, i64 noundef 0, i64 noundef 1000000, i64 noundef 100)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @_ZN13GrowToAtLeastC2ERN3tbb17concurrent_vectorI3FooEE(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(32) %1)
  invoke void @_ZN3tbb12parallel_forINS_13blocked_rangeImEE13GrowToAtLeastEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
          to label %6 unwind label %7

6:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #3
  call void @_ZN3tbb17concurrent_vectorI3FooED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %1) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #3
  ret void

7:                                                ; preds = %5, %4, %0
  %8 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #3
  call void @_ZN3tbb17concurrent_vectorI3FooED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %1) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #3
  resume { ptr, i32 } %8
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb12parallel_forINS_13blocked_rangeImEE13GrowToAtLeastEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3tbb13blocked_rangeImEC2Emmm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, i64 noundef, i64 noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN13GrowToAtLeastC2ERN3tbb17concurrent_vectorI3FooEE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 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 = { 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 #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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass