; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/tbb (concurrent_vector)

; 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::internal::concurrent_vector_base_v3::segment_value_t" = type { ptr }
%"struct.tbb::internal::concurrent_vector_base_v3::segment_allocated" = type { i8 }
%"class.tbb::internal::concurrent_vector_base_v3" = type { ptr, %"struct.tbb::atomic", %"struct.tbb::atomic", %"struct.tbb::atomic.0", [3 x %"class.tbb::internal::concurrent_vector_base_v3::segment_t"] }
%"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 { i64 }
%"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 { ptr }
%"class.tbb::internal::concurrent_vector_base_v3::segment_t" = type { %"struct.tbb::atomic.4" }
%"struct.tbb::atomic.4" = type { %"struct.tbb::internal::atomic_impl.5" }
%"struct.tbb::internal::atomic_impl.5" = type { %"struct.tbb::internal::aligned_storage.6" }
%"struct.tbb::internal::aligned_storage.6" = 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 nounwind uwtable
declare dso_local noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v312segment_baseEm(i64 noundef) #1 align 2

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

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

; 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
declare dso_local noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v36helper14enable_segmentERS1_mmb(ptr noundef nonnull align 8 dereferenceable(56), i64 noundef, i64 noundef, i1 noundef zeroext) #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v316segment_index_ofEm(i64 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3tbb8internalneINS0_25concurrent_vector_base_v317segment_allocatedEEEbRKNS2_15segment_value_tET_(ptr noundef nonnull align 8 dereferenceable(8)) #1

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3tbb8internal15throw_exceptionENS0_12exception_idE(i32 noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3tbb8internal25concurrent_vector_base_v316internal_reserveEmmm(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca %"class.tbb::internal::concurrent_vector_base_v3::segment_value_t", align 8
  %11 = alloca %"struct.tbb::internal::concurrent_vector_base_v3::segment_allocated", align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = load i64, ptr %8, align 8, !tbaa !9
  %15 = icmp ugt i64 %13, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  call void @_ZN3tbb8internal15throw_exceptionENS0_12exception_idE(i32 noundef 16)
  br label %17

17:                                               ; preds = %16, %4
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = sub i64 %18, 1
  %20 = call noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v316segment_index_ofEm(i64 noundef %19)
  call void @_ZN3tbb8internal25concurrent_vector_base_v36helper33assign_first_segment_if_necessaryERS1_m(ptr noundef nonnull align 8 dereferenceable(56) %12, i64 noundef %20)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %21 = call noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v36helper16find_segment_endERKS1_(ptr noundef nonnull align 8 dereferenceable(56) %12)
  store i64 %21, ptr %9, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %41, %17
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = call noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v312segment_baseEm(i64 noundef %23)
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %27, label %44

27:                                               ; preds = %22
  %28 = load i64, ptr %9, align 8, !tbaa !9
  call void @_ZN3tbb8internal25concurrent_vector_base_v36helper25extend_table_if_necessaryERS1_mm(ptr noundef nonnull align 8 dereferenceable(56) %12, i64 noundef %28, i64 noundef 0)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %29 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base_v3", ptr %12, i32 0, i32 3
  %30 = call noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_25concurrent_vector_base_v39segment_tEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %29)
  %31 = load i64, ptr %9, align 8, !tbaa !9
  %32 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base_v3::segment_t", ptr %30, i64 %31
  %33 = call ptr @_ZNK3tbb8internal25concurrent_vector_base_v39segment_t4loadILNS_16memory_semanticsE3EEENS1_15segment_value_tEv(ptr noundef nonnull align 8 dereferenceable(8) %32)
  %34 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base_v3::segment_value_t", ptr %10, i32 0, i32 0
  store ptr %33, ptr %34, align 8
  %35 = call noundef zeroext i1 @_ZN3tbb8internalneINS0_25concurrent_vector_base_v317segment_allocatedEEEbRKNS2_15segment_value_tET_(ptr noundef nonnull align 8 dereferenceable(8) %10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br i1 %35, label %36, label %40

36:                                               ; preds = %27
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = call noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v36helper14enable_segmentERS1_mmb(ptr noundef nonnull align 8 dereferenceable(56) %12, i64 noundef %37, i64 noundef %38, i1 noundef zeroext true)
  br label %40

40:                                               ; preds = %36, %27
  br label %41

41:                                               ; preds = %40
  %42 = load i64, ptr %9, align 8, !tbaa !9
  %43 = add i64 %42, 1
  store i64 %43, ptr %9, align 8, !tbaa !9
  br label %22, !llvm.loop !11

44:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !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::internal::concurrent_vector_base_v3::segment_value_t" = type { ptr }
%"class.tbb::internal::concurrent_vector_base_v3::segment_t" = type { %"struct.tbb::atomic.4" }
%"struct.tbb::atomic.4" = type { %"struct.tbb::internal::atomic_impl.5" }
%"struct.tbb::internal::atomic_impl.5" = type { %"struct.tbb::internal::aligned_storage.6" }
%"struct.tbb::internal::aligned_storage.6" = 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 nounwind uwtable
declare dso_local noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v312segment_baseEm(i64 noundef) local_unnamed_addr #1 align 2

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

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

; 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
declare dso_local noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v36helper14enable_segmentERS1_mmb(ptr noundef nonnull align 8 dereferenceable(56), i64 noundef, i64 noundef, i1 noundef zeroext) local_unnamed_addr #2 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3tbb8internalneINS0_25concurrent_vector_base_v317segment_allocatedEEEbRKNS2_15segment_value_tET_(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3tbb8internal15throw_exceptionENS0_12exception_idE(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3tbb8internal25concurrent_vector_base_v316internal_reserveEmmm(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #2 align 2 {
  %5 = alloca %"class.tbb::internal::concurrent_vector_base_v3::segment_value_t", align 8
  %6 = icmp ugt i64 %1, %3
  br i1 %6, label %7, label %8

7:                                                ; preds = %4
  tail call void @_ZN3tbb8internal15throw_exceptionENS0_12exception_idE(i32 noundef 16)
  br label %8

8:                                                ; preds = %7, %4
  %9 = add i64 %1, -1
  %10 = tail call noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v316segment_index_ofEm(i64 noundef %9)
  tail call void @_ZN3tbb8internal25concurrent_vector_base_v36helper33assign_first_segment_if_necessaryERS1_m(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %10)
  %11 = tail call noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v36helper16find_segment_endERKS1_(ptr noundef nonnull align 8 dereferenceable(56) %0)
  %12 = tail call noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v312segment_baseEm(i64 noundef %11)
  %13 = icmp ult i64 %12, %1
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  br label %15

15:                                               ; preds = %.lr.ph, %22
  %.010 = phi i64 [ %11, %.lr.ph ], [ %23, %22 ]
  call void @_ZN3tbb8internal25concurrent_vector_base_v36helper25extend_table_if_necessaryERS1_mm(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %.010, i64 noundef 0)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %16 = call noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_25concurrent_vector_base_v39segment_tEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %14)
  %17 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base_v3::segment_t", ptr %16, i64 %.010
  %18 = call ptr @_ZNK3tbb8internal25concurrent_vector_base_v39segment_t4loadILNS_16memory_semanticsE3EEENS1_15segment_value_tEv(ptr noundef nonnull align 8 dereferenceable(8) %17)
  store ptr %18, ptr %5, align 8
  %19 = call noundef zeroext i1 @_ZN3tbb8internalneINS0_25concurrent_vector_base_v317segment_allocatedEEEbRKNS2_15segment_value_tET_(ptr noundef nonnull align 8 dereferenceable(8) %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br i1 %19, label %20, label %22

20:                                               ; preds = %15
  %21 = call noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v36helper14enable_segmentERS1_mmb(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %.010, i64 noundef %2, i1 noundef zeroext true)
  br label %22

22:                                               ; preds = %15, %20
  %23 = add i64 %.010, 1
  %24 = call noundef i64 @_ZN3tbb8internal25concurrent_vector_base_v312segment_baseEm(i64 noundef %23)
  %25 = icmp ult i64 %24, %1
  br i1 %25, label %15, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %22, %8
  ret void
}

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

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


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