; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/old/concurrent_queue_v2.ll (ZN3tbb8internal21concurrent_queue_baseD2Ev)

; 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::cache_aligned_allocator" = type { i8 }
%"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 }

@_ZTVN3tbb8internal21concurrent_queue_baseE = external dso_local unnamed_addr constant { [6 x ptr] }, align 8

; 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

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3tbb8internal21concurrent_queue_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %"class.tbb::cache_aligned_allocator", align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  store ptr getelementptr inbounds inrange(-16, 32) ({ [6 x ptr] }, ptr @_ZTVN3tbb8internal21concurrent_queue_baseE, i32 0, i32 0, i32 2), ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %8 = getelementptr inbounds %"class.tbb::internal::concurrent_queue_base", ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  store i64 8, ptr %3, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store i64 0, ptr %4, align 8, !tbaa !14
  br label %10

10:                                               ; preds = %32, %1
  %11 = load i64, ptr %4, align 8, !tbaa !14
  %12 = load i64, ptr %3, align 8, !tbaa !14
  %13 = icmp ult i64 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %16 = getelementptr inbounds %"class.tbb::internal::concurrent_queue_base", ptr %7, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = getelementptr inbounds %"class.tbb::internal::concurrent_queue_rep", ptr %17, i32 0, i32 4
  %19 = load i64, ptr %4, align 8, !tbaa !14
  %20 = getelementptr inbounds [8 x %"struct.tbb::internal::micro_queue"], ptr %18, i64 0, i64 %19
  %21 = getelementptr inbounds %"struct.tbb::internal::micro_queue", ptr %20, i32 0, i32 2
  %22 = invoke noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_21concurrent_queue_base4pageEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %21)
          to label %23 unwind label %39

23:                                               ; preds = %15
  store ptr %22, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %31

26:                                               ; preds = %23
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  call void @_ZdlPvm(ptr noundef %27, i64 noundef 16) #6
  br label %30

30:                                               ; preds = %29, %26
  br label %31

31:                                               ; preds = %30, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %32

32:                                               ; preds = %31
  %33 = load i64, ptr %4, align 8, !tbaa !14
  %34 = add i64 %33, 1
  store i64 %34, ptr %4, align 8, !tbaa !14
  br label %10, !llvm.loop !15

35:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #5
  call void @_ZN3tbb23cache_aligned_allocatorINS_8internal20concurrent_queue_repEEC2Ev(ptr noundef nonnull align 1 dereferenceable(1) %6) #5
  %36 = getelementptr inbounds %"class.tbb::internal::concurrent_queue_base", ptr %7, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  invoke void @_ZN3tbb23cache_aligned_allocatorINS_8internal20concurrent_queue_repEE10deallocateEPS2_m(ptr noundef nonnull align 1 dereferenceable(1) %6, ptr noundef %37, i64 noundef 1)
          to label %38 unwind label %39

38:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void

39:                                               ; preds = %35, %15
  %40 = landingpad { ptr, i32 }
          catch ptr null
  %41 = extractvalue { ptr, i32 } %40, 0
  call void @__clang_call_terminate(ptr %41) #7
  unreachable
}

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb23cache_aligned_allocatorINS_8internal20concurrent_queue_repEE10deallocateEPS2_m(ptr noundef nonnull align 1 dereferenceable(1), ptr 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 = { noinline noreturn nounwind uwtable "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 = { nobuiltin nounwind "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 = { nounwind }
attributes #6 = { builtin nounwind }
attributes #7 = { noreturn 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTSN3tbb8internal21concurrent_queue_baseE", !6, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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::cache_aligned_allocator" = type { i8 }

@_ZTVN3tbb8internal21concurrent_queue_baseE = external dso_local unnamed_addr constant { [6 x ptr] }, align 8

; 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

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3tbb8internal21concurrent_queue_baseD2Ev(ptr nocapture noundef nonnull align 8 dereferenceable(40) %0) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.tbb::cache_aligned_allocator", align 1
  store ptr getelementptr inbounds inrange(-16, 32) (i8, ptr @_ZTVN3tbb8internal21concurrent_queue_baseE, i64 16), ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !8
  %5 = getelementptr inbounds i8, ptr %4, i64 272
  %6 = invoke noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_21concurrent_queue_base4pageEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %5)
          to label %7 unwind label %.loopexit

7:                                                ; preds = %1
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %9, label %8

8:                                                ; preds = %7
  tail call void @_ZdlPvm(ptr noundef nonnull %6, i64 noundef 16) #5
  br label %9

9:                                                ; preds = %8, %7
  %10 = load ptr, ptr %3, align 8, !tbaa !8
  %11 = getelementptr inbounds i8, ptr %10, i64 312
  %12 = invoke noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_21concurrent_queue_base4pageEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %11)
          to label %13 unwind label %.loopexit

13:                                               ; preds = %9
  %.not.1 = icmp eq ptr %12, null
  br i1 %.not.1, label %15, label %14

14:                                               ; preds = %13
  tail call void @_ZdlPvm(ptr noundef nonnull %12, i64 noundef 16) #5
  br label %15

15:                                               ; preds = %14, %13
  %16 = load ptr, ptr %3, align 8, !tbaa !8
  %17 = getelementptr inbounds i8, ptr %16, i64 352
  %18 = invoke noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_21concurrent_queue_base4pageEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %17)
          to label %19 unwind label %.loopexit

19:                                               ; preds = %15
  %.not.2 = icmp eq ptr %18, null
  br i1 %.not.2, label %21, label %20

20:                                               ; preds = %19
  tail call void @_ZdlPvm(ptr noundef nonnull %18, i64 noundef 16) #5
  br label %21

21:                                               ; preds = %20, %19
  %22 = load ptr, ptr %3, align 8, !tbaa !8
  %23 = getelementptr inbounds i8, ptr %22, i64 392
  %24 = invoke noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_21concurrent_queue_base4pageEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %23)
          to label %25 unwind label %.loopexit

25:                                               ; preds = %21
  %.not.3 = icmp eq ptr %24, null
  br i1 %.not.3, label %27, label %26

26:                                               ; preds = %25
  tail call void @_ZdlPvm(ptr noundef nonnull %24, i64 noundef 16) #5
  br label %27

27:                                               ; preds = %26, %25
  %28 = load ptr, ptr %3, align 8, !tbaa !8
  %29 = getelementptr inbounds i8, ptr %28, i64 432
  %30 = invoke noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_21concurrent_queue_base4pageEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %29)
          to label %31 unwind label %.loopexit

31:                                               ; preds = %27
  %.not.4 = icmp eq ptr %30, null
  br i1 %.not.4, label %33, label %32

32:                                               ; preds = %31
  tail call void @_ZdlPvm(ptr noundef nonnull %30, i64 noundef 16) #5
  br label %33

33:                                               ; preds = %32, %31
  %34 = load ptr, ptr %3, align 8, !tbaa !8
  %35 = getelementptr inbounds i8, ptr %34, i64 472
  %36 = invoke noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_21concurrent_queue_base4pageEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %35)
          to label %37 unwind label %.loopexit

37:                                               ; preds = %33
  %.not.5 = icmp eq ptr %36, null
  br i1 %.not.5, label %39, label %38

38:                                               ; preds = %37
  tail call void @_ZdlPvm(ptr noundef nonnull %36, i64 noundef 16) #5
  br label %39

39:                                               ; preds = %38, %37
  %40 = load ptr, ptr %3, align 8, !tbaa !8
  %41 = getelementptr inbounds i8, ptr %40, i64 512
  %42 = invoke noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_21concurrent_queue_base4pageEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %41)
          to label %43 unwind label %.loopexit

43:                                               ; preds = %39
  %.not.6 = icmp eq ptr %42, null
  br i1 %.not.6, label %45, label %44

44:                                               ; preds = %43
  tail call void @_ZdlPvm(ptr noundef nonnull %42, i64 noundef 16) #5
  br label %45

45:                                               ; preds = %44, %43
  %46 = load ptr, ptr %3, align 8, !tbaa !8
  %47 = getelementptr inbounds i8, ptr %46, i64 552
  %48 = invoke noundef ptr @_ZNVK3tbb8internal11atomic_implIPNS0_21concurrent_queue_base4pageEEcvS4_Ev(ptr noundef nonnull align 8 dereferenceable(8) %47)
          to label %49 unwind label %.loopexit

49:                                               ; preds = %45
  %.not.7 = icmp eq ptr %48, null
  br i1 %.not.7, label %51, label %50

50:                                               ; preds = %49
  tail call void @_ZdlPvm(ptr noundef nonnull %48, i64 noundef 16) #5
  br label %51

51:                                               ; preds = %50, %49
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #6
  call void @_ZN3tbb23cache_aligned_allocatorINS_8internal20concurrent_queue_repEEC2Ev(ptr noundef nonnull align 1 dereferenceable(1) %2) #6
  %52 = load ptr, ptr %3, align 8, !tbaa !8
  invoke void @_ZN3tbb23cache_aligned_allocatorINS_8internal20concurrent_queue_repEE10deallocateEPS2_m(ptr noundef nonnull align 1 dereferenceable(1) %2, ptr noundef %52, i64 noundef 1)
          to label %53 unwind label %.loopexit.split-lp

53:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #6
  ret void

.loopexit:                                        ; preds = %45, %39, %33, %27, %21, %15, %9, %1
  %lpad.loopexit = landingpad { ptr, i32 }
          catch ptr null
  br label %54

.loopexit.split-lp:                               ; preds = %51
  %lpad.loopexit.split-lp = landingpad { ptr, i32 }
          catch ptr null
  br label %54

54:                                               ; preds = %.loopexit.split-lp, %.loopexit
  %lpad.phi = phi { ptr, i32 } [ %lpad.loopexit, %.loopexit ], [ %lpad.loopexit.split-lp, %.loopexit.split-lp ]
  %55 = extractvalue { ptr, i32 } %lpad.phi, 0
  call void @__clang_call_terminate(ptr %55) #7
  unreachable
}

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb23cache_aligned_allocatorINS_8internal20concurrent_queue_repEE10deallocateEPS2_m(ptr noundef nonnull align 1 dereferenceable(1), ptr 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 = { noinline noreturn nounwind uwtable "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 = { nobuiltin nounwind "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 = { builtin nounwind }
attributes #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !10, i64 8}
!9 = !{!"_ZTSN3tbb8internal21concurrent_queue_baseE", !10, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!"long", !11, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass