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

; 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 @_ZNK16VmaBlockMetadata9IsVirtualEv(ptr noundef nonnull align 8 dereferenceable(33)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK21VmaBlockMetadata_TLSF12GetListIndexEht(ptr noundef nonnull align 8 dereferenceable(400) %0, i8 noundef zeroext %1, i16 noundef zeroext %2) #2 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i16, align 2
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store i16 %2, ptr %7, align 2, !tbaa !10
  %10 = load ptr, ptr %5, align 8
  %11 = load i8, ptr %6, align 1, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %3
  %15 = load i16, ptr %7, align 2, !tbaa !10
  %16 = zext i16 %15 to i32
  store i32 %16, ptr %4, align 4
  br label %33

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %18 = load i8, ptr %6, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = sub nsw i32 %19, 1
  %21 = mul i32 %20, 32
  %22 = load i16, ptr %7, align 2, !tbaa !10
  %23 = zext i16 %22 to i32
  %24 = add i32 %21, %23
  store i32 %24, ptr %8, align 4, !tbaa !12
  %25 = call noundef zeroext i1 @_ZNK16VmaBlockMetadata9IsVirtualEv(ptr noundef nonnull align 8 dereferenceable(33) %10)
  br i1 %25, label %26, label %29

26:                                               ; preds = %17
  %27 = load i32, ptr %8, align 4, !tbaa !12
  %28 = add i32 %27, 32
  store i32 %28, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %32

29:                                               ; preds = %17
  %30 = load i32, ptr %8, align 4, !tbaa !12
  %31 = add i32 %30, 4
  store i32 %31, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %32

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

33:                                               ; preds = %32, %14
  %34 = load i32, ptr %4, align 4
  ret i32 %34
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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"

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 73696) i32 @_ZNK21VmaBlockMetadata_TLSF12GetListIndexEht(ptr noundef nonnull align 8 dereferenceable(400) %0, i8 noundef zeroext %1, i16 noundef zeroext %2) local_unnamed_addr #0 align 2 {
  %4 = icmp eq i8 %1, 0
  br i1 %4, label %5, label %7

5:                                                ; preds = %3
  %6 = zext i16 %2 to i32
  br label %14

7:                                                ; preds = %3
  %8 = zext i8 %1 to i32
  %9 = shl nuw nsw i32 %8, 5
  %10 = zext i16 %2 to i32
  %11 = tail call noundef zeroext i1 @_ZNK16VmaBlockMetadata9IsVirtualEv(ptr noundef nonnull align 8 dereferenceable(33) %0)
  %12 = add nuw nsw i32 %9, %10
  %13 = add nsw i32 %12, -28
  %.0 = select i1 %11, i32 %12, i32 %13
  br label %14

14:                                               ; preds = %7, %5
  %.1 = phi i32 [ %6, %5 ], [ %.0, %7 ]
  ret i32 %.1
}

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

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


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