; 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
declare dso_local noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; 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
define dso_local void @_ZN3tbb8internal22concurrent_vector_base13internal_copyERKS1_mPFvPvPKvmE(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %2, ptr noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %14, i32 0, i32 0
  %16 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %15)
  store i64 %16, ptr %9, align 8, !tbaa !9
  %17 = load i64, ptr %9, align 8, !tbaa !9
  %18 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %13, i32 0, i32 0
  %19 = call noundef i64 @_ZN3tbb6atomicImEaSEm(ptr noundef nonnull align 8 dereferenceable(8) %18, i64 noundef %17)
  %20 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %13, i32 0, i32 2
  %21 = getelementptr inbounds [2 x %"struct.tbb::internal::concurrent_vector_base::segment_t"], ptr %20, i64 0, i64 0
  %22 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %13, i32 0, i32 1
  %23 = call noundef ptr @_ZN3tbb6atomicIPNS_8internal22concurrent_vector_base9segment_tEEaSES4_(ptr noundef nonnull align 8 dereferenceable(8) %22, ptr noundef %21)
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %74

26:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %70, %26
  %28 = load i64, ptr %11, align 8, !tbaa !9
  %29 = call noundef i64 @_ZN3tbb8internal22concurrent_vector_base12segment_baseEm(i64 noundef %28)
  store i64 %29, ptr %10, align 8, !tbaa !9
  %30 = load i64, ptr %9, align 8, !tbaa !9
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %73

33:                                               ; preds = %27
  %34 = load i64, ptr %11, align 8, !tbaa !9
  call void @_ZN3tbb8internal22concurrent_vector_base6helper27extend_segment_if_necessaryERS1_m(ptr noundef nonnull align 8 dereferenceable(32) %13, i64 noundef %34)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %35 = load i64, ptr %11, align 8, !tbaa !9
  %36 = call noundef i64 @_ZN3tbb8internal22concurrent_vector_base12segment_sizeEm(i64 noundef %35)
  store i64 %36, ptr %12, align 8, !tbaa !9
  %37 = load i64, ptr %12, align 8, !tbaa !9
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = call noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef %37, i64 noundef %38, ptr noundef null)
  %40 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %13, i32 0, i32 1
  %41 = call noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_22concurrent_vector_base9segment_tEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %40)
  %42 = load i64, ptr %11, align 8, !tbaa !9
  %43 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %41, i64 %42
  %44 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %43, i32 0, i32 0
  store volatile ptr %39, ptr %44, align 8, !tbaa !11
  %45 = load i64, ptr %12, align 8, !tbaa !9
  %46 = load i64, ptr %9, align 8, !tbaa !9
  %47 = load i64, ptr %10, align 8, !tbaa !9
  %48 = sub i64 %46, %47
  %49 = icmp ugt i64 %45, %48
  br i1 %49, label %50, label %54

50:                                               ; preds = %33
  %51 = load i64, ptr %9, align 8, !tbaa !9
  %52 = load i64, ptr %10, align 8, !tbaa !9
  %53 = sub i64 %51, %52
  store i64 %53, ptr %12, align 8, !tbaa !9
  br label %54

54:                                               ; preds = %50, %33
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %13, i32 0, i32 1
  %57 = call noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_22concurrent_vector_base9segment_tEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %56)
  %58 = load i64, ptr %11, align 8, !tbaa !9
  %59 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %57, i64 %58
  %60 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %59, i32 0, i32 0
  %61 = load volatile ptr, ptr %60, align 8, !tbaa !11
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %62, i32 0, i32 1
  %64 = call noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_22concurrent_vector_base9segment_tEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %63)
  %65 = load i64, ptr %11, align 8, !tbaa !9
  %66 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %64, i64 %65
  %67 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %66, i32 0, i32 0
  %68 = load volatile ptr, ptr %67, align 8, !tbaa !11
  %69 = load i64, ptr %12, align 8, !tbaa !9
  call void %55(ptr noundef %61, ptr noundef %68, i64 noundef %69)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %70

70:                                               ; preds = %54
  %71 = load i64, ptr %11, align 8, !tbaa !9
  %72 = add i64 %71, 1
  store i64 %72, ptr %11, align 8, !tbaa !9
  br label %27, !llvm.loop !13

73:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %74

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN3tbb6atomicIPNS_8internal22concurrent_vector_base9segment_tEEaSES4_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1 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 = { "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
declare dso_local noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

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
define dso_local void @_ZN3tbb8internal22concurrent_vector_base13internal_copyERKS1_mPFvPvPKvmE(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 align 2 {
  %5 = tail call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %6 = tail call noundef i64 @_ZN3tbb6atomicImEaSEm(ptr noundef nonnull align 8 dereferenceable(8) %0, i64 noundef %5)
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = tail call noundef ptr @_ZN3tbb6atomicIPNS_8internal22concurrent_vector_base9segment_tEEaSES4_(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef nonnull %7)
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %4
  %10 = tail call noundef i64 @_ZN3tbb8internal22concurrent_vector_base12segment_baseEm(i64 noundef 0)
  %11 = icmp ult i64 %10, %5
  br i1 %11, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  br label %13

13:                                               ; preds = %.lr.ph, %13
  %14 = phi i64 [ %10, %.lr.ph ], [ %27, %13 ]
  %.02126 = phi i64 [ 0, %.lr.ph ], [ %26, %13 ]
  tail call void @_ZN3tbb8internal22concurrent_vector_base6helper27extend_segment_if_necessaryERS1_m(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %.02126)
  %15 = tail call noundef i64 @_ZN3tbb8internal22concurrent_vector_base12segment_sizeEm(i64 noundef %.02126)
  %16 = tail call noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef %15, i64 noundef %2, ptr noundef null)
  %17 = tail call noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_22concurrent_vector_base9segment_tEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %8)
  %18 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %17, i64 %.02126
  store volatile ptr %16, ptr %18, align 8, !tbaa !5
  %19 = sub i64 %5, %14
  %spec.select = tail call i64 @llvm.umin.i64(i64 %15, i64 %19)
  %20 = tail call noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_22concurrent_vector_base9segment_tEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %8)
  %21 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %20, i64 %.02126
  %22 = load volatile ptr, ptr %21, align 8, !tbaa !5
  %23 = tail call noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_22concurrent_vector_base9segment_tEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %12)
  %24 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %23, i64 %.02126
  %25 = load volatile ptr, ptr %24, align 8, !tbaa !5
  tail call void %3(ptr noundef %22, ptr noundef %25, i64 noundef %spec.select)
  %26 = add i64 %.02126, 1
  %27 = tail call noundef i64 @_ZN3tbb8internal22concurrent_vector_base12segment_baseEm(i64 noundef %26)
  %28 = icmp ult i64 %27, %5
  br i1 %28, label %13, label %.loopexit, !llvm.loop !10

.loopexit:                                        ; preds = %13, %.preheader, %4
  ret void
}

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

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

; 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,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass