; 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.VmaBlockBufferImageGranularity = type { i64, i32, ptr }
%"struct.VmaBlockBufferImageGranularity::RegionInfo" = type { i8, i16 }

; 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 noundef zeroext i1 @_ZNK30VmaBlockBufferImageGranularity9IsEnabledEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK30VmaBlockBufferImageGranularity12GetStartPageEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK30VmaBlockBufferImageGranularity10GetEndPageEmm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN30VmaBlockBufferImageGranularity9FreePagesEmm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1, i64 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = call noundef zeroext i1 @_ZNK30VmaBlockBufferImageGranularity9IsEnabledEv(ptr noundef nonnull align 8 dereferenceable(24) %9)
  br i1 %10, label %11, label %72

11:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = call noundef i32 @_ZNK30VmaBlockBufferImageGranularity12GetStartPageEm(ptr noundef nonnull align 8 dereferenceable(24) %9, i64 noundef %12)
  store i32 %13, ptr %7, align 4, !tbaa !11
  %14 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %9, i32 0, i32 2
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = load i32, ptr %7, align 4, !tbaa !11
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %15, i64 %17
  %19 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %18, i32 0, i32 1
  %20 = load i16, ptr %19, align 2, !tbaa !15
  %21 = add i16 %20, -1
  store i16 %21, ptr %19, align 2, !tbaa !15
  %22 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %9, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = load i32, ptr %7, align 4, !tbaa !11
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %23, i64 %25
  %27 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %26, i32 0, i32 1
  %28 = load i16, ptr %27, align 2, !tbaa !15
  %29 = zext i16 %28 to i32
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %38

31:                                               ; preds = %11
  %32 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %9, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load i32, ptr %7, align 4, !tbaa !11
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %33, i64 %35
  %37 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %36, i32 0, i32 0
  store i8 0, ptr %37, align 2, !tbaa !18
  br label %38

38:                                               ; preds = %31, %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = call noundef i32 @_ZNK30VmaBlockBufferImageGranularity10GetEndPageEmm(ptr noundef nonnull align 8 dereferenceable(24) %9, i64 noundef %39, i64 noundef %40)
  store i32 %41, ptr %8, align 4, !tbaa !11
  %42 = load i32, ptr %7, align 4, !tbaa !11
  %43 = load i32, ptr %8, align 4, !tbaa !11
  %44 = icmp ne i32 %42, %43
  br i1 %44, label %45, label %71

45:                                               ; preds = %38
  %46 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %9, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = load i32, ptr %8, align 4, !tbaa !11
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %47, i64 %49
  %51 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %50, i32 0, i32 1
  %52 = load i16, ptr %51, align 2, !tbaa !15
  %53 = add i16 %52, -1
  store i16 %53, ptr %51, align 2, !tbaa !15
  %54 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %9, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  %56 = load i32, ptr %8, align 4, !tbaa !11
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %55, i64 %57
  %59 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %58, i32 0, i32 1
  %60 = load i16, ptr %59, align 2, !tbaa !15
  %61 = zext i16 %60 to i32
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %70

63:                                               ; preds = %45
  %64 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %9, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !13
  %66 = load i32, ptr %8, align 4, !tbaa !11
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %65, i64 %67
  %69 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %68, i32 0, i32 0
  store i8 0, ptr %69, align 2, !tbaa !18
  br label %70

70:                                               ; preds = %63, %45
  br label %71

71:                                               ; preds = %70, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %72

72:                                               ; preds = %71, %3
  ret void
}

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, !6, i64 16}
!14 = !{!"_ZTS30VmaBlockBufferImageGranularity", !10, i64 0, !12, i64 8, !6, i64 16}
!15 = !{!16, !17, i64 2}
!16 = !{!"_ZTSN30VmaBlockBufferImageGranularity10RegionInfoE", !7, i64 0, !17, i64 2}
!17 = !{!"short", !7, i64 0}
!18 = !{!16, !7, 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.VmaBlockBufferImageGranularity::RegionInfo" = type { i8, i16 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK30VmaBlockBufferImageGranularity9IsEnabledEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK30VmaBlockBufferImageGranularity12GetStartPageEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK30VmaBlockBufferImageGranularity10GetEndPageEmm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN30VmaBlockBufferImageGranularity9FreePagesEmm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = tail call noundef zeroext i1 @_ZNK30VmaBlockBufferImageGranularity9IsEnabledEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  br i1 %4, label %5, label %27

5:                                                ; preds = %3
  %6 = tail call noundef i32 @_ZNK30VmaBlockBufferImageGranularity12GetStartPageEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1)
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = zext i32 %6 to i64
  %10 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %8, i64 %9, i32 1
  %11 = load i16, ptr %10, align 2, !tbaa !12
  %12 = add i16 %11, -1
  store i16 %12, ptr %10, align 2, !tbaa !12
  %13 = icmp eq i16 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %5
  %15 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %8, i64 %9
  store i8 0, ptr %15, align 2, !tbaa !15
  br label %16

16:                                               ; preds = %14, %5
  %17 = tail call noundef i32 @_ZNK30VmaBlockBufferImageGranularity10GetEndPageEmm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1, i64 noundef %2)
  %.not = icmp eq i32 %6, %17
  br i1 %.not, label %27, label %18

18:                                               ; preds = %16
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = zext i32 %17 to i64
  %21 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %19, i64 %20, i32 1
  %22 = load i16, ptr %21, align 2, !tbaa !12
  %23 = add i16 %22, -1
  store i16 %23, ptr %21, align 2, !tbaa !12
  %24 = icmp eq i16 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %18
  %26 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %19, i64 %20
  store i8 0, ptr %26, align 2, !tbaa !15
  br label %27

27:                                               ; preds = %16, %25, %18, %3
  ret void
}

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

!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 = !{!"_ZTS30VmaBlockBufferImageGranularity", !7, i64 0, !10, i64 8, !11, i64 16}
!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 = !{!13, !14, i64 2}
!13 = !{!"_ZTSN30VmaBlockBufferImageGranularity10RegionInfoE", !8, i64 0, !14, i64 2}
!14 = !{!"short", !8, i64 0}
!15 = !{!13, !8, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass