; 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::atomic_backoff" = type { i32 }
%"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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3tbb8internal22concurrent_vector_base6helper14extend_segmentERS1_(ptr noundef nonnull align 8 dereferenceable(32) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"class.tbb::internal::atomic_backoff", align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store i64 64, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %6 = call noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef 64, i64 noundef 8, ptr noundef null)
  store ptr %6, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 1 %7, i8 0, i64 512, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @_ZN3tbb8internal14atomic_backoffC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %5)
  br label %8

8:                                                ; preds = %25, %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %9, i32 0, i32 2
  %11 = getelementptr inbounds [2 x %"struct.tbb::internal::concurrent_vector_base::segment_t"], ptr %10, i64 0, i64 0
  %12 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %11, i32 0, i32 0
  %13 = load volatile ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %23

15:                                               ; preds = %8
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %16, i32 0, i32 2
  %18 = getelementptr inbounds [2 x %"struct.tbb::internal::concurrent_vector_base::segment_t"], ptr %17, i64 0, i64 1
  %19 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %18, i32 0, i32 0
  %20 = load volatile ptr, ptr %19, align 8, !tbaa !11
  %21 = icmp ne ptr %20, null
  %22 = xor i1 %21, true
  br label %23

23:                                               ; preds = %15, %8
  %24 = phi i1 [ true, %8 ], [ %22, %15 ]
  br i1 %24, label %25, label %26

25:                                               ; preds = %23
  call void @_ZN3tbb8internal14atomic_backoff5pauseEv(ptr noundef nonnull align 4 dereferenceable(4) %5)
  br label %8, !llvm.loop !13

26:                                               ; preds = %23
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %27, i32 0, i32 2
  %29 = getelementptr inbounds [2 x %"struct.tbb::internal::concurrent_vector_base::segment_t"], ptr %28, i64 0, i64 0
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %30, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %31, ptr align 8 %29, i64 8, i1 true), !tbaa.struct !15
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %32, i32 0, i32 2
  %34 = getelementptr inbounds [2 x %"struct.tbb::internal::concurrent_vector_base::segment_t"], ptr %33, i64 0, i64 1
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.tbb::internal::concurrent_vector_base::segment_t", ptr %35, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %36, ptr align 8 %34, i64 8, i1 true), !tbaa.struct !15
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %40, i32 0, i32 2
  %42 = getelementptr inbounds [2 x %"struct.tbb::internal::concurrent_vector_base::segment_t"], ptr %41, i64 0, i64 0
  %43 = call noundef ptr @_ZN3tbb8internal11atomic_implIPNS0_22concurrent_vector_base9segment_tEE16compare_and_swapES4_S4_(ptr noundef nonnull align 8 dereferenceable(8) %38, ptr noundef %39, ptr noundef %42)
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %"class.tbb::internal::concurrent_vector_base", ptr %44, i32 0, i32 2
  %46 = getelementptr inbounds [2 x %"struct.tbb::internal::concurrent_vector_base::segment_t"], ptr %45, i64 0, i64 0
  %47 = icmp ne ptr %43, %46
  br i1 %47, label %48, label %50

48:                                               ; preds = %26
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN3tbb8internal8NFS_FreeEPv(ptr noundef %49)
  br label %50

50:                                               ; preds = %48, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb8internal14atomic_backoff5pauseEv(ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

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

declare void @_ZN3tbb8internal8NFS_FreeEPv(ptr noundef) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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"}
!15 = !{i64 0, i64 8, !5}


; 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::atomic_backoff" = type { i32 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3tbb8internal22concurrent_vector_base6helper14extend_segmentERS1_(ptr noundef nonnull align 8 dereferenceable(32) %0) local_unnamed_addr #1 align 2 {
  %2 = alloca %"class.tbb::internal::atomic_backoff", align 4
  %3 = tail call noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef 64, i64 noundef 8, ptr noundef null)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(512) %3, i8 0, i64 512, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  call void @_ZN3tbb8internal14atomic_backoffC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %2)
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  br label %6

6:                                                ; preds = %.critedge, %1
  %7 = load volatile ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %.critedge, label %8

8:                                                ; preds = %6
  %9 = load volatile ptr, ptr %4, align 8, !tbaa !5
  %.not12 = icmp eq ptr %9, null
  br i1 %.not12, label %.critedge, label %10

.critedge:                                        ; preds = %6, %8
  call void @_ZN3tbb8internal14atomic_backoff5pauseEv(ptr noundef nonnull align 4 dereferenceable(4) %2)
  br label %6, !llvm.loop !10

10:                                               ; preds = %8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr nonnull align 8 %5, i64 8, i1 true), !tbaa.struct !12
  %11 = getelementptr inbounds i8, ptr %3, i64 8
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %11, ptr nonnull align 8 %4, i64 8, i1 true), !tbaa.struct !12
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = call noundef ptr @_ZN3tbb8internal11atomic_implIPNS0_22concurrent_vector_base9segment_tEE16compare_and_swapES4_S4_(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef %3, ptr noundef nonnull %5)
  %.not13 = icmp eq ptr %13, %5
  br i1 %.not13, label %15, label %14

14:                                               ; preds = %10
  call void @_ZN3tbb8internal8NFS_FreeEPv(ptr noundef %3)
  br label %15

15:                                               ; preds = %14, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb8internal14atomic_backoff5pauseEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

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

declare void @_ZN3tbb8internal8NFS_FreeEPv(ptr noundef) local_unnamed_addr #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 = { "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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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, !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"}
!12 = !{i64 0, i64 8, !13}
!13 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass