; 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: inlinehint mustprogress nounwind uwtable
declare hidden noundef i64 @_ZL10VmaAlignUpImET_S0_S0_(i64 noundef, i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK30VmaBlockBufferImageGranularity23CheckConflictAndAlignUpERmmmm20VmaSuballocationType(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i32 noundef %5) #3 align 2 {
  %7 = alloca i1, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i64 %2, ptr %10, align 8, !tbaa !9
  store i64 %3, ptr %11, align 8, !tbaa !9
  store i64 %4, ptr %12, align 8, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !11
  %17 = load ptr, ptr %8, align 8
  %18 = call noundef zeroext i1 @_ZNK30VmaBlockBufferImageGranularity9IsEnabledEv(ptr noundef nonnull align 8 dereferenceable(24) %17)
  br i1 %18, label %19, label %97

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

32:                                               ; preds = %19
  %33 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %17, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = load i32, ptr %14, align 4, !tbaa !13
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %34, i64 %36
  %38 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %37, i32 0, i32 0
  %39 = load i8, ptr %38, align 2, !tbaa !20
  %40 = zext i8 %39 to i32
  %41 = load i32, ptr %13, align 4, !tbaa !11
  %42 = call noundef zeroext i1 @_ZL35VmaIsBufferImageGranularityConflict20VmaSuballocationTypeS_(i32 noundef %40, i32 noundef %41)
  br i1 %42, label %43, label %62

43:                                               ; preds = %32
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %17, i32 0, i32 0
  %47 = load i64, ptr %46, align 8, !tbaa !21
  %48 = call noundef i64 @_ZL10VmaAlignUpImET_S0_S0_(i64 noundef %45, i64 noundef %47)
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %48, ptr %49, align 8, !tbaa !9
  %50 = load i64, ptr %12, align 8, !tbaa !9
  %51 = load i64, ptr %10, align 8, !tbaa !9
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load i64, ptr %52, align 8, !tbaa !9
  %54 = add i64 %51, %53
  %55 = load i64, ptr %11, align 8, !tbaa !9
  %56 = sub i64 %54, %55
  %57 = icmp ult i64 %50, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %43
  store i1 true, ptr %7, align 1
  store i32 1, ptr %15, align 4
  br label %94

59:                                               ; preds = %43
  %60 = load i32, ptr %14, align 4, !tbaa !13
  %61 = add i32 %60, 1
  store i32 %61, ptr %14, align 4, !tbaa !13
  br label %62

62:                                               ; preds = %59, %32, %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = load i64, ptr %63, align 8, !tbaa !9
  %65 = load i64, ptr %10, align 8, !tbaa !9
  %66 = call noundef i32 @_ZNK30VmaBlockBufferImageGranularity10GetEndPageEmm(ptr noundef nonnull align 8 dereferenceable(24) %17, i64 noundef %64, i64 noundef %65)
  store i32 %66, ptr %16, align 4, !tbaa !13
  %67 = load i32, ptr %16, align 4, !tbaa !13
  %68 = load i32, ptr %14, align 4, !tbaa !13
  %69 = icmp ne i32 %67, %68
  br i1 %69, label %70, label %92

70:                                               ; preds = %62
  %71 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %17, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !15
  %73 = load i32, ptr %16, align 4, !tbaa !13
  %74 = zext i32 %73 to i64
  %75 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %72, i64 %74
  %76 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %75, i32 0, i32 1
  %77 = load i16, ptr %76, align 2, !tbaa !17
  %78 = zext i16 %77 to i32
  %79 = icmp sgt i32 %78, 0
  br i1 %79, label %80, label %92

80:                                               ; preds = %70
  %81 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %17, i32 0, i32 2
  %82 = load ptr, ptr %81, align 8, !tbaa !15
  %83 = load i32, ptr %16, align 4, !tbaa !13
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %82, i64 %84
  %86 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %85, i32 0, i32 0
  %87 = load i8, ptr %86, align 2, !tbaa !20
  %88 = zext i8 %87 to i32
  %89 = load i32, ptr %13, align 4, !tbaa !11
  %90 = call noundef zeroext i1 @_ZL35VmaIsBufferImageGranularityConflict20VmaSuballocationTypeS_(i32 noundef %88, i32 noundef %89)
  br i1 %90, label %91, label %92

91:                                               ; preds = %80
  store i1 true, ptr %7, align 1
  store i32 1, ptr %15, align 4
  br label %93

92:                                               ; preds = %80, %70, %62
  store i32 0, ptr %15, align 4
  br label %93

93:                                               ; preds = %92, %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %94

94:                                               ; preds = %93, %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %95 = load i32, ptr %15, align 4
  switch i32 %95, label %100 [
    i32 0, label %96
    i32 1, label %98
  ]

96:                                               ; preds = %94
  br label %97

97:                                               ; preds = %96, %6
  store i1 false, ptr %7, align 1
  br label %98

98:                                               ; preds = %97, %94
  %99 = load i1, ptr %7, align 1
  ret i1 %99

100:                                              ; preds = %94
  unreachable
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL35VmaIsBufferImageGranularityConflict20VmaSuballocationTypeS_(i32 noundef, i32 noundef) #2

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

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 = { 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 #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 = { 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 = !{!"_ZTS20VmaSuballocationType", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 16}
!16 = !{!"_ZTS30VmaBlockBufferImageGranularity", !10, i64 0, !14, i64 8, !6, i64 16}
!17 = !{!18, !19, i64 2}
!18 = !{!"_ZTSN30VmaBlockBufferImageGranularity10RegionInfoE", !7, i64 0, !19, i64 2}
!19 = !{!"short", !7, i64 0}
!20 = !{!18, !7, i64 0}
!21 = !{!16, !10, 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: inlinehint mustprogress nounwind uwtable
declare hidden noundef i64 @_ZL10VmaAlignUpImET_S0_S0_(i64 noundef, i64 noundef) local_unnamed_addr #1

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

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

._crit_edge:                                      ; preds = %8
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  br label %29

17:                                               ; preds = %8
  %18 = load i8, ptr %14, align 2, !tbaa !16
  %19 = zext i8 %18 to i32
  %20 = tail call noundef zeroext i1 @_ZL35VmaIsBufferImageGranularityConflict20VmaSuballocationTypeS_(i32 noundef %19, i32 noundef %5)
  %.pre27 = load i64, ptr %1, align 8, !tbaa !5
  br i1 %20, label %21, label %29

21:                                               ; preds = %17
  %22 = load i64, ptr %0, align 8, !tbaa !17
  %23 = tail call noundef i64 @_ZL10VmaAlignUpImET_S0_S0_(i64 noundef %.pre27, i64 noundef %22)
  store i64 %23, ptr %1, align 8, !tbaa !5
  %24 = sub i64 %2, %3
  %25 = add i64 %24, %23
  %26 = icmp ugt i64 %25, %4
  br i1 %26, label %.thread, label %27

27:                                               ; preds = %21
  %28 = add i32 %10, 1
  br label %29

29:                                               ; preds = %._crit_edge, %27, %17
  %30 = phi i64 [ %23, %27 ], [ %.pre27, %17 ], [ %.pre, %._crit_edge ]
  %.022 = phi i32 [ %28, %27 ], [ %10, %17 ], [ %10, %._crit_edge ]
  %31 = tail call noundef i32 @_ZNK30VmaBlockBufferImageGranularity10GetEndPageEmm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %30, i64 noundef %2)
  %.not23 = icmp eq i32 %31, %.022
  br i1 %.not23, label %42, label %32

32:                                               ; preds = %29
  %33 = load ptr, ptr %11, align 8, !tbaa !9
  %34 = zext i32 %31 to i64
  %35 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %33, i64 %34
  %36 = getelementptr inbounds i8, ptr %35, i64 2
  %37 = load i16, ptr %36, align 2, !tbaa !13
  %.not24 = icmp eq i16 %37, 0
  br i1 %.not24, label %42, label %38

38:                                               ; preds = %32
  %39 = load i8, ptr %35, align 2, !tbaa !16
  %40 = zext i8 %39 to i32
  %41 = tail call noundef zeroext i1 @_ZL35VmaIsBufferImageGranularityConflict20VmaSuballocationTypeS_(i32 noundef %40, i32 noundef %5)
  br i1 %41, label %.thread, label %42

.thread:                                          ; preds = %21, %38
  br label %42

42:                                               ; preds = %6, %29, %32, %38, %.thread
  %.2 = phi i1 [ true, %.thread ], [ false, %38 ], [ false, %32 ], [ false, %29 ], [ false, %6 ]
  ret i1 %.2
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL35VmaIsBufferImageGranularityConflict20VmaSuballocationTypeS_(i32 noundef, i32 noundef) local_unnamed_addr #1

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

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

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 16}
!10 = !{!"_ZTS30VmaBlockBufferImageGranularity", !6, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !15, i64 2}
!14 = !{!"_ZTSN30VmaBlockBufferImageGranularity10RegionInfoE", !7, i64 0, !15, i64 2}
!15 = !{!"short", !7, i64 0}
!16 = !{!14, !7, i64 0}
!17 = !{!10, !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass