; LLVM IR from AmplitudeAudio/sdk :: src/Utils/SmMalloc (smmalloc)

; 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.std::initializer_list" = type { ptr, i64 }
%"class.sm::Allocator" = type { i64, i64, ptr, %"struct.std::array", [56 x i8], %"struct.std::array.0", %"class.std::unique_ptr", ptr, [40 x i8] }
%"struct.std::array" = type { [62 x ptr] }
%"struct.std::array.0" = type { [62 x %"struct.sm::Allocator::PoolBucket"] }
%"struct.sm::Allocator::PoolBucket" = type <{ %"struct.std::atomic", ptr, ptr, %"struct.std::atomic.1", [36 x i8] }>
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i64 }
%"struct.std::atomic.1" = type { %"struct.std::__atomic_base.2" }
%"struct.std::__atomic_base.2" = type { i32 }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Tuple_impl.3", %"struct.std::_Head_base.4" }
%"struct.std::_Tuple_impl.3" = type { %"struct.std::_Head_base" }
%"struct.std::_Head_base" = type { %"struct.sm::GenericAllocator::Deleter" }
%"struct.sm::GenericAllocator::Deleter" = type { ptr }
%"struct.std::_Head_base.4" = type { ptr }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2sm8internal13TlsPoolBucket4InitEPjjNS_18CacheWarmupOptionsEPNS_9AllocatorEm(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef) #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 @_ZN2sm9Allocator17CreateThreadCacheENS_18CacheWarmupOptionsESt16initializer_listIjE(ptr noundef nonnull align 64 dereferenceable(4568) %0, i32 noundef %1, ptr %2, i64 %3) #0 align 2 {
  %5 = alloca %"class.std::initializer_list", align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 0
  store ptr %2, ptr %16, align 8
  %17 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 1
  store i64 %3, ptr %17, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  %18 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store ptr %5, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = call noundef ptr @_ZNKSt16initializer_listIjE5beginEv(ptr noundef nonnull align 8 dereferenceable(16) %19) #4
  store ptr %20, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = call noundef ptr @_ZNKSt16initializer_listIjE3endEv(ptr noundef nonnull align 8 dereferenceable(16) %21) #4
  store ptr %22, ptr %11, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %56, %4
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  %26 = icmp ne ptr %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 2, ptr %12, align 4
  br label %59

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load i32, ptr %29, align 4, !tbaa !13
  store i32 %30, ptr %13, align 4, !tbaa !13
  %31 = load i64, ptr %8, align 8, !tbaa !11
  %32 = getelementptr inbounds %"class.sm::Allocator", ptr %18, i32 0, i32 0
  %33 = load i64, ptr %32, align 64, !tbaa !15
  %34 = icmp uge i64 %31, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %28
  store i32 2, ptr %12, align 4
  br label %53

36:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %37 = load i32, ptr %13, align 4, !tbaa !13
  %38 = add i32 %37, 7
  store i32 %38, ptr %14, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %39 = getelementptr inbounds %"class.sm::Allocator", ptr %18, i32 0, i32 7
  %40 = load ptr, ptr %39, align 16, !tbaa !28
  %41 = load i32, ptr %14, align 4, !tbaa !13
  %42 = zext i32 %41 to i64
  %43 = mul i64 %42, 4
  %44 = call noundef ptr @_ZN2sm16GenericAllocator5AllocEPvmm(ptr noundef %40, i64 noundef %43, i64 noundef 64)
  store ptr %44, ptr %15, align 8, !tbaa !5
  %45 = load i64, ptr %8, align 8, !tbaa !11
  %46 = call noundef ptr @_ZN2sm12GetTlsBucketEm(i64 noundef %45)
  %47 = load ptr, ptr %15, align 8, !tbaa !5
  %48 = load i32, ptr %14, align 4, !tbaa !13
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = load i64, ptr %8, align 8, !tbaa !11
  call void @_ZN2sm8internal13TlsPoolBucket4InitEPjjNS_18CacheWarmupOptionsEPNS_9AllocatorEm(ptr noundef nonnull align 8 dereferenceable(64) %46, ptr noundef %47, i32 noundef %48, i32 noundef %49, ptr noundef %18, i64 noundef %50)
  %51 = load i64, ptr %8, align 8, !tbaa !11
  %52 = add i64 %51, 1
  store i64 %52, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  store i32 0, ptr %12, align 4
  br label %53

53:                                               ; preds = %36, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  %54 = load i32, ptr %12, align 4
  switch i32 %54, label %59 [
    i32 0, label %55
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds i32, ptr %57, i32 1
  store ptr %58, ptr %10, align 8, !tbaa !5
  br label %23

59:                                               ; preds = %53, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %60

60:                                               ; preds = %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt16initializer_listIjE5beginEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt16initializer_listIjE3endEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

declare noundef ptr @_ZN2sm16GenericAllocator5AllocEPvmm(ptr noundef, i64 noundef, i64 noundef) #3

declare noundef ptr @_ZN2sm12GetTlsBucketEm(i64 noundef) #3

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 = { "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 = { 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 = !{!"_ZTSN2sm18CacheWarmupOptionsE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !12, i64 0}
!16 = !{!"_ZTSN2sm9AllocatorE", !12, i64 0, !12, i64 8, !6, i64 16, !17, i64 24, !18, i64 576, !19, i64 4544, !6, i64 4560}
!17 = !{!"_ZTSSt5arrayIPhLm62EE", !7, i64 0}
!18 = !{!"_ZTSSt5arrayIN2sm9Allocator10PoolBucketELm62EE", !7, i64 0}
!19 = !{!"_ZTSSt10unique_ptrIhN2sm16GenericAllocator7DeleterEE", !20, i64 0}
!20 = !{!"_ZTSSt15__uniq_ptr_dataIhN2sm16GenericAllocator7DeleterELb1ELb1EE", !21, i64 0}
!21 = !{!"_ZTSSt15__uniq_ptr_implIhN2sm16GenericAllocator7DeleterEE", !22, i64 0}
!22 = !{!"_ZTSSt5tupleIJPhN2sm16GenericAllocator7DeleterEEE", !23, i64 0}
!23 = !{!"_ZTSSt11_Tuple_implILm0EJPhN2sm16GenericAllocator7DeleterEEE", !24, i64 0, !27, i64 8}
!24 = !{!"_ZTSSt11_Tuple_implILm1EJN2sm16GenericAllocator7DeleterEEE", !25, i64 0}
!25 = !{!"_ZTSSt10_Head_baseILm1EN2sm16GenericAllocator7DeleterELb0EE", !26, i64 0}
!26 = !{!"_ZTSN2sm16GenericAllocator7DeleterE", !6, i64 0}
!27 = !{!"_ZTSSt10_Head_baseILm0EPhLb0EE", !6, i64 0}
!28 = !{!16, !6, i64 4560}


; 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.std::initializer_list" = type { ptr, i64 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2sm9Allocator17CreateThreadCacheENS_18CacheWarmupOptionsESt16initializer_listIjE(ptr noundef nonnull align 64 dereferenceable(4568) %0, i32 noundef %1, ptr %2, i64 %3) local_unnamed_addr #0 align 2 {
  %5 = alloca %"class.std::initializer_list", align 8
  store ptr %2, ptr %5, align 8
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  store i64 %3, ptr %6, align 8
  %7 = call noundef ptr @_ZNKSt16initializer_listIjE5beginEv(ptr noundef nonnull align 8 dereferenceable(16) %5) #3
  %8 = call noundef ptr @_ZNKSt16initializer_listIjE3endEv(ptr noundef nonnull align 8 dereferenceable(16) %5) #3
  %.not21 = icmp ne ptr %7, %8
  %9 = load i64, ptr %0, align 64
  %.not1822 = icmp ne i64 %9, 0
  %or.cond23 = select i1 %.not21, i1 %.not1822, i1 false
  br i1 %or.cond23, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 4560
  br label %11

11:                                               ; preds = %.lr.ph, %11
  %.025 = phi i64 [ 0, %.lr.ph ], [ %19, %11 ]
  %.01624 = phi ptr [ %7, %.lr.ph ], [ %20, %11 ]
  %12 = load i32, ptr %.01624, align 4, !tbaa !5
  %13 = add i32 %12, 7
  %14 = load ptr, ptr %10, align 16, !tbaa !9
  %15 = zext i32 %13 to i64
  %16 = shl nuw nsw i64 %15, 2
  %17 = call noundef ptr @_ZN2sm16GenericAllocator5AllocEPvmm(ptr noundef %14, i64 noundef %16, i64 noundef 64)
  %18 = call noundef ptr @_ZN2sm12GetTlsBucketEm(i64 noundef %.025)
  call void @_ZN2sm8internal13TlsPoolBucket4InitEPjjNS_18CacheWarmupOptionsEPNS_9AllocatorEm(ptr noundef nonnull align 8 dereferenceable(64) %18, ptr noundef %17, i32 noundef %13, i32 noundef %1, ptr noundef nonnull %0, i64 noundef %.025)
  %19 = add nuw i64 %.025, 1
  %20 = getelementptr inbounds i8, ptr %.01624, i64 4
  %.not = icmp ne ptr %20, %8
  %21 = load i64, ptr %0, align 64
  %.not18 = icmp ult i64 %19, %21
  %or.cond = select i1 %.not, i1 %.not18, i1 false
  br i1 %or.cond, label %11, label %._crit_edge

._crit_edge:                                      ; preds = %11, %4
  ret void
}

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

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

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

declare noundef ptr @_ZN2sm12GetTlsBucketEm(i64 noundef) local_unnamed_addr #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 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 #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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 4560}
!10 = !{!"_ZTSN2sm9AllocatorE", !11, i64 0, !11, i64 8, !12, i64 16, !13, i64 24, !14, i64 576, !15, i64 4544, !12, i64 4560}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"_ZTSSt5arrayIPhLm62EE", !7, i64 0}
!14 = !{!"_ZTSSt5arrayIN2sm9Allocator10PoolBucketELm62EE", !7, i64 0}
!15 = !{!"_ZTSSt10unique_ptrIhN2sm16GenericAllocator7DeleterEE", !16, i64 0}
!16 = !{!"_ZTSSt15__uniq_ptr_dataIhN2sm16GenericAllocator7DeleterELb1ELb1EE", !17, i64 0}
!17 = !{!"_ZTSSt15__uniq_ptr_implIhN2sm16GenericAllocator7DeleterEE", !18, i64 0}
!18 = !{!"_ZTSSt5tupleIJPhN2sm16GenericAllocator7DeleterEEE", !19, i64 0}
!19 = !{!"_ZTSSt11_Tuple_implILm0EJPhN2sm16GenericAllocator7DeleterEEE", !20, i64 0, !23, i64 8}
!20 = !{!"_ZTSSt11_Tuple_implILm1EJN2sm16GenericAllocator7DeleterEEE", !21, i64 0}
!21 = !{!"_ZTSSt10_Head_baseILm1EN2sm16GenericAllocator7DeleterELb0EE", !22, i64 0}
!22 = !{!"_ZTSN2sm16GenericAllocator7DeleterE", !12, i64 0}
!23 = !{!"_ZTSSt10_Head_baseILm0EPhLb0EE", !12, i64 0}


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