; 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.VmaBudget = type { %struct.VmaStatistics, i64, i64 }
%struct.VmaStatistics = type { i32, i32, i64, i64 }
%struct.VmaAllocationCreateInfo = type { i32, i32, i32, i32, i32, ptr, ptr, float }
%struct.VmaAllocator_T = type <{ i8, [3 x i8], i32, i8, i8, i8, i8, i8, i8, [2 x i8], ptr, ptr, i8, [7 x i8], %struct.VkAllocationCallbacks, %struct.VmaDeviceMemoryCallbacks, %class.VmaAllocationObjectAllocator, i32, [4 x i8], %struct.VkPhysicalDeviceProperties, %struct.VkPhysicalDeviceMemoryProperties, [32 x ptr], [32 x %class.VmaDedicatedAllocationList], %struct.VmaCurrentBudgetData, %"struct.std::atomic", [4 x i8], i64, ptr, %"struct.std::atomic", %"struct.std::atomic", [32 x i32], %class.VmaRWMutex, %class.VmaIntrusiveLinkedList.14, i32, [4 x i8], %struct.VmaVulkanFunctions, i32, [4 x i8] }>
%struct.VkAllocationCallbacks = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct.VmaDeviceMemoryCallbacks = type { ptr, ptr, ptr }
%class.VmaAllocationObjectAllocator = type { %class.VmaMutex, %class.VmaPoolAllocator.11 }
%class.VmaMutex = type { %"class.std::mutex" }
%"class.std::mutex" = type { %"class.std::__mutex_base" }
%"class.std::__mutex_base" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%class.VmaPoolAllocator.11 = type { ptr, i32, %class.VmaVector.12 }
%class.VmaVector.12 = type { %struct.VmaStlAllocator.13, ptr, i64, i64 }
%struct.VmaStlAllocator.13 = type { ptr }
%struct.VkPhysicalDeviceProperties = type { i32, i32, i32, i32, i32, [256 x i8], [16 x i8], %struct.VkPhysicalDeviceLimits, %struct.VkPhysicalDeviceSparseProperties }
%struct.VkPhysicalDeviceLimits = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [3 x i32], i32, [3 x i32], i32, i32, i32, i32, i32, float, float, i32, [2 x i32], [2 x float], i32, i64, i64, i64, i64, i32, i32, i32, i32, float, float, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, float, i32, i32, i32, i32, [2 x float], [2 x float], float, float, i32, i32, i64, i64, i64 }
%struct.VkPhysicalDeviceSparseProperties = type { i32, i32, i32, i32, i32 }
%struct.VkPhysicalDeviceMemoryProperties = type { i32, [32 x %struct.VkMemoryType], i32, [16 x %struct.VkMemoryHeap] }
%struct.VkMemoryType = type { i32, i32 }
%struct.VkMemoryHeap = type { i64, i32 }
%class.VmaDedicatedAllocationList = type { i8, %class.VmaRWMutex, %class.VmaIntrusiveLinkedList }
%class.VmaIntrusiveLinkedList = type { ptr, ptr, i64 }
%struct.VmaCurrentBudgetData = type { [16 x %"struct.std::atomic"], [16 x %"struct.std::atomic"], [16 x %"struct.std::atomic.9"], [16 x %"struct.std::atomic.9"], %"struct.std::atomic", %class.VmaRWMutex, [16 x i64], [16 x i64], [16 x i64] }
%"struct.std::atomic.9" = type { %"struct.std::__atomic_base.10" }
%"struct.std::__atomic_base.10" = type { i64 }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%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.14 = type { ptr, ptr, i64 }
%struct.VmaVulkanFunctions = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK14VmaAllocator_T26MemoryTypeIndexToHeapIndexEj(ptr noundef nonnull align 8 dereferenceable(5916), i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14VmaAllocator_T14GetHeapBudgetsEP9VmaBudgetjj(ptr noundef nonnull align 8 dereferenceable(5916), ptr noundef, i32 noundef, i32 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN14VmaAllocator_T17CalcMemTypeParamsER23VmaAllocationCreateInfojmm(ptr noundef nonnull align 8 dereferenceable(5916) %0, ptr noundef nonnull align 8 dereferenceable(48) %1, i32 noundef %2, i64 noundef %3, i64 noundef %4) #3 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca %struct.VmaBudget, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !11
  store i64 %4, ptr %11, align 8, !tbaa !11
  %15 = load ptr, ptr %7, align 8
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.VmaAllocationCreateInfo, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = and i32 %18, 4
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %36

21:                                               ; preds = %5
  %22 = getelementptr inbounds %struct.VmaAllocator_T, ptr %15, i32 0, i32 20
  %23 = getelementptr inbounds %struct.VkPhysicalDeviceMemoryProperties, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [32 x %struct.VkMemoryType], ptr %23, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.VkMemoryType, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %29 = and i32 %28, 2
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %36

31:                                               ; preds = %21
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.VmaAllocationCreateInfo, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !13
  %35 = and i32 %34, -5
  store i32 %35, ptr %33, align 8, !tbaa !13
  br label %36

36:                                               ; preds = %31, %21, %5
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.VmaAllocationCreateInfo, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !13
  %40 = and i32 %39, 1
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %66

42:                                               ; preds = %36
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.VmaAllocationCreateInfo, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !13
  %46 = and i32 %45, 256
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %66

48:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = call noundef i32 @_ZNK14VmaAllocator_T26MemoryTypeIndexToHeapIndexEj(ptr noundef nonnull align 8 dereferenceable(5916) %15, i32 noundef %49)
  store i32 %50, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %13) #4
  call void @llvm.memset.p0.i64(ptr align 8 %13, i8 0, i64 40, i1 false)
  %51 = load i32, ptr %12, align 4, !tbaa !9
  call void @_ZN14VmaAllocator_T14GetHeapBudgetsEP9VmaBudgetjj(ptr noundef nonnull align 8 dereferenceable(5916) %15, ptr noundef %13, i32 noundef %51, i32 noundef 1)
  %52 = getelementptr inbounds %struct.VmaBudget, ptr %13, i32 0, i32 1
  %53 = load i64, ptr %52, align 8, !tbaa !19
  %54 = load i64, ptr %10, align 8, !tbaa !11
  %55 = load i64, ptr %11, align 8, !tbaa !11
  %56 = mul i64 %54, %55
  %57 = add i64 %53, %56
  %58 = getelementptr inbounds %struct.VmaBudget, ptr %13, i32 0, i32 2
  %59 = load i64, ptr %58, align 8, !tbaa !22
  %60 = icmp ugt i64 %57, %59
  br i1 %60, label %61, label %62

61:                                               ; preds = %48
  store i32 -2, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %63

62:                                               ; preds = %48
  store i32 0, ptr %14, align 4
  br label %63

63:                                               ; preds = %62, %61
  call void @llvm.lifetime.end.p0(i64 40, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %64 = load i32, ptr %14, align 4
  switch i32 %64, label %69 [
    i32 0, label %65
    i32 1, label %67
  ]

65:                                               ; preds = %63
  br label %66

66:                                               ; preds = %65, %42, %36
  store i32 0, ptr %6, align 4
  br label %67

67:                                               ; preds = %66, %63
  %68 = load i32, ptr %6, align 4
  ret i32 %68

69:                                               ; preds = %63
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS23VmaAllocationCreateInfo", !10, i64 0, !15, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24, !6, i64 32, !16, i64 40}
!15 = !{!"_ZTS14VmaMemoryUsage", !7, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!18, !10, i64 0}
!18 = !{!"_ZTS12VkMemoryType", !10, i64 0, !10, i64 4}
!19 = !{!20, !12, i64 24}
!20 = !{!"_ZTS9VmaBudget", !21, i64 0, !12, i64 24, !12, i64 32}
!21 = !{!"_ZTS13VmaStatistics", !10, i64 0, !10, i64 4, !12, i64 8, !12, i64 16}
!22 = !{!20, !12, i64 32}


; 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.VmaBudget = type { %struct.VmaStatistics, i64, i64 }
%struct.VmaStatistics = type { i32, i32, i64, i64 }
%struct.VkMemoryType = type { i32, i32 }

; 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 nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK14VmaAllocator_T26MemoryTypeIndexToHeapIndexEj(ptr noundef nonnull align 8 dereferenceable(5916), i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14VmaAllocator_T14GetHeapBudgetsEP9VmaBudgetjj(ptr noundef nonnull align 8 dereferenceable(5916), ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -2, 1) i32 @_ZN14VmaAllocator_T17CalcMemTypeParamsER23VmaAllocationCreateInfojmm(ptr noundef nonnull align 8 dereferenceable(5916) %0, ptr nocapture noundef nonnull align 8 dereferenceable(48) %1, i32 noundef %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #3 align 2 {
  %6 = alloca %struct.VmaBudget, align 8
  %7 = load i32, ptr %1, align 8, !tbaa !5
  %8 = and i32 %7, 4
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %18, label %9

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 1036
  %11 = zext i32 %2 to i64
  %12 = getelementptr inbounds [32 x %struct.VkMemoryType], ptr %10, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = and i32 %13, 2
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %9
  %17 = and i32 %7, -5
  store i32 %17, ptr %1, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %16, %9, %5
  %19 = phi i32 [ %17, %16 ], [ %7, %9 ], [ %7, %5 ]
  %20 = and i32 %19, 257
  %or.cond.not = icmp eq i32 %20, 257
  br i1 %or.cond.not, label %21, label %29

21:                                               ; preds = %18
  %22 = tail call noundef i32 @_ZNK14VmaAllocator_T26MemoryTypeIndexToHeapIndexEj(ptr noundef nonnull align 8 dereferenceable(5916) %0, i32 noundef %2)
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %6) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %6, i8 0, i64 40, i1 false)
  call void @_ZN14VmaAllocator_T14GetHeapBudgetsEP9VmaBudgetjj(ptr noundef nonnull align 8 dereferenceable(5916) %0, ptr noundef nonnull %6, i32 noundef %22, i32 noundef 1)
  %23 = getelementptr inbounds i8, ptr %6, i64 24
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = mul i64 %4, %3
  %26 = add i64 %24, %25
  %27 = getelementptr inbounds i8, ptr %6, i64 32
  %28 = load i64, ptr %27, align 8, !tbaa !19
  %.not14 = icmp ugt i64 %26, %28
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %6) #4
  br i1 %.not14, label %30, label %29

29:                                               ; preds = %21, %18
  br label %30

30:                                               ; preds = %21, %29
  %.1 = phi i32 [ -2, %21 ], [ 0, %29 ]
  ret i32 %.1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTS23VmaAllocationCreateInfo", !7, i64 0, !10, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !11, i64 24, !11, i64 32, !12, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS14VmaMemoryUsage", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"float", !8, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"_ZTS12VkMemoryType", !7, i64 0, !7, i64 4}
!15 = !{!16, !18, i64 24}
!16 = !{!"_ZTS9VmaBudget", !17, i64 0, !18, i64 24, !18, i64 32}
!17 = !{!"_ZTS13VmaStatistics", !7, i64 0, !7, i64 4, !18, i64 8, !18, i64 16}
!18 = !{!"long", !8, i64 0}
!19 = !{!16, !18, i64 32}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass