; 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.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 }

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.57 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__._ZN27VmaDefragmentationContext_TD2Ev = external hidden unnamed_addr constant [60 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN14VmaBlockVector18SetIncrementalSortEb(ptr noundef nonnull align 8 dereferenceable(181), i1 noundef zeroext) #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN27VmaDefragmentationContext_TD2Ev(ptr noundef nonnull align 8 dereferenceable(168) %0) unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 9
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %13

9:                                                ; preds = %1
  %10 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 9
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  invoke void @_ZN14VmaBlockVector18SetIncrementalSortEb(ptr noundef nonnull align 8 dereferenceable(181) %11, i1 noundef zeroext true)
          to label %12 unwind label %68

12:                                               ; preds = %9
  br label %37

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !16
  br label %14

14:                                               ; preds = %33, %13
  %15 = load i32, ptr %3, align 4, !tbaa !16
  %16 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 8
  %17 = load i32, ptr %16, align 8, !tbaa !17
  %18 = icmp ult i32 %15, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %36

20:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %21 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 10
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = load i32, ptr %3, align 4, !tbaa !16
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds ptr, ptr %22, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %26, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %32

29:                                               ; preds = %20
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  invoke void @_ZN14VmaBlockVector18SetIncrementalSortEb(ptr noundef nonnull align 8 dereferenceable(181) %30, i1 noundef zeroext true)
          to label %31 unwind label %68

31:                                               ; preds = %29
  br label %32

32:                                               ; preds = %31, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %3, align 4, !tbaa !16
  %35 = add i32 %34, 1
  store i32 %35, ptr %3, align 4, !tbaa !16
  br label %14, !llvm.loop !19

36:                                               ; preds = %19
  br label %37

37:                                               ; preds = %36, %12
  %38 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 14
  %39 = load ptr, ptr %38, align 8, !tbaa !21
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %66

41:                                               ; preds = %37
  %42 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 7
  %43 = load i32, ptr %42, align 4, !tbaa !22
  switch i32 %43, label %64 [
    i32 2, label %44
    i32 8, label %54
  ]

44:                                               ; preds = %41
  %45 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 4
  %46 = getelementptr inbounds %struct.VmaStlAllocator.17, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !23
  %48 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 14
  %49 = load ptr, ptr %48, align 8, !tbaa !21
  %50 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 8
  %51 = load i32, ptr %50, align 8, !tbaa !17
  %52 = zext i32 %51 to i64
  invoke void @_ZL16vma_delete_arrayIN27VmaDefragmentationContext_T13StateBalancedEEvPK21VkAllocationCallbacksPT_m(ptr noundef %47, ptr noundef %49, i64 noundef %52)
          to label %53 unwind label %68

53:                                               ; preds = %44
  br label %65

54:                                               ; preds = %41
  %55 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 4
  %56 = getelementptr inbounds %struct.VmaStlAllocator.17, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !23
  %58 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 14
  %59 = load ptr, ptr %58, align 8, !tbaa !21
  %60 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 8
  %61 = load i32, ptr %60, align 8, !tbaa !17
  %62 = zext i32 %61 to i64
  invoke void @_ZL16vma_delete_arrayIN27VmaDefragmentationContext_T14StateExtensiveEEvPK21VkAllocationCallbacksPT_m(ptr noundef %57, ptr noundef %59, i64 noundef %62)
          to label %63 unwind label %68

63:                                               ; preds = %54
  br label %65

64:                                               ; preds = %41
  call void @__assert_fail(ptr noundef @.str.57, ptr noundef @.str.2, i32 noundef 13122, ptr noundef @__PRETTY_FUNCTION__._ZN27VmaDefragmentationContext_TD2Ev) #6
  unreachable

65:                                               ; preds = %63, %53
  br label %66

66:                                               ; preds = %65, %37
  %67 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %5, i32 0, i32 5
  call void @_ZN9VmaVectorI22VmaDefragmentationMove15VmaStlAllocatorIS0_EED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %67) #5
  ret void

68:                                               ; preds = %54, %44, %29, %9
  %69 = landingpad { ptr, i32 }
          catch ptr null
  %70 = extractvalue { ptr, i32 } %69, 0
  call void @__clang_call_terminate(ptr %70) #6
  unreachable
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL16vma_delete_arrayIN27VmaDefragmentationContext_T13StateBalancedEEvPK21VkAllocationCallbacksPT_m(ptr noundef, ptr noundef, i64 noundef) #4

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL16vma_delete_arrayIN27VmaDefragmentationContext_T14StateExtensiveEEvPK21VkAllocationCallbacksPT_m(ptr noundef, ptr noundef, i64 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 = { noinline noreturn nounwind uwtable "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 = { 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 #5 = { nounwind }
attributes #6 = { noreturn 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 88}
!10 = !{!"_ZTS27VmaDefragmentationContext_T", !11, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !14, i64 40, !7, i64 72, !12, i64 76, !12, i64 80, !6, i64 88, !6, i64 96, !11, i64 104, !15, i64 112, !15, i64 136, !6, i64 160}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTS15VmaStlAllocatorI22VmaDefragmentationMoveE", !6, i64 0}
!14 = !{!"_ZTS9VmaVectorI22VmaDefragmentationMove15VmaStlAllocatorIS0_EE", !13, i64 0, !6, i64 8, !11, i64 16, !11, i64 24}
!15 = !{!"_ZTS23VmaDefragmentationStats", !11, i64 0, !11, i64 8, !12, i64 16, !12, i64 20}
!16 = !{!12, !12, i64 0}
!17 = !{!10, !12, i64 80}
!18 = !{!10, !6, i64 96}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!10, !6, i64 160}
!22 = !{!10, !12, i64 76}
!23 = !{!10, !6, 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"

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.57 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__._ZN27VmaDefragmentationContext_TD2Ev = external hidden unnamed_addr constant [60 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN14VmaBlockVector18SetIncrementalSortEb(ptr noundef nonnull align 8 dereferenceable(181), i1 noundef zeroext) local_unnamed_addr #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN27VmaDefragmentationContext_TD2Ev(ptr noundef nonnull align 8 dereferenceable(168) %0) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 88
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.preheader, label %7

.preheader:                                       ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 80
  %5 = load i32, ptr %4, align 8, !tbaa !15
  %.not11 = icmp eq i32 %5, 0
  br i1 %.not11, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %6 = getelementptr inbounds i8, ptr %0, i64 96
  br label %8

7:                                                ; preds = %1
  tail call void @_ZN14VmaBlockVector18SetIncrementalSortEb(ptr noundef nonnull align 8 dereferenceable(181) %3, i1 noundef zeroext true)
  br label %.loopexit

8:                                                ; preds = %.lr.ph, %14
  %9 = phi i32 [ %5, %.lr.ph ], [ %15, %14 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %10 = load ptr, ptr %6, align 8, !tbaa !16
  %11 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv
  %12 = load ptr, ptr %11, align 8, !tbaa !17
  %.not8 = icmp eq ptr %12, null
  br i1 %.not8, label %14, label %13

13:                                               ; preds = %8
  tail call void @_ZN14VmaBlockVector18SetIncrementalSortEb(ptr noundef nonnull align 8 dereferenceable(181) %12, i1 noundef zeroext true)
  %.pre = load i32, ptr %4, align 8, !tbaa !15
  br label %14

14:                                               ; preds = %13, %8
  %15 = phi i32 [ %.pre, %13 ], [ %9, %8 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = zext i32 %15 to i64
  %17 = icmp ult i64 %indvars.iv.next, %16
  br i1 %17, label %8, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %14, %.preheader, %7
  %18 = getelementptr inbounds i8, ptr %0, i64 160
  %19 = load ptr, ptr %18, align 8, !tbaa !20
  %.not9 = icmp eq ptr %19, null
  br i1 %.not9, label %36, label %20

20:                                               ; preds = %.loopexit
  %21 = getelementptr inbounds i8, ptr %0, i64 76
  %22 = load i32, ptr %21, align 4, !tbaa !21
  switch i32 %22, label %35 [
    i32 2, label %23
    i32 8, label %29
  ]

23:                                               ; preds = %20
  %24 = getelementptr inbounds i8, ptr %0, i64 32
  %25 = load ptr, ptr %24, align 8, !tbaa !22
  %26 = getelementptr inbounds i8, ptr %0, i64 80
  %27 = load i32, ptr %26, align 8, !tbaa !15
  %28 = zext i32 %27 to i64
  invoke void @_ZL16vma_delete_arrayIN27VmaDefragmentationContext_T13StateBalancedEEvPK21VkAllocationCallbacksPT_m(ptr noundef %25, ptr noundef nonnull %19, i64 noundef %28)
          to label %36 unwind label %38

29:                                               ; preds = %20
  %30 = getelementptr inbounds i8, ptr %0, i64 32
  %31 = load ptr, ptr %30, align 8, !tbaa !22
  %32 = getelementptr inbounds i8, ptr %0, i64 80
  %33 = load i32, ptr %32, align 8, !tbaa !15
  %34 = zext i32 %33 to i64
  invoke void @_ZL16vma_delete_arrayIN27VmaDefragmentationContext_T14StateExtensiveEEvPK21VkAllocationCallbacksPT_m(ptr noundef %31, ptr noundef nonnull %19, i64 noundef %34)
          to label %36 unwind label %38

35:                                               ; preds = %20
  tail call void @__assert_fail(ptr noundef nonnull @.str.57, ptr noundef nonnull @.str.2, i32 noundef 13122, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN27VmaDefragmentationContext_TD2Ev) #4
  unreachable

36:                                               ; preds = %23, %29, %.loopexit
  %37 = getelementptr inbounds i8, ptr %0, i64 40
  tail call void @_ZN9VmaVectorI22VmaDefragmentationMove15VmaStlAllocatorIS0_EED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %37) #5
  ret void

38:                                               ; preds = %29, %23
  %39 = landingpad { ptr, i32 }
          catch ptr null
  %40 = extractvalue { ptr, i32 } %39, 0
  tail call void @__clang_call_terminate(ptr %40) #4
  unreachable
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL16vma_delete_arrayIN27VmaDefragmentationContext_T13StateBalancedEEvPK21VkAllocationCallbacksPT_m(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL16vma_delete_arrayIN27VmaDefragmentationContext_T14StateExtensiveEEvPK21VkAllocationCallbacksPT_m(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { noreturn nounwind "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 = { noinline noreturn nounwind uwtable "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 = { 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 = { noreturn nounwind }
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 88}
!6 = !{!"_ZTS27VmaDefragmentationContext_T", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !13, i64 40, !8, i64 72, !10, i64 76, !10, i64 80, !11, i64 88, !11, i64 96, !7, i64 104, !14, i64 112, !14, i64 136, !11, i64 160}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"_ZTS15VmaStlAllocatorI22VmaDefragmentationMoveE", !11, i64 0}
!13 = !{!"_ZTS9VmaVectorI22VmaDefragmentationMove15VmaStlAllocatorIS0_EE", !12, i64 0, !11, i64 8, !7, i64 16, !7, i64 24}
!14 = !{!"_ZTS23VmaDefragmentationStats", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20}
!15 = !{!6, !10, i64 80}
!16 = !{!6, !11, i64 96}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !11, i64 160}
!21 = !{!6, !10, i64 76}
!22 = !{!6, !11, i64 32}


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