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

; 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" = type { %"struct.tbb::atomic", %"struct.tbb::atomic.0", [2 x %"struct.tbb::internal::concurrent_vector_base::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 }
%"struct.tbb::internal::concurrent_vector_base::segment_t" = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3tbb8internal22concurrent_vector_base25internal_grow_to_at_leastEmmPFvPvmE(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  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 ptr %3, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %13 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %12, i32 0, i32 0
  %14 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %13)
  store i64 %14, ptr %9, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %36, %4
  %16 = load i64, ptr %9, align 8, !tbaa !9
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %19, label %37

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %20 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %12, i32 0, i32 0
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = call noundef i64 @_ZN3tbb8internal11atomic_implImE16compare_and_swapEmm(ptr noundef nonnull align 8 dereferenceable(8) %20, i64 noundef %21, i64 noundef %22)
  store i64 %23, ptr %10, align 8, !tbaa !9
  %24 = load i64, ptr %10, align 8, !tbaa !9
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = icmp eq i64 %24, %25
  br i1 %26, label %27, label %32

27:                                               ; preds = %19
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN3tbb8internal22concurrent_vector_base13internal_growEmmmPFvPvmE(ptr noundef nonnull align 8 dereferenceable(32) %12, i64 noundef %28, i64 noundef %29, i64 noundef %30, ptr noundef %31)
  store i32 1, ptr %11, align 4
  br label %34

32:                                               ; preds = %19
  %33 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %33, ptr %9, align 8, !tbaa !9
  store i32 0, ptr %11, align 4
  br label %34

34:                                               ; preds = %32, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %35 = load i32, ptr %11, align 4
  switch i32 %35, label %38 [
    i32 0, label %36
  ]

36:                                               ; preds = %34
  br label %15, !llvm.loop !11

37:                                               ; preds = %15
  store i32 0, ptr %11, align 4
  br label %38

38:                                               ; preds = %37, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %39 = load i32, ptr %11, align 4
  switch i32 %39, label %41 [
    i32 0, label %40
    i32 1, label %40
  ]

40:                                               ; preds = %38, %38
  ret void

41:                                               ; preds = %38
  unreachable
}

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

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

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

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

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

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 = { 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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3tbb8internal22concurrent_vector_base25internal_grow_to_at_leastEmmPFvPvmE(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #0 align 2 {
  %5 = tail call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  br label %6

6:                                                ; preds = %8, %4
  %.012 = phi i64 [ %5, %4 ], [ %9, %8 ]
  %7 = icmp ult i64 %.012, %1
  br i1 %7, label %8, label %.loopexit

8:                                                ; preds = %6
  %9 = tail call noundef i64 @_ZN3tbb8internal11atomic_implImE16compare_and_swapEmm(ptr noundef nonnull align 8 dereferenceable(8) %0, i64 noundef %1, i64 noundef %.012)
  %.not = icmp eq i64 %9, %.012
  br i1 %.not, label %.thread, label %6

.thread:                                          ; preds = %8
  tail call void @_ZN3tbb8internal22concurrent_vector_base13internal_growEmmmPFvPvmE(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %.012, i64 noundef %1, i64 noundef %2, ptr noundef %3)
  br label %.loopexit

.loopexit:                                        ; preds = %6, %.thread
  ret void
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb8internal22concurrent_vector_base13internal_growEmmmPFvPvmE(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #0 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" }

!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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass