; 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 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

; 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
define dso_local noundef zeroext i1 @_ZN3tbb8internal21concurrent_queue_base25internal_push_if_not_fullEPKv(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca %"class.tbb::internal::atomic_backoff", align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = getelementptr inbounds %"class.tbb::internal::concurrent_queue_base", ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @_ZN3tbb8internal14atomic_backoffC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %8)
  br label %13

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

25:                                               ; preds = %13
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %38

26:                                               ; preds = %13
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %"class.tbb::internal::concurrent_queue_rep", ptr %27, i32 0, i32 2
  %29 = load i64, ptr %7, align 8, !tbaa !12
  %30 = add i64 %29, 1
  %31 = load i64, ptr %7, align 8, !tbaa !12
  %32 = call noundef i64 @_ZN3tbb8internal11atomic_implImE16compare_and_swapEmm(ptr noundef nonnull align 8 dereferenceable(8) %28, i64 noundef %30, i64 noundef %31)
  %33 = load i64, ptr %7, align 8, !tbaa !12
  %34 = icmp eq i64 %32, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %26
  store i32 2, ptr %9, align 4
  br label %38

36:                                               ; preds = %26
  br label %37

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

38:                                               ; preds = %35, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %39 = load i32, ptr %9, align 4
  switch i32 %39, label %46 [
    i32 2, label %40
  ]

40:                                               ; preds = %38
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i64, ptr %7, align 8, !tbaa !12
  %43 = call noundef nonnull align 8 dereferenceable(33) ptr @_ZN3tbb8internal20concurrent_queue_rep6chooseEm(ptr noundef nonnull align 8 dereferenceable(576) %41, i64 noundef %42)
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i64, ptr %7, align 8, !tbaa !12
  call void @_ZN3tbb8internal11micro_queue4pushEPKvmRNS0_21concurrent_queue_baseE(ptr noundef nonnull align 8 dereferenceable(33) %43, ptr noundef %44, i64 noundef %45, ptr noundef nonnull align 8 dereferenceable(40) %10)
  store i1 true, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %46

46:                                               ; preds = %40, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %47 = load i1, ptr %3, align 1
  ret i1 %47
}

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 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

; 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
define dso_local noundef zeroext i1 @_ZN3tbb8internal21concurrent_queue_base25internal_push_if_not_fullEPKv(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
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  call void @_ZN3tbb8internal14atomic_backoffC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %3)
  %6 = getelementptr inbounds i8, ptr %5, i64 128
  %7 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %8 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  %9 = sub i64 %7, %8
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %.not17 = icmp slt i64 %9, %11
  br i1 %.not17, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %2, %16
  %12 = phi i64 [ %17, %16 ], [ %7, %2 ]
  %13 = add i64 %12, 1
  %14 = call noundef i64 @_ZN3tbb8internal11atomic_implImE16compare_and_swapEmm(ptr noundef nonnull align 8 dereferenceable(8) %6, i64 noundef %13, i64 noundef %12)
  %15 = icmp eq i64 %14, %12
  br i1 %15, label %21, label %16

16:                                               ; preds = %.lr.ph
  call void @_ZN3tbb8internal14atomic_backoff5pauseEv(ptr noundef nonnull align 4 dereferenceable(4) %3)
  %17 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %18 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  %19 = sub i64 %17, %18
  %20 = load i64, ptr %10, align 8, !tbaa !11
  %.not = icmp slt i64 %19, %20
  br i1 %.not, label %.lr.ph, label %.critedge, !llvm.loop !12

21:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  %22 = call noundef nonnull align 8 dereferenceable(33) ptr @_ZN3tbb8internal20concurrent_queue_rep6chooseEm(ptr noundef nonnull align 8 dereferenceable(576) %5, i64 noundef %12)
  call void @_ZN3tbb8internal11micro_queue4pushEPKvmRNS0_21concurrent_queue_baseE(ptr noundef nonnull align 8 dereferenceable(33) %22, ptr noundef %1, i64 noundef %12, ptr noundef nonnull align 8 dereferenceable(40) %0)
  br label %23

.critedge:                                        ; preds = %16, %2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %23

23:                                               ; preds = %.critedge, %21
  %.not15 = phi i1 [ false, %.critedge ], [ true, %21 ]
  ret i1 %.not15
}

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,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass