; 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.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 }
%"struct.VmaDefragmentationContext_T::MoveAllocationData" = type { i64, i64, i32, i32, %struct.VmaDefragmentationMove }
%struct.VmaDefragmentationMove = type { i32, ptr, ptr }
%struct.VmaDefragmentationContext_T = type { i64, i32, ptr, ptr, %struct.VmaStlAllocator.17, %class.VmaVector.18, i8, i32, i32, ptr, ptr, i64, %struct.VmaDefragmentationStats, %struct.VmaDefragmentationStats, ptr }
%struct.VmaStlAllocator.17 = type { ptr }
%class.VmaVector.18 = type { %struct.VmaStlAllocator.17, ptr, i64, i64 }
%struct.VmaDefragmentationStats = type { i64, i64, 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 uwtable
declare dso_local noundef i32 @_ZN14VmaBlockVector17AllocateFromBlockEP20VmaDeviceMemoryBlockmmjPv20VmaSuballocationTypejPP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(181), ptr noundef, i64 noundef, i64 noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK14VmaBlockVector8GetBlockEm(ptr noundef nonnull align 8 dereferenceable(181), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN27VmaDefragmentationContext_T17IncrementCountersEm(ptr noundef nonnull align 8 dereferenceable(168), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9VmaVectorI22VmaDefragmentationMove15VmaStlAllocatorIS0_EE9push_backERKS0_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN27VmaDefragmentationContext_T17AllocInOtherBlockEmmRNS_18MoveAllocationDataER14VmaBlockVector(ptr noundef nonnull align 8 dereferenceable(168) %0, i64 noundef %1, i64 noundef %2, ptr noundef nonnull align 8 dereferenceable(48) %3, ptr noundef nonnull align 8 dereferenceable(181) %4) #1 align 2 {
  %6 = alloca i1, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8
  br label %15

15:                                               ; preds = %69, %5
  %16 = load i64, ptr %8, align 8, !tbaa !9
  %17 = load i64, ptr %9, align 8, !tbaa !9
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %19, label %72

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %20 = load ptr, ptr %11, align 8, !tbaa !5
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = call noundef ptr @_ZNK14VmaBlockVector8GetBlockEm(ptr noundef nonnull align 8 dereferenceable(181) %20, i64 noundef %21)
  store ptr %22, ptr %12, align 8, !tbaa !5
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  %24 = getelementptr inbounds %class.VmaDeviceMemoryBlock, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = load ptr, ptr %25, align 8, !tbaa !18
  %27 = getelementptr inbounds ptr, ptr %26, i64 6
  %28 = load ptr, ptr %27, align 8
  %29 = call noundef i64 %28(ptr noundef nonnull align 8 dereferenceable(33) %25)
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.VmaDefragmentationContext_T::MoveAllocationData", ptr %30, i32 0, i32 0
  %32 = load i64, ptr %31, align 8, !tbaa !20
  %33 = icmp uge i64 %29, %32
  br i1 %33, label %34, label %65

34:                                               ; preds = %19
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.VmaDefragmentationContext_T::MoveAllocationData", ptr %37, i32 0, i32 0
  %39 = load i64, ptr %38, align 8, !tbaa !20
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.VmaDefragmentationContext_T::MoveAllocationData", ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !25
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.VmaDefragmentationContext_T::MoveAllocationData", ptr %43, i32 0, i32 3
  %45 = load i32, ptr %44, align 4, !tbaa !26
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.VmaDefragmentationContext_T::MoveAllocationData", ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 8, !tbaa !27
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %"struct.VmaDefragmentationContext_T::MoveAllocationData", ptr %49, i32 0, i32 4
  %51 = getelementptr inbounds %struct.VmaDefragmentationMove, ptr %50, i32 0, i32 2
  %52 = call noundef i32 @_ZN14VmaBlockVector17AllocateFromBlockEP20VmaDeviceMemoryBlockmmjPv20VmaSuballocationTypejPP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(181) %35, ptr noundef %36, i64 noundef %39, i64 noundef %42, i32 noundef %45, ptr noundef %14, i32 noundef %48, i32 noundef 0, ptr noundef %51)
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %64

54:                                               ; preds = %34
  %55 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %14, i32 0, i32 5
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %"struct.VmaDefragmentationContext_T::MoveAllocationData", ptr %56, i32 0, i32 4
  call void @_ZN9VmaVectorI22VmaDefragmentationMove15VmaStlAllocatorIS0_EE9push_backERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %55, ptr noundef nonnull align 8 dereferenceable(24) %57)
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds %"struct.VmaDefragmentationContext_T::MoveAllocationData", ptr %58, i32 0, i32 0
  %60 = load i64, ptr %59, align 8, !tbaa !20
  %61 = call noundef zeroext i1 @_ZN27VmaDefragmentationContext_T17IncrementCountersEm(ptr noundef nonnull align 8 dereferenceable(168) %14, i64 noundef %60)
  br i1 %61, label %62, label %63

62:                                               ; preds = %54
  store i1 true, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %66

63:                                               ; preds = %54
  store i32 2, ptr %13, align 4
  br label %66

64:                                               ; preds = %34
  br label %65

65:                                               ; preds = %64, %19
  store i32 0, ptr %13, align 4
  br label %66

66:                                               ; preds = %65, %63, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %67 = load i32, ptr %13, align 4
  switch i32 %67, label %75 [
    i32 0, label %68
    i32 1, label %73
    i32 2, label %72
  ]

68:                                               ; preds = %66
  br label %69

69:                                               ; preds = %68
  %70 = load i64, ptr %8, align 8, !tbaa !9
  %71 = add i64 %70, 1
  store i64 %71, ptr %8, align 8, !tbaa !9
  br label %15, !llvm.loop !28

72:                                               ; preds = %66, %15
  store i1 false, ptr %6, align 1
  br label %73

73:                                               ; preds = %72, %66
  %74 = load i1, ptr %6, align 1
  ret i1 %74

75:                                               ; preds = %66
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { 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, !6, i64 0}
!12 = !{!"_ZTS20VmaDeviceMemoryBlock", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 20, !6, i64 24, !14, i64 32, !17, i64 72, !13, i64 84, !6, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS8VmaMutex", !15, i64 0}
!15 = !{!"_ZTSSt5mutex", !16, i64 0}
!16 = !{!"_ZTSSt12__mutex_base", !7, i64 0}
!17 = !{!"_ZTS20VmaMappingHysteresis", !13, i64 0, !13, i64 4, !13, i64 8}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !8, i64 0}
!20 = !{!21, !10, i64 0}
!21 = !{!"_ZTSN27VmaDefragmentationContext_T18MoveAllocationDataE", !10, i64 0, !10, i64 8, !22, i64 16, !13, i64 20, !23, i64 24}
!22 = !{!"_ZTS20VmaSuballocationType", !7, i64 0}
!23 = !{!"_ZTS22VmaDefragmentationMove", !24, i64 0, !6, i64 8, !6, i64 16}
!24 = !{!"_ZTS31VmaDefragmentationMoveOperation", !7, i64 0}
!25 = !{!21, !10, i64 8}
!26 = !{!21, !13, i64 20}
!27 = !{!21, !22, i64 16}
!28 = distinct !{!28, !29}
!29 = !{!"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 uwtable
declare dso_local noundef i32 @_ZN14VmaBlockVector17AllocateFromBlockEP20VmaDeviceMemoryBlockmmjPv20VmaSuballocationTypejPP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(181), ptr noundef, i64 noundef, i64 noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN27VmaDefragmentationContext_T17IncrementCountersEm(ptr noundef nonnull align 8 dereferenceable(168), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9VmaVectorI22VmaDefragmentationMove15VmaStlAllocatorIS0_EE9push_backERKS0_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN27VmaDefragmentationContext_T17AllocInOtherBlockEmmRNS_18MoveAllocationDataER14VmaBlockVector(ptr noundef nonnull align 8 dereferenceable(168) %0, i64 noundef %1, i64 noundef %2, ptr noundef nonnull align 8 dereferenceable(48) %3, ptr noundef nonnull align 8 dereferenceable(181) %4) local_unnamed_addr #0 align 2 {
  %6 = icmp ult i64 %1, %2
  br i1 %6, label %.lr.ph, label %.thread22

.lr.ph:                                           ; preds = %5
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  %8 = getelementptr inbounds i8, ptr %3, i64 20
  %9 = getelementptr inbounds i8, ptr %3, i64 16
  %10 = getelementptr inbounds i8, ptr %3, i64 40
  br label %11

11:                                               ; preds = %.lr.ph, %30
  %.01924 = phi i64 [ %1, %.lr.ph ], [ %31, %30 ]
  %12 = tail call noundef ptr @_ZNK14VmaBlockVector8GetBlockEm(ptr noundef nonnull align 8 dereferenceable(181) %4, i64 noundef %.01924)
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %14, i64 48
  %16 = load ptr, ptr %15, align 8
  %17 = tail call noundef i64 %16(ptr noundef nonnull align 8 dereferenceable(33) %13)
  %18 = load i64, ptr %3, align 8, !tbaa !17
  %.not = icmp ult i64 %17, %18
  br i1 %.not, label %30, label %19

19:                                               ; preds = %11
  %20 = load i64, ptr %7, align 8, !tbaa !23
  %21 = load i32, ptr %8, align 4, !tbaa !24
  %22 = load i32, ptr %9, align 8, !tbaa !25
  %23 = tail call noundef i32 @_ZN14VmaBlockVector17AllocateFromBlockEP20VmaDeviceMemoryBlockmmjPv20VmaSuballocationTypejPP15VmaAllocation_T(ptr noundef nonnull align 8 dereferenceable(181) %4, ptr noundef nonnull %12, i64 noundef %18, i64 noundef %20, i32 noundef %21, ptr noundef nonnull %0, i32 noundef %22, i32 noundef 0, ptr noundef nonnull %10)
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %19
  %26 = getelementptr inbounds i8, ptr %3, i64 24
  %27 = getelementptr inbounds i8, ptr %0, i64 40
  tail call void @_ZN9VmaVectorI22VmaDefragmentationMove15VmaStlAllocatorIS0_EE9push_backERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %27, ptr noundef nonnull align 8 dereferenceable(24) %26)
  %28 = load i64, ptr %3, align 8, !tbaa !17
  %29 = tail call noundef zeroext i1 @_ZN27VmaDefragmentationContext_T17IncrementCountersEm(ptr noundef nonnull align 8 dereferenceable(168) %0, i64 noundef %28)
  br label %.thread22

30:                                               ; preds = %19, %11
  %31 = add i64 %.01924, 1
  %exitcond.not = icmp eq i64 %31, %2
  br i1 %exitcond.not, label %.thread22, label %11, !llvm.loop !26

.thread22:                                        ; preds = %30, %5, %25
  %.2 = phi i1 [ %29, %25 ], [ false, %5 ], [ false, %30 ]
  ret i1 %.2
}

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

!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}
!17 = !{!18, !19, i64 0}
!18 = !{!"_ZTSN27VmaDefragmentationContext_T18MoveAllocationDataE", !19, i64 0, !19, i64 8, !20, i64 16, !10, i64 20, !21, i64 24}
!19 = !{!"long", !8, i64 0}
!20 = !{!"_ZTS20VmaSuballocationType", !8, i64 0}
!21 = !{!"_ZTS22VmaDefragmentationMove", !22, i64 0, !7, i64 8, !7, i64 16}
!22 = !{!"_ZTS31VmaDefragmentationMoveOperation", !8, i64 0}
!23 = !{!18, !19, i64 8}
!24 = !{!18, !10, i64 20}
!25 = !{!18, !20, i64 16}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}


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