; 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 }
%struct.VmaVirtualBlock_T = type { i8, %struct.VkAllocationCallbacks, ptr }
%struct.VkAllocationCallbacks = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct.VmaVirtualAllocationCreateInfo = type { i64, i64, i32, 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

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

42:                                               ; preds = %4
  %43 = getelementptr inbounds %struct.VmaVirtualBlock_T, ptr %13, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.VmaVirtualAllocationCreateInfo, ptr %45, i32 0, i32 3
  %47 = load ptr, ptr %46, align 8, !tbaa !29
  %48 = load ptr, ptr %44, align 8, !tbaa !27
  %49 = getelementptr inbounds ptr, ptr %48, i64 19
  %50 = load ptr, ptr %49, align 8
  call void %50(ptr noundef nonnull align 8 dereferenceable(33) %44, ptr noundef nonnull align 8 dereferenceable(52) %10, i32 noundef 1, ptr noundef %47)
  %51 = getelementptr inbounds %struct.VmaAllocationRequest, ptr %10, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %52, ptr %53, align 8, !tbaa !5
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %66

56:                                               ; preds = %42
  %57 = getelementptr inbounds %struct.VmaVirtualBlock_T, ptr %13, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !18
  %59 = getelementptr inbounds %struct.VmaAllocationRequest, ptr %10, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = load ptr, ptr %58, align 8, !tbaa !27
  %62 = getelementptr inbounds ptr, ptr %61, i64 9
  %63 = load ptr, ptr %62, align 8
  %64 = call noundef i64 %63(ptr noundef nonnull align 8 dereferenceable(33) %58, ptr noundef %60)
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %64, ptr %65, align 8, !tbaa !25
  br label %66

66:                                               ; preds = %56, %42
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %74

67:                                               ; preds = %4
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %68, align 8, !tbaa !5
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %73

71:                                               ; preds = %67
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 -1, ptr %72, align 8, !tbaa !25
  br label %73

73:                                               ; preds = %71, %67
  store i32 -2, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %74

74:                                               ; preds = %73, %66
  call void @llvm.lifetime.end.p0(i64 56, ptr %10) #4
  %75 = load i32, ptr %5, align 4
  ret i32 %75
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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, !6, i64 0}
!10 = !{!"_ZTS20VmaAllocationRequest", !6, i64 0, !11, i64 8, !12, i64 16, !6, i64 32, !11, i64 40, !13, i64 48}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTSN7VmaListI16VmaSuballocation15VmaStlAllocatorIS0_EE8iteratorE", !6, i64 0, !6, i64 8}
!13 = !{!"_ZTS24VmaAllocationRequestType", !7, i64 0}
!14 = !{!10, !11, i64 8}
!15 = !{!10, !6, i64 32}
!16 = !{!10, !11, i64 40}
!17 = !{!10, !13, i64 48}
!18 = !{!19, !6, i64 56}
!19 = !{!"_ZTS17VmaVirtualBlock_T", !20, i64 0, !21, i64 8, !6, i64 56}
!20 = !{!"bool", !7, i64 0}
!21 = !{!"_ZTS21VkAllocationCallbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!22 = !{!23, !11, i64 0}
!23 = !{!"_ZTS30VmaVirtualAllocationCreateInfo", !11, i64 0, !11, i64 8, !24, i64 16, !6, i64 24}
!24 = !{!"int", !7, i64 0}
!25 = !{!11, !11, i64 0}
!26 = !{!23, !24, i64 16}
!27 = !{!28, !28, i64 0}
!28 = !{!"vtable pointer", !8, i64 0}
!29 = !{!23, !6, i64 24}


; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

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

24:                                               ; preds = %4
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %1, i64 24
  %27 = load ptr, ptr %26, align 8, !tbaa !20
  %28 = load ptr, ptr %25, align 8, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %28, i64 152
  %30 = load ptr, ptr %29, align 8
  call void %30(ptr noundef nonnull align 8 dereferenceable(33) %25, ptr noundef nonnull align 8 dereferenceable(52) %5, i32 noundef 1, ptr noundef %27)
  %31 = load ptr, ptr %5, align 8, !tbaa !21
  store ptr %31, ptr %2, align 8, !tbaa !25
  %.not13 = icmp eq ptr %3, null
  br i1 %.not13, label %39, label %32

32:                                               ; preds = %24
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %33, align 8, !tbaa !18
  %35 = getelementptr inbounds i8, ptr %34, i64 72
  %36 = load ptr, ptr %35, align 8
  %37 = call noundef i64 %36(ptr noundef nonnull align 8 dereferenceable(33) %33, ptr noundef %31)
  br label %.sink.split

38:                                               ; preds = %4
  store ptr null, ptr %2, align 8, !tbaa !25
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %39, label %.sink.split

.sink.split:                                      ; preds = %38, %32
  %.sink = phi i64 [ %37, %32 ], [ -1, %38 ]
  %.0.ph = phi i32 [ 0, %32 ], [ -2, %38 ]
  store i64 %.sink, ptr %3, align 8, !tbaa !16
  br label %39

39:                                               ; preds = %.sink.split, %38, %24
  %.0 = phi i32 [ 0, %24 ], [ -2, %38 ], [ %.0.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %5) #5
  ret i32 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7VmaListI16VmaSuballocation15VmaStlAllocatorIS0_EE8iteratorC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) 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 = { inlinehint 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 = { 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, !11, i64 56}
!6 = !{!"_ZTS17VmaVirtualBlock_T", !7, i64 0, !10, i64 8, !11, i64 56}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS21VkAllocationCallbacks", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"_ZTS30VmaVirtualAllocationCreateInfo", !14, i64 0, !14, i64 8, !15, i64 16, !11, i64 24}
!14 = !{!"long", !8, i64 0}
!15 = !{!"int", !8, i64 0}
!16 = !{!14, !14, i64 0}
!17 = !{!13, !15, i64 16}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !9, i64 0}
!20 = !{!13, !11, i64 24}
!21 = !{!22, !11, i64 0}
!22 = !{!"_ZTS20VmaAllocationRequest", !11, i64 0, !14, i64 8, !23, i64 16, !11, i64 32, !14, i64 40, !24, i64 48}
!23 = !{!"_ZTSN7VmaListI16VmaSuballocation15VmaStlAllocatorIS0_EE8iteratorE", !11, i64 0, !11, i64 8}
!24 = !{!"_ZTS24VmaAllocationRequestType", !8, i64 0}
!25 = !{!11, !11, i64 0}


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