; 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.VmaBlockMetadata_TLSF = type { %class.VmaBlockMetadata.base, i64, i64, i64, i32, i8, [58 x i32], i32, ptr, %class.VmaPoolAllocator, ptr, %class.VmaBlockBufferImageGranularity }
%class.VmaBlockMetadata.base = type <{ ptr, i64, ptr, i64, i8 }>
%class.VmaPoolAllocator = type { ptr, i32, %class.VmaVector.4 }
%class.VmaVector.4 = type { %struct.VmaStlAllocator.5, ptr, i64, i64 }
%struct.VmaStlAllocator.5 = type { ptr }
%class.VmaBlockBufferImageGranularity = type { i64, i32, ptr }

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.130 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__._ZNK21VmaBlockMetadata_TLSF13FindFreeBlockEmRj = external hidden unnamed_addr constant [99 x i8], align 1
@.str.131 = external hidden unnamed_addr constant [22 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 uwtable
declare dso_local noundef zeroext i8 @_ZNK21VmaBlockMetadata_TLSF17SizeToMemoryClassEm(ptr noundef nonnull align 8 dereferenceable(400), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i16 @_ZNK21VmaBlockMetadata_TLSF17SizeToSecondIndexEmh(ptr noundef nonnull align 8 dereferenceable(400), i64 noundef, i8 noundef zeroext) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK21VmaBlockMetadata_TLSF13FindFreeBlockEmRj(ptr noundef nonnull align 8 dereferenceable(400) %0, i64 noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = call noundef zeroext i8 @_ZNK21VmaBlockMetadata_TLSF17SizeToMemoryClassEm(ptr noundef nonnull align 8 dereferenceable(400) %12, i64 noundef %13)
  store i8 %14, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %15 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %12, i32 0, i32 6
  %16 = load i8, ptr %8, align 1, !tbaa !11
  %17 = zext i8 %16 to i64
  %18 = getelementptr inbounds [58 x i32], ptr %15, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = load i8, ptr %8, align 1, !tbaa !11
  %22 = call noundef zeroext i16 @_ZNK21VmaBlockMetadata_TLSF17SizeToSecondIndexEmh(ptr noundef nonnull align 8 dereferenceable(400) %12, i64 noundef %20, i8 noundef zeroext %21)
  %23 = zext i16 %22 to i32
  %24 = shl i32 -1, %23
  %25 = and i32 %19, %24
  store i32 %25, ptr %9, align 4, !tbaa !12
  %26 = load i32, ptr %9, align 4, !tbaa !12
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %59, label %28

28:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %29 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %12, i32 0, i32 4
  %30 = load i32, ptr %29, align 8, !tbaa !14
  %31 = zext i32 %30 to i64
  %32 = load i8, ptr %8, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  %34 = add nsw i32 %33, 1
  %35 = zext i32 %34 to i64
  %36 = shl i64 -1, %35
  %37 = and i64 %31, %36
  %38 = trunc i64 %37 to i32
  store i32 %38, ptr %10, align 4, !tbaa !12
  %39 = load i32, ptr %10, align 4, !tbaa !12
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %42, label %41

41:                                               ; preds = %28
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %56

42:                                               ; preds = %28
  %43 = load i32, ptr %10, align 4, !tbaa !12
  %44 = call noundef zeroext i8 @_ZL13VmaBitScanLSBj(i32 noundef %43)
  store i8 %44, ptr %8, align 1, !tbaa !11
  %45 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %12, i32 0, i32 6
  %46 = load i8, ptr %8, align 1, !tbaa !11
  %47 = zext i8 %46 to i64
  %48 = getelementptr inbounds [58 x i32], ptr %45, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !12
  store i32 %49, ptr %9, align 4, !tbaa !12
  %50 = load i32, ptr %9, align 4, !tbaa !12
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %42
  br label %55

53:                                               ; preds = %42
  call void @__assert_fail(ptr noundef @.str.130, ptr noundef @.str.2, i32 noundef 10882, ptr noundef @__PRETTY_FUNCTION__._ZNK21VmaBlockMetadata_TLSF13FindFreeBlockEmRj) #5
  unreachable

54:                                               ; No predecessors!
  br label %55

55:                                               ; preds = %54, %52
  store i32 0, ptr %11, align 4
  br label %56

56:                                               ; preds = %55, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %57 = load i32, ptr %11, align 4
  switch i32 %57, label %85 [
    i32 0, label %58
  ]

58:                                               ; preds = %56
  br label %59

59:                                               ; preds = %58, %3
  %60 = load i8, ptr %8, align 1, !tbaa !11
  %61 = load i32, ptr %9, align 4, !tbaa !12
  %62 = call noundef zeroext i8 @_ZL13VmaBitScanLSBj(i32 noundef %61)
  %63 = zext i8 %62 to i16
  %64 = call noundef i32 @_ZNK21VmaBlockMetadata_TLSF12GetListIndexEht(ptr noundef nonnull align 8 dereferenceable(400) %12, i8 noundef zeroext %60, i16 noundef zeroext %63)
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %64, ptr %65, align 4, !tbaa !12
  %66 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %12, i32 0, i32 8
  %67 = load ptr, ptr %66, align 8, !tbaa !22
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load i32, ptr %68, align 4, !tbaa !12
  %70 = zext i32 %69 to i64
  %71 = getelementptr inbounds ptr, ptr %67, i64 %70
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  %73 = icmp ne ptr %72, null
  br i1 %73, label %74, label %75

74:                                               ; preds = %59
  br label %77

75:                                               ; preds = %59
  call void @__assert_fail(ptr noundef @.str.131, ptr noundef @.str.2, i32 noundef 10886, ptr noundef @__PRETTY_FUNCTION__._ZNK21VmaBlockMetadata_TLSF13FindFreeBlockEmRj) #5
  unreachable

76:                                               ; No predecessors!
  br label %77

77:                                               ; preds = %76, %74
  %78 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %12, i32 0, i32 8
  %79 = load ptr, ptr %78, align 8, !tbaa !22
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load i32, ptr %80, align 4, !tbaa !12
  %82 = zext i32 %81 to i64
  %83 = getelementptr inbounds ptr, ptr %79, i64 %82
  %84 = load ptr, ptr %83, align 8, !tbaa !5
  store ptr %84, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %85

85:                                               ; preds = %77, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  %86 = load ptr, ptr %4, align 8
  ret ptr %86
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK21VmaBlockMetadata_TLSF12GetListIndexEht(ptr noundef nonnull align 8 dereferenceable(400), i8 noundef zeroext, i16 noundef zeroext) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i8 @_ZL13VmaBitScanLSBj(i32 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 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 = { 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 #4 = { nounwind }
attributes #5 = { 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, !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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 64}
!15 = !{!"_ZTS21VmaBlockMetadata_TLSF", !16, i64 0, !10, i64 40, !10, i64 48, !10, i64 56, !13, i64 64, !7, i64 68, !7, i64 72, !13, i64 304, !6, i64 312, !18, i64 320, !6, i64 368, !21, i64 376}
!16 = !{!"_ZTS16VmaBlockMetadata", !10, i64 8, !6, i64 16, !10, i64 24, !17, i64 32}
!17 = !{!"bool", !7, i64 0}
!18 = !{!"_ZTS16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE", !6, i64 0, !13, i64 8, !19, i64 16}
!19 = !{!"_ZTS9VmaVectorIN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE9ItemBlockE15VmaStlAllocatorIS4_EE", !20, i64 0, !6, i64 8, !10, i64 16, !10, i64 24}
!20 = !{!"_ZTS15VmaStlAllocatorIN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE9ItemBlockEE", !6, i64 0}
!21 = !{!"_ZTS30VmaBlockBufferImageGranularity", !10, i64 0, !13, i64 8, !6, i64 16}
!22 = !{!15, !6, i64 312}


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

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.130 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__._ZNK21VmaBlockMetadata_TLSF13FindFreeBlockEmRj = external hidden unnamed_addr constant [99 x i8], align 1
@.str.131 = external hidden unnamed_addr constant [22 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 uwtable
declare dso_local noundef zeroext i8 @_ZNK21VmaBlockMetadata_TLSF17SizeToMemoryClassEm(ptr noundef nonnull align 8 dereferenceable(400), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i16 @_ZNK21VmaBlockMetadata_TLSF17SizeToSecondIndexEmh(ptr noundef nonnull align 8 dereferenceable(400), i64 noundef, i8 noundef zeroext) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK21VmaBlockMetadata_TLSF13FindFreeBlockEmRj(ptr noundef nonnull align 8 dereferenceable(400) %0, i64 noundef %1, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %2) local_unnamed_addr #1 align 2 {
  %4 = tail call noundef zeroext i8 @_ZNK21VmaBlockMetadata_TLSF17SizeToMemoryClassEm(ptr noundef nonnull align 8 dereferenceable(400) %0, i64 noundef %1)
  %5 = getelementptr inbounds i8, ptr %0, i64 72
  %6 = zext i8 %4 to i64
  %7 = getelementptr inbounds [58 x i32], ptr %5, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = tail call noundef zeroext i16 @_ZNK21VmaBlockMetadata_TLSF17SizeToSecondIndexEmh(ptr noundef nonnull align 8 dereferenceable(400) %0, i64 noundef %1, i8 noundef zeroext %4)
  %10 = zext nneg i16 %9 to i32
  %11 = shl nsw i32 -1, %10
  %12 = and i32 %11, %8
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %25

13:                                               ; preds = %3
  %14 = getelementptr inbounds i8, ptr %0, i64 64
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = shl nsw i64 -2, %6
  %17 = trunc i64 %16 to i32
  %18 = and i32 %15, %17
  %.not27.not = icmp eq i32 %18, 0
  br i1 %.not27.not, label %.thread, label %19

19:                                               ; preds = %13
  %20 = tail call noundef zeroext i8 @_ZL13VmaBitScanLSBj(i32 noundef %18)
  %21 = zext i8 %20 to i64
  %22 = getelementptr inbounds [58 x i32], ptr %5, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %.not28 = icmp eq i32 %23, 0
  br i1 %.not28, label %24, label %25

24:                                               ; preds = %19
  tail call void @__assert_fail(ptr noundef nonnull @.str.130, ptr noundef nonnull @.str.2, i32 noundef 10882, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK21VmaBlockMetadata_TLSF13FindFreeBlockEmRj) #3
  unreachable

25:                                               ; preds = %19, %3
  %.121 = phi i8 [ %4, %3 ], [ %20, %19 ]
  %.119 = phi i32 [ %12, %3 ], [ %23, %19 ]
  %26 = tail call noundef zeroext i8 @_ZL13VmaBitScanLSBj(i32 noundef %.119)
  %27 = zext i8 %26 to i16
  %28 = tail call noundef i32 @_ZNK21VmaBlockMetadata_TLSF12GetListIndexEht(ptr noundef nonnull align 8 dereferenceable(400) %0, i8 noundef zeroext %.121, i16 noundef zeroext %27)
  store i32 %28, ptr %2, align 4, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %0, i64 312
  %30 = load ptr, ptr %29, align 8, !tbaa !19
  %31 = zext i32 %28 to i64
  %32 = getelementptr inbounds ptr, ptr %30, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !20
  %.not29 = icmp eq ptr %33, null
  br i1 %.not29, label %34, label %.thread

34:                                               ; preds = %25
  tail call void @__assert_fail(ptr noundef nonnull @.str.131, ptr noundef nonnull @.str.2, i32 noundef 10886, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK21VmaBlockMetadata_TLSF13FindFreeBlockEmRj) #3
  unreachable

.thread:                                          ; preds = %13, %25
  %.1 = phi ptr [ %33, %25 ], [ null, %13 ]
  ret ptr %.1
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK21VmaBlockMetadata_TLSF12GetListIndexEht(ptr noundef nonnull align 8 dereferenceable(400), i8 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i8 @_ZL13VmaBitScanLSBj(i32 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 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 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 64}
!10 = !{!"_ZTS21VmaBlockMetadata_TLSF", !11, i64 0, !12, i64 40, !12, i64 48, !12, i64 56, !6, i64 64, !7, i64 68, !7, i64 72, !6, i64 304, !13, i64 312, !15, i64 320, !13, i64 368, !18, i64 376}
!11 = !{!"_ZTS16VmaBlockMetadata", !12, i64 8, !13, i64 16, !12, i64 24, !14, i64 32}
!12 = !{!"long", !7, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"_ZTS16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE", !13, i64 0, !6, i64 8, !16, i64 16}
!16 = !{!"_ZTS9VmaVectorIN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE9ItemBlockE15VmaStlAllocatorIS4_EE", !17, i64 0, !13, i64 8, !12, i64 16, !12, i64 24}
!17 = !{!"_ZTS15VmaStlAllocatorIN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE9ItemBlockEE", !13, i64 0}
!18 = !{!"_ZTS30VmaBlockBufferImageGranularity", !12, i64 0, !6, i64 8, !13, i64 16}
!19 = !{!10, !13, i64 312}
!20 = !{!13, !13, i64 0}


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