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

%struct.VmaMutexLockRead = type { ptr }
%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.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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN16VmaMutexLockReadC2ER10VmaRWMutexb(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(56), i1 noundef zeroext) unnamed_addr #2 align 2

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

; 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
define dso_local void @_ZN26VmaDedicatedAllocationList13AddStatisticsER13VmaStatistics(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.VmaMutexLockRead, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %12 = getelementptr inbounds %class.VmaDedicatedAllocationList, ptr %11, i32 0, i32 1
  %13 = getelementptr inbounds %class.VmaDedicatedAllocationList, ptr %11, i32 0, i32 0
  %14 = load i8, ptr %13, align 8, !tbaa !9, !range !17, !noundef !18
  %15 = trunc i8 %14 to i1
  call void @_ZN16VmaMutexLockReadC2ER10VmaRWMutexb(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(56) %12, i1 noundef zeroext %15)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %16 = getelementptr inbounds %class.VmaDedicatedAllocationList, ptr %11, i32 0, i32 2
  %17 = invoke noundef i64 @_ZNK22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %16)
          to label %18 unwind label %37

18:                                               ; preds = %2
  %19 = trunc i64 %17 to i32
  store i32 %19, ptr %6, align 4, !tbaa !19
  %20 = load i32, ptr %6, align 4, !tbaa !19
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.VmaStatistics, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !21
  %24 = add i32 %23, %20
  store i32 %24, ptr %22, align 8, !tbaa !21
  %25 = load i32, ptr %6, align 4, !tbaa !19
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.VmaStatistics, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !23
  %29 = add i32 %28, %25
  store i32 %29, ptr %27, align 4, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %30 = getelementptr inbounds %class.VmaDedicatedAllocationList, ptr %11, i32 0, i32 2
  %31 = invoke noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE5FrontEv(ptr noundef nonnull align 8 dereferenceable(24) %30)
          to label %32 unwind label %41

32:                                               ; preds = %18
  store ptr %31, ptr %9, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %62, %32
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %45, label %36

36:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %68

37:                                               ; preds = %2
  %38 = landingpad { ptr, i32 }
          cleanup
  %39 = extractvalue { ptr, i32 } %38, 0
  store ptr %39, ptr %7, align 8
  %40 = extractvalue { ptr, i32 } %38, 1
  store i32 %40, ptr %8, align 4
  br label %69

41:                                               ; preds = %59, %18
  %42 = landingpad { ptr, i32 }
          cleanup
  %43 = extractvalue { ptr, i32 } %42, 0
  store ptr %43, ptr %7, align 8
  %44 = extractvalue { ptr, i32 } %42, 1
  store i32 %44, ptr %8, align 4
  br label %67

45:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = invoke noundef i64 @_ZNK15VmaAllocation_T7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(84) %46)
          to label %48 unwind label %63

48:                                               ; preds = %45
  store i64 %47, ptr %10, align 8, !tbaa !24
  %49 = load i64, ptr %10, align 8, !tbaa !24
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.VmaStatistics, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !25
  %53 = add i64 %52, %49
  store i64 %53, ptr %51, align 8, !tbaa !25
  %54 = load i64, ptr %10, align 8, !tbaa !24
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.VmaStatistics, ptr %55, i32 0, i32 3
  %57 = load i64, ptr %56, align 8, !tbaa !26
  %58 = add i64 %57, %54
  store i64 %58, ptr %56, align 8, !tbaa !26
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %59

59:                                               ; preds = %48
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = invoke noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE7GetNextEPK15VmaAllocation_T(ptr noundef %60)
          to label %62 unwind label %41

62:                                               ; preds = %59
  store ptr %61, ptr %9, align 8, !tbaa !5
  br label %33, !llvm.loop !27

63:                                               ; preds = %45
  %64 = landingpad { ptr, i32 }
          cleanup
  %65 = extractvalue { ptr, i32 } %64, 0
  store ptr %65, ptr %7, align 8
  %66 = extractvalue { ptr, i32 } %64, 1
  store i32 %66, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %67

67:                                               ; preds = %63, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %69

68:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @_ZN16VmaMutexLockReadD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void

69:                                               ; preds = %67, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @_ZN16VmaMutexLockReadD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr %7, align 8
  %72 = load i32, ptr %8, align 4
  %73 = insertvalue { ptr, i32 } poison, ptr %71, 0
  %74 = insertvalue { ptr, i32 } %73, i32 %72, 1
  resume { ptr, i32 } %74
}

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, !11, i64 0}
!10 = !{!"_ZTS26VmaDedicatedAllocationList", !11, i64 0, !12, i64 8, !15, i64 64}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"_ZTS10VmaRWMutex", !13, i64 0}
!13 = !{!"_ZTSSt12shared_mutex", !14, i64 0}
!14 = !{!"_ZTSSt22__shared_mutex_pthread", !7, i64 0}
!15 = !{!"_ZTS22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE", !6, i64 0, !6, i64 8, !16, i64 16}
!16 = !{!"long", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!20, !20, i64 0}
!20 = !{!"int", !7, i64 0}
!21 = !{!22, !20, i64 0}
!22 = !{!"_ZTS13VmaStatistics", !20, i64 0, !20, i64 4, !16, i64 8, !16, i64 16}
!23 = !{!22, !20, i64 4}
!24 = !{!16, !16, i64 0}
!25 = !{!22, !16, i64 8}
!26 = !{!22, !16, i64 16}
!27 = distinct !{!27, !28}
!28 = !{!"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"

%struct.VmaMutexLockRead = 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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN16VmaMutexLockReadC2ER10VmaRWMutexb(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(56), i1 noundef zeroext) unnamed_addr #2 align 2

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN26VmaDedicatedAllocationList13AddStatisticsER13VmaStatistics(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr nocapture noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %struct.VmaMutexLockRead, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i8, ptr %0, align 8, !tbaa !5, !range !16, !noundef !17
  %6 = trunc nuw i8 %5 to i1
  call void @_ZN16VmaMutexLockReadC2ER10VmaRWMutexb(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(56) %4, i1 noundef zeroext %6)
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  %8 = call noundef i64 @_ZNK22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %7)
  %9 = trunc i64 %8 to i32
  %10 = load <2 x i32>, ptr %1, align 8, !tbaa !18
  %11 = insertelement <2 x i32> poison, i32 %9, i64 0
  %12 = shufflevector <2 x i32> %11, <2 x i32> poison, <2 x i32> zeroinitializer
  %13 = add <2 x i32> %10, %12
  store <2 x i32> %13, ptr %1, align 8, !tbaa !18
  %14 = call noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE5FrontEv(ptr noundef nonnull align 8 dereferenceable(24) %7)
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  br label %16

16:                                               ; preds = %20, %2
  %.0 = phi ptr [ %14, %2 ], [ %26, %20 ]
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %17, label %20

17:                                               ; preds = %16
  call void @_ZN16VmaMutexLockReadD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret void

18:                                               ; preds = %20
  %19 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN16VmaMutexLockReadD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  resume { ptr, i32 } %19

20:                                               ; preds = %16
  %21 = call noundef i64 @_ZNK15VmaAllocation_T7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(84) %.0)
  %22 = load <2 x i64>, ptr %15, align 8, !tbaa !20
  %23 = insertelement <2 x i64> poison, i64 %21, i64 0
  %24 = shufflevector <2 x i64> %23, <2 x i64> poison, <2 x i32> zeroinitializer
  %25 = add <2 x i64> %22, %24
  store <2 x i64> %25, ptr %15, align 8, !tbaa !20
  %26 = invoke noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE7GetNextEPK15VmaAllocation_T(ptr noundef nonnull %.0)
          to label %16 unwind label %18, !llvm.loop !21
}

attributes #0 = { mustprogress 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, !7, i64 0}
!6 = !{!"_ZTS26VmaDedicatedAllocationList", !7, i64 0, !10, i64 8, !13, i64 64}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS10VmaRWMutex", !11, i64 0}
!11 = !{!"_ZTSSt12shared_mutex", !12, i64 0}
!12 = !{!"_ZTSSt22__shared_mutex_pthread", !8, i64 0}
!13 = !{!"_ZTS22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE", !14, i64 0, !14, i64 8, !15, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!19, !19, i64 0}
!19 = !{!"int", !8, i64 0}
!20 = !{!15, !15, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass