; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/old (concurrent_queue_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_queue_base" = type { ptr, ptr, i64, i64, i64 }
%"class.tbb::internal::concurrent_queue_rep" = type { %"struct.tbb::atomic.0", [120 x i8], %"struct.tbb::atomic.0", [120 x i8], [8 x %"struct.tbb::internal::micro_queue"] }
%"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 { i64 }
%"struct.tbb::internal::micro_queue" = type <{ %"struct.tbb::atomic", %"struct.tbb::atomic.0", %"struct.tbb::atomic", %"struct.tbb::atomic.0", %"class.tbb::spin_mutex", [7 x i8] }>
%"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 { ptr }
%"class.tbb::spin_mutex" = type { i8 }

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3tbb8internal21concurrent_queue_base13internal_pushEPKv(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca %"class.tbb::internal::atomic_backoff", align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %9 = getelementptr inbounds %"class.tbb::internal::concurrent_queue_base", ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %"class.tbb::internal::concurrent_queue_rep", ptr %11, i32 0, i32 2
  %13 = call noundef i64 @_ZN3tbb8internal27atomic_impl_with_arithmeticImmcEppEi(ptr noundef nonnull align 8 dereferenceable(8) %12, i32 noundef 0)
  store i64 %13, ptr %6, align 8, !tbaa !12
  %14 = getelementptr inbounds %"class.tbb::internal::concurrent_queue_base", ptr %8, i32 0, i32 2
  %15 = load i64, ptr %14, align 8, !tbaa !13
  %16 = icmp slt i64 %15, 9223372036854775807
  br i1 %16, label %17, label %29

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @_ZN3tbb8internal14atomic_backoffC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %7)
  br label %18

18:                                               ; preds = %27, %17
  %19 = load i64, ptr %6, align 8, !tbaa !12
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.tbb::internal::concurrent_queue_rep", ptr %20, i32 0, i32 0
  %22 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %21)
  %23 = sub i64 %19, %22
  %24 = getelementptr inbounds %"class.tbb::internal::concurrent_queue_base", ptr %8, i32 0, i32 2
  %25 = load volatile i64, ptr %24, align 8, !tbaa !13
  %26 = icmp sge i64 %23, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %18
  call void @_ZN3tbb8internal14atomic_backoff5pauseEv(ptr noundef nonnull align 4 dereferenceable(4) %7)
  br label %18, !llvm.loop !14

28:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %29

29:                                               ; preds = %28, %2
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %6, align 8, !tbaa !12
  %32 = call noundef nonnull align 8 dereferenceable(33) ptr @_ZN3tbb8internal20concurrent_queue_rep6chooseEm(ptr noundef nonnull align 8 dereferenceable(576) %30, i64 noundef %31)
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load i64, ptr %6, align 8, !tbaa !12
  call void @_ZN3tbb8internal11micro_queue4pushEPKvmRNS0_21concurrent_queue_baseE(ptr noundef nonnull align 8 dereferenceable(33) %32, ptr noundef %33, i64 noundef %34, ptr noundef nonnull align 8 dereferenceable(40) %8)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

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

; 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 void @_ZN3tbb8internal14atomic_backoff5pauseEv(ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(33) ptr @_ZN3tbb8internal20concurrent_queue_rep6chooseEm(ptr noundef nonnull align 8 dereferenceable(576), i64 noundef) #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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 8}
!10 = !{!"_ZTSN3tbb8internal21concurrent_queue_baseE", !6, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"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::atomic_backoff" = type { i32 }

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3tbb8internal21concurrent_queue_base13internal_pushEPKv(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = alloca %"class.tbb::internal::atomic_backoff", align 4
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 128
  %7 = tail call noundef i64 @_ZN3tbb8internal27atomic_impl_with_arithmeticImmcEppEi(ptr noundef nonnull align 8 dereferenceable(8) %6, i32 noundef 0)
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %.not = icmp eq i64 %9, 9223372036854775807
  br i1 %.not, label %17, label %10

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  call void @_ZN3tbb8internal14atomic_backoffC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %3)
  %11 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  %12 = sub i64 %7, %11
  %13 = load volatile i64, ptr %8, align 8, !tbaa !11
  %.not78 = icmp slt i64 %12, %13
  br i1 %.not78, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %10, %.lr.ph
  call void @_ZN3tbb8internal14atomic_backoff5pauseEv(ptr noundef nonnull align 4 dereferenceable(4) %3)
  %14 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  %15 = sub i64 %7, %14
  %16 = load volatile i64, ptr %8, align 8, !tbaa !11
  %.not7 = icmp slt i64 %15, %16
  br i1 %.not7, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %17

17:                                               ; preds = %._crit_edge, %2
  %18 = call noundef nonnull align 8 dereferenceable(33) ptr @_ZN3tbb8internal20concurrent_queue_rep6chooseEm(ptr noundef nonnull align 8 dereferenceable(576) %5, i64 noundef %7)
  call void @_ZN3tbb8internal11micro_queue4pushEPKvmRNS0_21concurrent_queue_baseE(ptr noundef nonnull align 8 dereferenceable(33) %18, ptr noundef %1, i64 noundef %7, ptr noundef nonnull align 8 dereferenceable(40) %0)
  ret void
}

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

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

; 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 void @_ZN3tbb8internal14atomic_backoff5pauseEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(33) ptr @_ZN3tbb8internal20concurrent_queue_rep6chooseEm(ptr noundef nonnull align 8 dereferenceable(576), i64 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 8}
!6 = !{!"_ZTSN3tbb8internal21concurrent_queue_baseE", !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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