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

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

%"struct.sm::GenericAllocator::Deleter" = type { ptr }
%"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.std::_Head_base.4" = type { ptr }

; 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
define dso_local void @_ZN2sm9AllocatorC2EPv(ptr noundef nonnull align 64 dereferenceable(4568) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.sm::GenericAllocator::Deleter", align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.sm::Allocator", ptr %6, i32 0, i32 0
  store i64 0, ptr %7, align 64, !tbaa !9
  %8 = getelementptr inbounds %"class.sm::Allocator", ptr %6, i32 0, i32 1
  store i64 0, ptr %8, align 8, !tbaa !23
  %9 = getelementptr inbounds %"class.sm::Allocator", ptr %6, i32 0, i32 2
  store ptr null, ptr %9, align 16, !tbaa !24
  %10 = getelementptr inbounds %"class.sm::Allocator", ptr %6, i32 0, i32 3
  %11 = getelementptr inbounds %"class.sm::Allocator", ptr %6, i32 0, i32 5
  call void @_ZNSt5arrayIN2sm9Allocator10PoolBucketELm62EEC2Ev(ptr noundef nonnull align 64 dereferenceable(3968) %11)
  %12 = getelementptr inbounds %"class.sm::Allocator", ptr %6, i32 0, i32 6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN2sm16GenericAllocator7DeleterC2EPv(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef %13)
  call void @_ZNSt10unique_ptrIhN2sm16GenericAllocator7DeleterEEC2IS2_vEEPhNSt9enable_ifIXntsr19is_lvalue_referenceIT_EE5valueEOS7_E4typeE(ptr noundef nonnull align 8 dereferenceable(16) %12, ptr noundef null, ptr noundef nonnull align 8 dereferenceable(8) %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %14 = getelementptr inbounds %"class.sm::Allocator", ptr %6, i32 0, i32 7
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %15, ptr %14, align 16, !tbaa !25
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNSt5arrayIN2sm9Allocator10PoolBucketELm62EEC2Ev(ptr noundef nonnull align 64 dereferenceable(3968)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2sm16GenericAllocator7DeleterC2EPv(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10unique_ptrIhN2sm16GenericAllocator7DeleterEEC2IS2_vEEPhNSt9enable_ifIXntsr19is_lvalue_referenceIT_EE5valueEOS7_E4typeE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 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 = { inlinehint 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 #3 = { 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 #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, !11, i64 0}
!10 = !{!"_ZTSN2sm9AllocatorE", !11, i64 0, !11, i64 8, !6, i64 16, !12, i64 24, !13, i64 576, !14, i64 4544, !6, i64 4560}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTSSt5arrayIPhLm62EE", !7, i64 0}
!13 = !{!"_ZTSSt5arrayIN2sm9Allocator10PoolBucketELm62EE", !7, i64 0}
!14 = !{!"_ZTSSt10unique_ptrIhN2sm16GenericAllocator7DeleterEE", !15, i64 0}
!15 = !{!"_ZTSSt15__uniq_ptr_dataIhN2sm16GenericAllocator7DeleterELb1ELb1EE", !16, i64 0}
!16 = !{!"_ZTSSt15__uniq_ptr_implIhN2sm16GenericAllocator7DeleterEE", !17, i64 0}
!17 = !{!"_ZTSSt5tupleIJPhN2sm16GenericAllocator7DeleterEEE", !18, i64 0}
!18 = !{!"_ZTSSt11_Tuple_implILm0EJPhN2sm16GenericAllocator7DeleterEEE", !19, i64 0, !22, i64 8}
!19 = !{!"_ZTSSt11_Tuple_implILm1EJN2sm16GenericAllocator7DeleterEEE", !20, i64 0}
!20 = !{!"_ZTSSt10_Head_baseILm1EN2sm16GenericAllocator7DeleterELb0EE", !21, i64 0}
!21 = !{!"_ZTSN2sm16GenericAllocator7DeleterE", !6, i64 0}
!22 = !{!"_ZTSSt10_Head_baseILm0EPhLb0EE", !6, i64 0}
!23 = !{!10, !11, i64 8}
!24 = !{!10, !6, i64 16}
!25 = !{!10, !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"

%"struct.sm::GenericAllocator::Deleter" = type { ptr }

; 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
define dso_local void @_ZN2sm9AllocatorC2EPv(ptr noundef nonnull align 64 dereferenceable(4568) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca %"struct.sm::GenericAllocator::Deleter", align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 576
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 64 dereferenceable(24) %0, i8 0, i64 24, i1 false)
  tail call void @_ZNSt5arrayIN2sm9Allocator10PoolBucketELm62EEC2Ev(ptr noundef nonnull align 64 dereferenceable(3968) %4)
  %5 = getelementptr inbounds i8, ptr %0, i64 4544
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  call void @_ZN2sm16GenericAllocator7DeleterC2EPv(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef %1)
  call void @_ZNSt10unique_ptrIhN2sm16GenericAllocator7DeleterEEC2IS2_vEEPhNSt9enable_ifIXntsr19is_lvalue_referenceIT_EE5valueEOS7_E4typeE(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef null, ptr noundef nonnull align 8 dereferenceable(8) %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  %6 = getelementptr inbounds i8, ptr %0, i64 4560
  store ptr %1, ptr %6, align 16, !tbaa !5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNSt5arrayIN2sm9Allocator10PoolBucketELm62EEC2Ev(ptr noundef nonnull align 64 dereferenceable(3968)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2sm16GenericAllocator7DeleterC2EPv(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10unique_ptrIhN2sm16GenericAllocator7DeleterEEC2IS2_vEEPhNSt9enable_ifIXntsr19is_lvalue_referenceIT_EE5valueEOS7_E4typeE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { inlinehint 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 #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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, !10, i64 4560}
!6 = !{!"_ZTSN2sm9AllocatorE", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !12, i64 576, !13, i64 4544, !10, i64 4560}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTSSt5arrayIPhLm62EE", !8, i64 0}
!12 = !{!"_ZTSSt5arrayIN2sm9Allocator10PoolBucketELm62EE", !8, i64 0}
!13 = !{!"_ZTSSt10unique_ptrIhN2sm16GenericAllocator7DeleterEE", !14, i64 0}
!14 = !{!"_ZTSSt15__uniq_ptr_dataIhN2sm16GenericAllocator7DeleterELb1ELb1EE", !15, i64 0}
!15 = !{!"_ZTSSt15__uniq_ptr_implIhN2sm16GenericAllocator7DeleterEE", !16, i64 0}
!16 = !{!"_ZTSSt5tupleIJPhN2sm16GenericAllocator7DeleterEEE", !17, i64 0}
!17 = !{!"_ZTSSt11_Tuple_implILm0EJPhN2sm16GenericAllocator7DeleterEEE", !18, i64 0, !21, i64 8}
!18 = !{!"_ZTSSt11_Tuple_implILm1EJN2sm16GenericAllocator7DeleterEEE", !19, i64 0}
!19 = !{!"_ZTSSt10_Head_baseILm1EN2sm16GenericAllocator7DeleterELb0EE", !20, i64 0}
!20 = !{!"_ZTSN2sm16GenericAllocator7DeleterE", !10, i64 0}
!21 = !{!"_ZTSSt10_Head_baseILm0EPhLb0EE", !10, i64 0}


; Effective O3 passes: EarlyCSEPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,TailCallElimPass