; 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.VmaAllocationRequest = type <{ ptr, i64, %"class.VmaList<VmaSuballocation, VmaStlAllocator<VmaSuballocation>>::iterator", ptr, i64, i32, [4 x i8] }>
%"class.VmaList<VmaSuballocation, VmaStlAllocator<VmaSuballocation>>::iterator" = type { ptr, ptr }
%class.VmaDeviceMemoryBlock = type { ptr, ptr, i32, i32, ptr, %class.VmaMutex, %class.VmaMappingHysteresis, i32, ptr }
%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.VmaMappingHysteresis = type { i32, i32, i32 }

; 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 void @_ZN7VmaListI16VmaSuballocation15VmaStlAllocatorIS0_EE8iteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN14VmaBlockVector17AllocateFromBlockEP20VmaDeviceMemoryBlockmmjPv20VmaSuballocationTypejPP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(181) %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i32 noundef %4, ptr noundef %5, i32 noundef %6, i32 noundef %7, ptr noundef %8) #2 align 2 {
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  %20 = alloca i8, align 1
  %21 = alloca %struct.VmaAllocationRequest, align 8
  %22 = alloca i32, align 4
  store ptr %0, ptr %11, align 8, !tbaa !5
  store ptr %1, ptr %12, align 8, !tbaa !5
  store i64 %2, ptr %13, align 8, !tbaa !9
  store i64 %3, ptr %14, align 8, !tbaa !9
  store i32 %4, ptr %15, align 4, !tbaa !11
  store ptr %5, ptr %16, align 8, !tbaa !5
  store i32 %6, ptr %17, align 4, !tbaa !13
  store i32 %7, ptr %18, align 4, !tbaa !11
  store ptr %8, ptr %19, align 8, !tbaa !5
  %23 = load ptr, ptr %11, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %20) #3
  %24 = load i32, ptr %15, align 4, !tbaa !11
  %25 = and i32 %24, 64
  %26 = icmp ne i32 %25, 0
  %27 = zext i1 %26 to i8
  store i8 %27, ptr %20, align 1, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 56, ptr %21) #3
  %28 = getelementptr inbounds %struct.VmaAllocationRequest, ptr %21, i32 0, i32 0
  store ptr null, ptr %28, align 8, !tbaa !17
  %29 = getelementptr inbounds %struct.VmaAllocationRequest, ptr %21, i32 0, i32 1
  store i64 0, ptr %29, align 8, !tbaa !21
  %30 = getelementptr inbounds %struct.VmaAllocationRequest, ptr %21, i32 0, i32 2
  call void @_ZN7VmaListI16VmaSuballocation15VmaStlAllocatorIS0_EE8iteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %30)
  %31 = getelementptr inbounds %struct.VmaAllocationRequest, ptr %21, i32 0, i32 3
  store ptr null, ptr %31, align 8, !tbaa !22
  %32 = getelementptr inbounds %struct.VmaAllocationRequest, ptr %21, i32 0, i32 4
  store i64 0, ptr %32, align 8, !tbaa !23
  %33 = getelementptr inbounds %struct.VmaAllocationRequest, ptr %21, i32 0, i32 5
  store i32 0, ptr %33, align 8, !tbaa !24
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.VmaDeviceMemoryBlock, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !25
  %37 = load i64, ptr %13, align 8, !tbaa !9
  %38 = load i64, ptr %14, align 8, !tbaa !9
  %39 = load i8, ptr %20, align 1, !tbaa !15, !range !31, !noundef !32
  %40 = trunc i8 %39 to i1
  %41 = load i32, ptr %17, align 4, !tbaa !13
  %42 = load i32, ptr %18, align 4, !tbaa !11
  %43 = load ptr, ptr %36, align 8, !tbaa !33
  %44 = getelementptr inbounds ptr, ptr %43, i64 17
  %45 = load ptr, ptr %44, align 8
  %46 = call noundef zeroext i1 %45(ptr noundef nonnull align 8 dereferenceable(33) %36, i64 noundef %37, i64 noundef %38, i1 noundef zeroext %40, i32 noundef %41, i32 noundef %42, ptr noundef %21)
  br i1 %46, label %47, label %55

47:                                               ; preds = %9
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = load i64, ptr %14, align 8, !tbaa !9
  %50 = load i32, ptr %15, align 4, !tbaa !11
  %51 = load ptr, ptr %16, align 8, !tbaa !5
  %52 = load i32, ptr %17, align 4, !tbaa !13
  %53 = load ptr, ptr %19, align 8, !tbaa !5
  %54 = call noundef i32 @_ZN14VmaBlockVector23CommitAllocationRequestER20VmaAllocationRequestP20VmaDeviceMemoryBlockmjPv20VmaSuballocationTypePP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(181) %23, ptr noundef nonnull align 8 dereferenceable(52) %21, ptr noundef %48, i64 noundef %49, i32 noundef %50, ptr noundef %51, i32 noundef %52, ptr noundef %53)
  store i32 %54, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %56

55:                                               ; preds = %9
  store i32 -2, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %56

56:                                               ; preds = %55, %47
  call void @llvm.lifetime.end.p0(i64 56, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %20) #3
  %57 = load i32, ptr %10, align 4
  ret i32 %57
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN14VmaBlockVector23CommitAllocationRequestER20VmaAllocationRequestP20VmaDeviceMemoryBlockmjPv20VmaSuballocationTypePP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(181), ptr noundef nonnull align 8 dereferenceable(52), ptr noundef, i64 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) #2 align 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_ZTS20VmaSuballocationType", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!18, !6, i64 0}
!18 = !{!"_ZTS20VmaAllocationRequest", !6, i64 0, !10, i64 8, !19, i64 16, !6, i64 32, !10, i64 40, !20, i64 48}
!19 = !{!"_ZTSN7VmaListI16VmaSuballocation15VmaStlAllocatorIS0_EE8iteratorE", !6, i64 0, !6, i64 8}
!20 = !{!"_ZTS24VmaAllocationRequestType", !7, i64 0}
!21 = !{!18, !10, i64 8}
!22 = !{!18, !6, i64 32}
!23 = !{!18, !10, i64 40}
!24 = !{!18, !20, i64 48}
!25 = !{!26, !6, i64 0}
!26 = !{!"_ZTS20VmaDeviceMemoryBlock", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !6, i64 24, !27, i64 32, !30, i64 72, !12, i64 84, !6, i64 88}
!27 = !{!"_ZTS8VmaMutex", !28, i64 0}
!28 = !{!"_ZTSSt5mutex", !29, i64 0}
!29 = !{!"_ZTSSt12__mutex_base", !7, i64 0}
!30 = !{!"_ZTS20VmaMappingHysteresis", !12, i64 0, !12, i64 4, !12, i64 8}
!31 = !{i8 0, i8 2}
!32 = !{}
!33 = !{!34, !34, i64 0}
!34 = !{!"vtable pointer", !8, i64 0}


; 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.VmaAllocationRequest = type <{ ptr, i64, %"class.VmaList<VmaSuballocation, VmaStlAllocator<VmaSuballocation>>::iterator", ptr, i64, i32, [4 x i8] }>
%"class.VmaList<VmaSuballocation, VmaStlAllocator<VmaSuballocation>>::iterator" = type { ptr, 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 nounwind uwtable
declare dso_local void @_ZN7VmaListI16VmaSuballocation15VmaStlAllocatorIS0_EE8iteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN14VmaBlockVector17AllocateFromBlockEP20VmaDeviceMemoryBlockmmjPv20VmaSuballocationTypejPP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(181) %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i32 noundef %4, ptr noundef %5, i32 noundef %6, i32 noundef %7, ptr noundef %8) local_unnamed_addr #2 align 2 {
  %10 = alloca %struct.VmaAllocationRequest, align 8
  %11 = and i32 %4, 64
  %12 = icmp ne i32 %11, 0
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %10) #4
  %13 = getelementptr inbounds i8, ptr %10, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %10, i8 0, i64 16, i1 false)
  call void @_ZN7VmaListI16VmaSuballocation15VmaStlAllocatorIS0_EE8iteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %13)
  %14 = getelementptr inbounds i8, ptr %10, i64 32
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %14, i8 0, i64 20, i1 false)
  %15 = load ptr, ptr %1, align 8, !tbaa !5
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %16, i64 136
  %18 = load ptr, ptr %17, align 8
  %19 = call noundef zeroext i1 %18(ptr noundef nonnull align 8 dereferenceable(33) %15, i64 noundef %2, i64 noundef %3, i1 noundef zeroext %12, i32 noundef %6, i32 noundef %7, ptr noundef nonnull %10)
  br i1 %19, label %20, label %22

20:                                               ; preds = %9
  %21 = call noundef i32 @_ZN14VmaBlockVector23CommitAllocationRequestER20VmaAllocationRequestP20VmaDeviceMemoryBlockmjPv20VmaSuballocationTypePP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(181) %0, ptr noundef nonnull align 8 dereferenceable(52) %10, ptr noundef nonnull %1, i64 noundef %3, i32 noundef %4, ptr noundef %5, i32 noundef %6, ptr noundef %8)
  br label %22

22:                                               ; preds = %9, %20
  %.0 = phi i32 [ %21, %20 ], [ -2, %9 ]
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %10) #4
  ret i32 %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN14VmaBlockVector23CommitAllocationRequestER20VmaAllocationRequestP20VmaDeviceMemoryBlockmjPv20VmaSuballocationTypePP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(181), ptr noundef nonnull align 8 dereferenceable(52), ptr noundef, i64 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2 align 2

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"_ZTS20VmaDeviceMemoryBlock", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !7, i64 24, !11, i64 32, !14, i64 72, !10, i64 84, !7, i64 88}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTS8VmaMutex", !12, i64 0}
!12 = !{!"_ZTSSt5mutex", !13, i64 0}
!13 = !{!"_ZTSSt12__mutex_base", !8, i64 0}
!14 = !{!"_ZTS20VmaMappingHysteresis", !10, i64 0, !10, i64 4, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !9, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass