; LLVM IR from khushmmehta/Scorch-V :: src/ScorchVkEngine/Abstractions (VulkanMemoryAllocator)

; 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.VmaDedicatedAllocationList = type { i8, %class.VmaRWMutex, %class.VmaIntrusiveLinkedList }
%class.VmaRWMutex = type { %"class.std::shared_mutex" }
%"class.std::shared_mutex" = type { %"class.std::__shared_mutex_pthread" }
%"class.std::__shared_mutex_pthread" = type { %union.pthread_rwlock_t }
%union.pthread_rwlock_t = type { %struct.__pthread_rwlock_arch_t }
%struct.__pthread_rwlock_arch_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i8, [7 x i8], i64, i32 }
%class.VmaIntrusiveLinkedList = type { ptr, ptr, i64 }
%struct.VmaDetailedStatistics = type { %struct.VmaStatistics, i32, i64, i64, i64, i64 }
%struct.VmaStatistics = type { i32, i32, i64, i64 }

; 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 nounwind uwtable
declare dso_local noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE5FrontEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE7GetNextEPK15VmaAllocation_T(ptr noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN26VmaDedicatedAllocationList21AddDetailedStatisticsER21VmaDetailedStatistics(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(64) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = getelementptr inbounds %class.VmaDedicatedAllocationList, ptr %7, i32 0, i32 2
  %9 = call noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE5FrontEv(ptr noundef nonnull align 8 dereferenceable(24) %8)
  store ptr %9, ptr %5, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %31, %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call noundef i64 @_ZNK15VmaAllocation_T7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(84) %15)
  store i64 %16, ptr %6, align 8, !tbaa !9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.VmaDetailedStatistics, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.VmaStatistics, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = add i32 %20, 1
  store i32 %21, ptr %19, align 8, !tbaa !11
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.VmaDetailedStatistics, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.VmaStatistics, ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !15
  %27 = add i64 %26, %22
  store i64 %27, ptr %25, align 8, !tbaa !15
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call noundef i64 @_ZNK15VmaAllocation_T7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(84) %29)
  call void @_ZL34VmaAddDetailedStatisticsAllocationR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64) %28, i64 noundef %30)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %31

31:                                               ; preds = %14
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = call noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE7GetNextEPK15VmaAllocation_T(ptr noundef %32)
  store ptr %33, ptr %5, align 8, !tbaa !5
  br label %10, !llvm.loop !16

34:                                               ; preds = %13
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL34VmaAddDetailedStatisticsAllocationR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64), i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !14, i64 0}
!12 = !{!"_ZTS21VmaDetailedStatistics", !13, i64 0, !14, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56}
!13 = !{!"_ZTS13VmaStatistics", !14, i64 0, !14, i64 4, !10, i64 8, !10, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !10, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE5FrontEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE7GetNextEPK15VmaAllocation_T(ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN26VmaDedicatedAllocationList21AddDetailedStatisticsER21VmaDetailedStatistics(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(64) %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 64
  %4 = tail call noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE5FrontEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not8 = icmp eq ptr %4, null
  br i1 %.not8, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  br label %6

._crit_edge:                                      ; preds = %6, %2
  ret void

6:                                                ; preds = %.lr.ph, %6
  %.09 = phi ptr [ %4, %.lr.ph ], [ %13, %6 ]
  %7 = tail call noundef i64 @_ZNK15VmaAllocation_T7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(84) %.09)
  %8 = load i32, ptr %1, align 8, !tbaa !5
  %9 = add i32 %8, 1
  store i32 %9, ptr %1, align 8, !tbaa !5
  %10 = load i64, ptr %5, align 8, !tbaa !12
  %11 = add i64 %10, %7
  store i64 %11, ptr %5, align 8, !tbaa !12
  %12 = tail call noundef i64 @_ZNK15VmaAllocation_T7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(84) %.09)
  tail call void @_ZL34VmaAddDetailedStatisticsAllocationR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64) %1, i64 noundef %12)
  %13 = tail call noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE7GetNextEPK15VmaAllocation_T(ptr noundef nonnull %.09)
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %._crit_edge, label %6, !llvm.loop !13
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK15VmaAllocation_T7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(84)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL34VmaAddDetailedStatisticsAllocationR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64), i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #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" }

!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, !8, i64 0}
!6 = !{!"_ZTS21VmaDetailedStatistics", !7, i64 0, !8, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!7 = !{!"_ZTS13VmaStatistics", !8, i64 0, !8, i64 4, !11, i64 8, !11, i64 16}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!6, !11, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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