; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3tbb8internal22concurrent_vector_base13internal_growEmmmPFvPvmE(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %20 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %20, ptr %11, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %85, %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %22 = load i64, ptr %11, align 8, !tbaa !9
  %23 = call noundef i64 @_ZN3tbb8internal22concurrent_vector_base16segment_index_ofEm(i64 noundef %22)
  store i64 %23, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %24 = load i64, ptr %12, align 8, !tbaa !9
  %25 = call noundef i64 @_ZN3tbb8internal22concurrent_vector_base12segment_baseEm(i64 noundef %24)
  store i64 %25, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %26 = load i64, ptr %12, align 8, !tbaa !9
  %27 = call noundef i64 @_ZN3tbb8internal22concurrent_vector_base12segment_sizeEm(i64 noundef %26)
  store i64 %27, ptr %14, align 8, !tbaa !9
  %28 = load i64, ptr %12, align 8, !tbaa !9
  call void @_ZN3tbb8internal22concurrent_vector_base6helper27extend_segment_if_necessaryERS1_m(ptr noundef nonnull align 8 dereferenceable(32) %19, i64 noundef %28)
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %29 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %19, i32 0, i32 1
  %30 = call noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_22concurrent_vector_base9segment_tEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %29)
  %31 = load i64, ptr %12, align 8, !tbaa !9
  %32 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %30, i64 %31
  store ptr %32, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %33 = load ptr, ptr %15, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %33, i32 0, i32 0
  %35 = load volatile ptr, ptr %34, align 8, !tbaa !11
  store ptr %35, ptr %16, align 8, !tbaa !5
  %36 = load ptr, ptr %16, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %56, label %38

38:                                               ; preds = %21
  %39 = load i64, ptr %13, align 8, !tbaa !9
  %40 = load i64, ptr %11, align 8, !tbaa !9
  %41 = icmp eq i64 %39, %40
  br i1 %41, label %42, label %49

42:                                               ; preds = %38
  %43 = load i64, ptr %14, align 8, !tbaa !9
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = call noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef %43, i64 noundef %44, ptr noundef null)
  store ptr %45, ptr %16, align 8, !tbaa !5
  %46 = load ptr, ptr %16, align 8, !tbaa !5
  %47 = load ptr, ptr %15, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %47, i32 0, i32 0
  store volatile ptr %46, ptr %48, align 8, !tbaa !11
  br label %55

49:                                               ; preds = %38
  %50 = load ptr, ptr %15, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %50, i32 0, i32 0
  call void @_ZN3tbb8internal18spin_wait_while_eqIPvS2_EEvRVKT_T0_(ptr noundef nonnull align 8 dereferenceable(8) %51, ptr noundef null)
  %52 = load ptr, ptr %15, align 8, !tbaa !5
  %53 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %52, i32 0, i32 0
  %54 = load volatile ptr, ptr %53, align 8, !tbaa !11
  store ptr %54, ptr %16, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %49, %42
  br label %56

56:                                               ; preds = %55, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = load i64, ptr %13, align 8, !tbaa !9
  %59 = sub i64 %57, %58
  store i64 %59, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %60 = load i64, ptr %14, align 8, !tbaa !9
  %61 = load i64, ptr %8, align 8, !tbaa !9
  %62 = load i64, ptr %13, align 8, !tbaa !9
  %63 = sub i64 %61, %62
  %64 = icmp ugt i64 %60, %63
  br i1 %64, label %65, label %69

65:                                               ; preds = %56
  %66 = load i64, ptr %8, align 8, !tbaa !9
  %67 = load i64, ptr %13, align 8, !tbaa !9
  %68 = sub i64 %66, %67
  br label %71

69:                                               ; preds = %56
  %70 = load i64, ptr %14, align 8, !tbaa !9
  br label %71

71:                                               ; preds = %69, %65
  %72 = phi i64 [ %68, %65 ], [ %70, %69 ]
  store i64 %72, ptr %18, align 8, !tbaa !9
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = load ptr, ptr %16, align 8, !tbaa !5
  %75 = load i64, ptr %9, align 8, !tbaa !9
  %76 = load i64, ptr %17, align 8, !tbaa !9
  %77 = mul i64 %75, %76
  %78 = getelementptr inbounds i8, ptr %74, i64 %77
  %79 = load i64, ptr %18, align 8, !tbaa !9
  %80 = load i64, ptr %17, align 8, !tbaa !9
  %81 = sub i64 %79, %80
  call void %73(ptr noundef %78, i64 noundef %81)
  %82 = load i64, ptr %13, align 8, !tbaa !9
  %83 = load i64, ptr %18, align 8, !tbaa !9
  %84 = add i64 %82, %83
  store i64 %84, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %85

85:                                               ; preds = %71
  %86 = load i64, ptr %11, align 8, !tbaa !9
  %87 = load i64, ptr %8, align 8, !tbaa !9
  %88 = icmp ult i64 %86, %87
  br i1 %88, label %21, label %89, !llvm.loop !13

89:                                               ; preds = %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  ret void
}

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

declare noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef, i64 noundef, ptr noundef) #2

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

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

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

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

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

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

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 = { 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 = !{!"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 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN3tbb8internal22concurrent_vector_base9segment_tE", !6, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%"struct.tbb::internal::concurrent_vector_base::segment_t" = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3tbb8internal22concurrent_vector_base13internal_growEmmmPFvPvmE(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  br label %7

7:                                                ; preds = %20, %5
  %.0 = phi i64 [ %1, %5 ], [ %27, %20 ]
  %8 = tail call noundef i64 @_ZN3tbb8internal22concurrent_vector_base16segment_index_ofEm(i64 noundef %.0)
  %9 = tail call noundef i64 @_ZN3tbb8internal22concurrent_vector_base12segment_baseEm(i64 noundef %8)
  %10 = tail call noundef i64 @_ZN3tbb8internal22concurrent_vector_base12segment_sizeEm(i64 noundef %8)
  tail call void @_ZN3tbb8internal22concurrent_vector_base6helper27extend_segment_if_necessaryERS1_m(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %8)
  %11 = tail call noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_22concurrent_vector_base9segment_tEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %12 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %11, i64 %8
  %13 = load volatile ptr, ptr %12, align 8, !tbaa !5
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %14, label %20

14:                                               ; preds = %7
  %15 = icmp eq i64 %9, %.0
  br i1 %15, label %16, label %18

16:                                               ; preds = %14
  %17 = tail call noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef %10, i64 noundef %3, ptr noundef null)
  store volatile ptr %17, ptr %12, align 8, !tbaa !5
  br label %20

18:                                               ; preds = %14
  tail call void @_ZN3tbb8internal18spin_wait_while_eqIPvS2_EEvRVKT_T0_(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef null)
  %19 = load volatile ptr, ptr %12, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %16, %18, %7
  %.034 = phi ptr [ %13, %7 ], [ %17, %16 ], [ %19, %18 ]
  %21 = sub i64 %.0, %9
  %22 = sub i64 %2, %9
  %23 = tail call i64 @llvm.umin.i64(i64 %10, i64 %22)
  %24 = mul i64 %21, %3
  %25 = getelementptr inbounds i8, ptr %.034, i64 %24
  %26 = sub i64 %23, %21
  tail call void %4(ptr noundef %25, i64 noundef %26)
  %27 = add i64 %23, %9
  %28 = icmp ult i64 %27, %2
  br i1 %28, label %7, label %29, !llvm.loop !10

29:                                               ; preds = %20
  ret void
}

declare noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

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

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

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #3

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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !7, i64 0}
!6 = !{!"_ZTSN3tbb8internal22concurrent_vector_base9segment_tE", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass