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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN27VmaDefragmentationContext_T13CheckCountersEm(ptr noundef nonnull align 8 dereferenceable(168) %0, i64 noundef %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %6 = load ptr, ptr %4, align 8
  %7 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %6, i32 0, i32 2
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %18

10:                                               ; preds = %2
  %11 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %6, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %6, i32 0, i32 3
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = call noundef i32 %12(ptr noundef %14)
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %10
  store i32 2, ptr %3, align 4
  br label %38

18:                                               ; preds = %10, %2
  %19 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %6, i32 0, i32 13
  %20 = getelementptr inbounds %struct.VmaDefragmentationStats, ptr %19, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !18
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = add i64 %21, %22
  %24 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %6, i32 0, i32 0
  %25 = load i64, ptr %24, align 8, !tbaa !19
  %26 = icmp ugt i64 %23, %25
  br i1 %26, label %27, label %35

27:                                               ; preds = %18
  %28 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %6, i32 0, i32 6
  %29 = load i8, ptr %28, align 8, !tbaa !20
  %30 = add i8 %29, 1
  store i8 %30, ptr %28, align 8, !tbaa !20
  %31 = zext i8 %30 to i32
  %32 = icmp slt i32 %31, 16
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  store i32 1, ptr %3, align 4
  br label %38

34:                                               ; preds = %27
  store i32 2, ptr %3, align 4
  br label %38

35:                                               ; preds = %18
  %36 = getelementptr inbounds %struct.VmaDefragmentationContext_T, ptr %6, i32 0, i32 6
  store i8 0, ptr %36, align 8, !tbaa !20
  br label %37

37:                                               ; preds = %35
  store i32 0, ptr %3, align 4
  br label %38

38:                                               ; preds = %37, %34, %33, %17
  %39 = load i32, ptr %3, align 4
  ret i32 %39
}

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" }

!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 16}
!12 = !{!"_ZTS27VmaDefragmentationContext_T", !10, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !15, i64 40, !7, i64 72, !13, i64 76, !13, i64 80, !6, i64 88, !6, i64 96, !10, i64 104, !16, i64 112, !16, i64 136, !6, i64 160}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS15VmaStlAllocatorI22VmaDefragmentationMoveE", !6, i64 0}
!15 = !{!"_ZTS9VmaVectorI22VmaDefragmentationMove15VmaStlAllocatorIS0_EE", !14, i64 0, !6, i64 8, !10, i64 16, !10, i64 24}
!16 = !{!"_ZTS23VmaDefragmentationStats", !10, i64 0, !10, i64 8, !13, i64 16, !13, i64 20}
!17 = !{!12, !6, i64 24}
!18 = !{!12, !10, i64 136}
!19 = !{!12, !10, i64 0}
!20 = !{!12, !7, i64 72}


; 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
define dso_local noundef range(i32 0, 3) i32 @_ZN27VmaDefragmentationContext_T13CheckCountersEm(ptr nocapture noundef nonnull align 8 dereferenceable(168) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %9, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %8 = tail call noundef i32 %4(ptr noundef %7)
  %.not3 = icmp eq i32 %8, 0
  br i1 %.not3, label %9, label %21

9:                                                ; preds = %5, %2
  %10 = getelementptr inbounds i8, ptr %0, i64 136
  %11 = load i64, ptr %10, align 8, !tbaa !16
  %12 = add i64 %11, %1
  %13 = load i64, ptr %0, align 8, !tbaa !17
  %14 = icmp ugt i64 %12, %13
  %15 = getelementptr inbounds i8, ptr %0, i64 72
  br i1 %14, label %16, label %20

16:                                               ; preds = %9
  %17 = load i8, ptr %15, align 8, !tbaa !18
  %18 = add i8 %17, 1
  store i8 %18, ptr %15, align 8, !tbaa !18
  %19 = icmp ult i8 %18, 16
  %. = select i1 %19, i32 1, i32 2
  br label %21

20:                                               ; preds = %9
  store i8 0, ptr %15, align 8, !tbaa !18
  br label %21

21:                                               ; preds = %16, %5, %20
  %.0 = phi i32 [ 0, %20 ], [ 2, %5 ], [ %., %16 ]
  ret i32 %.0
}

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" }

!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 16}
!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, !11, i64 24}
!16 = !{!6, !7, i64 136}
!17 = !{!6, !7, i64 0}
!18 = !{!6, !8, i64 72}


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