; 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: 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
declare dso_local noundef zeroext i1 @_ZN3tbb8internal11micro_queue3popEPvmRNS0_21concurrent_queue_baseE(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i64 noundef, ptr noundef nonnull align 8 dereferenceable(40)) #1 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)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb8internal14atomic_backoff5pauseEv(ptr noundef nonnull align 4 dereferenceable(4)) #1 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) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3tbb8internal21concurrent_queue_base23internal_pop_if_presentEPv(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1) #1 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
  br label %13

13:                                               ; preds = %39, %2
  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 %14

14:                                               ; preds = %35, %13
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %"class.tbb::internal::concurrent_queue_rep", ptr %15, i32 0, i32 0
  %17 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %16)
  store i64 %17, 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 2
  %20 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %19)
  %21 = load i64, ptr %7, align 8, !tbaa !12
  %22 = icmp ule i64 %20, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %14
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %36

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

33:                                               ; preds = %24
  store i32 4, ptr %9, align 4
  br label %36

34:                                               ; preds = %24
  br label %35

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

36:                                               ; preds = %33, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %37 = load i32, ptr %9, align 4
  switch i32 %37, label %48 [
    i32 4, label %38
  ]

38:                                               ; preds = %36
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i64, ptr %7, align 8, !tbaa !12
  %42 = call noundef nonnull align 8 dereferenceable(33) ptr @_ZN3tbb8internal20concurrent_queue_rep6chooseEm(ptr noundef nonnull align 8 dereferenceable(576) %40, i64 noundef %41)
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i64, ptr %7, align 8, !tbaa !12
  %45 = call noundef zeroext i1 @_ZN3tbb8internal11micro_queue3popEPvmRNS0_21concurrent_queue_baseE(ptr noundef nonnull align 8 dereferenceable(33) %42, ptr noundef %43, i64 noundef %44, ptr noundef nonnull align 8 dereferenceable(40) %10)
  %46 = xor i1 %45, true
  br i1 %46, label %13, label %47, !llvm.loop !15

47:                                               ; preds = %39
  store i1 true, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %48

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN3tbb8internal11atomic_implImE16compare_and_swapEmm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef, i64 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 = { 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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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
declare dso_local noundef zeroext i1 @_ZN3tbb8internal11micro_queue3popEPvmRNS0_21concurrent_queue_baseE(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i64 noundef, ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 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 #1 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 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 #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3tbb8internal21concurrent_queue_base23internal_pop_if_presentEPv(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1) local_unnamed_addr #1 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
  br label %7

7:                                                ; preds = %17, %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)
  %8 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  %9 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %.not18 = icmp ugt i64 %9, %8
  br i1 %.not18, label %.lr.ph, label %.critedge

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

14:                                               ; preds = %.lr.ph
  call void @_ZN3tbb8internal14atomic_backoff5pauseEv(ptr noundef nonnull align 4 dereferenceable(4) %3)
  %15 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  %16 = call noundef i64 @_ZNVK3tbb8internal11atomic_implImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %.not = icmp ugt i64 %16, %15
  br i1 %.not, label %.lr.ph, label %.critedge, !llvm.loop !11

17:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  %18 = call noundef nonnull align 8 dereferenceable(33) ptr @_ZN3tbb8internal20concurrent_queue_rep6chooseEm(ptr noundef nonnull align 8 dereferenceable(576) %5, i64 noundef %10)
  %19 = call noundef zeroext i1 @_ZN3tbb8internal11micro_queue3popEPvmRNS0_21concurrent_queue_baseE(ptr noundef nonnull align 8 dereferenceable(33) %18, ptr noundef %1, i64 noundef %10, ptr noundef nonnull align 8 dereferenceable(40) %0)
  br i1 %19, label %.loopexit, label %7, !llvm.loop !13

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

.loopexit:                                        ; preds = %17, %.critedge
  %.not16 = phi i1 [ false, %.critedge ], [ true, %17 ]
  ret i1 %.not16
}

; 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 #1 align 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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass