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

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [67 x i8], align 1
@__PRETTY_FUNCTION__._ZNK30VmaBlockBufferImageGranularity16FinishValidationERNS_17ValidationContextE = external hidden unnamed_addr constant [81 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [83 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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK30VmaBlockBufferImageGranularity16FinishValidationERNS_17ValidationContextE(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = call noundef zeroext i1 @_ZNK30VmaBlockBufferImageGranularity9IsEnabledEv(ptr noundef nonnull align 8 dereferenceable(24) %6)
  br i1 %7, label %8, label %64

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::ValidationContext", ptr %9, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %8
  br label %14

14:                                               ; preds = %13, %8
  %15 = phi i1 [ false, %8 ], [ true, %13 ]
  br i1 %15, label %16, label %17

16:                                               ; preds = %14
  br label %19

17:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str.38, ptr noundef @.str.2, i32 noundef 6814, ptr noundef @__PRETTY_FUNCTION__._ZNK30VmaBlockBufferImageGranularity16FinishValidationERNS_17ValidationContextE) #4
  unreachable

18:                                               ; No predecessors!
  br label %19

19:                                               ; preds = %18, %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %20

20:                                               ; preds = %49, %19
  %21 = load i32, ptr %5, align 4, !tbaa !11
  %22 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %6, i32 0, i32 1
  %23 = load i32, ptr %22, align 8, !tbaa !13
  %24 = icmp ult i32 %21, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %20
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::ValidationContext", ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = load i32, ptr %5, align 4, !tbaa !11
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds i16, ptr %30, i64 %32
  %34 = load i16, ptr %33, align 2, !tbaa !16
  %35 = zext i16 %34 to i32
  %36 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %6, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  %38 = load i32, ptr %5, align 4, !tbaa !11
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %37, i64 %39
  %41 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %40, i32 0, i32 1
  %42 = load i16, ptr %41, align 2, !tbaa !19
  %43 = zext i16 %42 to i32
  %44 = icmp eq i32 %35, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %27
  call void @__assert_fail(ptr noundef @.str.39, ptr noundef @.str.2, i32 noundef 6818, ptr noundef @__PRETTY_FUNCTION__._ZNK30VmaBlockBufferImageGranularity16FinishValidationERNS_17ValidationContextE) #4
  unreachable

46:                                               ; preds = %27
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %5, align 4, !tbaa !11
  %51 = add i32 %50, 1
  store i32 %51, ptr %5, align 4, !tbaa !11
  br label %20, !llvm.loop !21

52:                                               ; preds = %25
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::ValidationContext", ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !23
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::ValidationContext", ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  %59 = getelementptr inbounds %class.VmaBlockBufferImageGranularity, ptr %6, i32 0, i32 1
  %60 = load i32, ptr %59, align 8, !tbaa !13
  %61 = zext i32 %60 to i64
  call void @_ZL16vma_delete_arrayItEvPK21VkAllocationCallbacksPT_m(ptr noundef %55, ptr noundef %58, i64 noundef %61)
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::ValidationContext", ptr %62, i32 0, i32 1
  store ptr null, ptr %63, align 8, !tbaa !9
  br label %64

64:                                               ; preds = %52, %2
  ret i1 true
}

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

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 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTSN30VmaBlockBufferImageGranularity17ValidationContextE", !6, i64 0, !6, i64 8}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"_ZTS30VmaBlockBufferImageGranularity", !15, i64 0, !12, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!14, !6, i64 16}
!19 = !{!20, !17, i64 2}
!20 = !{!"_ZTSN30VmaBlockBufferImageGranularity10RegionInfoE", !7, i64 0, !17, i64 2}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!10, !6, 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 }

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [67 x i8], align 1
@__PRETTY_FUNCTION__._ZNK30VmaBlockBufferImageGranularity16FinishValidationERNS_17ValidationContextE = external hidden unnamed_addr constant [81 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [83 x i8], align 1

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

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

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

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %11, label %.preheader

.preheader:                                       ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !10
  %.not12 = icmp eq i32 %8, 0
  br i1 %.not12, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %wide.trip.count = zext i32 %8 to i64
  br label %14

11:                                               ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.38, ptr noundef nonnull @.str.2, i32 noundef 6814, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK30VmaBlockBufferImageGranularity16FinishValidationERNS_17ValidationContextE) #3
  unreachable

12:                                               ; preds = %14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %14, !llvm.loop !15

._crit_edge:                                      ; preds = %12, %.preheader
  %.pre-phi = phi i64 [ 0, %.preheader ], [ %wide.trip.count, %12 ]
  %13 = load ptr, ptr %1, align 8, !tbaa !17
  tail call void @_ZL16vma_delete_arrayItEvPK21VkAllocationCallbacksPT_m(ptr noundef %13, ptr noundef nonnull %6, i64 noundef %.pre-phi)
  store ptr null, ptr %5, align 8, !tbaa !5
  br label %21

14:                                               ; preds = %.lr.ph, %12
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %12 ]
  %15 = getelementptr inbounds i16, ptr %6, i64 %indvars.iv
  %16 = load i16, ptr %15, align 2, !tbaa !18
  %17 = getelementptr inbounds %"struct.VmaBlockBufferImageGranularity::RegionInfo", ptr %10, i64 %indvars.iv, i32 1
  %18 = load i16, ptr %17, align 2, !tbaa !20
  %19 = icmp eq i16 %16, %18
  br i1 %19, label %12, label %20

20:                                               ; preds = %14
  tail call void @__assert_fail(ptr noundef nonnull @.str.39, ptr noundef nonnull @.str.2, i32 noundef 6818, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK30VmaBlockBufferImageGranularity16FinishValidationERNS_17ValidationContextE) #3
  unreachable

21:                                               ; preds = %._crit_edge, %2
  ret i1 true
}

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

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


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