; 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::Block" = type { i64, i64, ptr, ptr, ptr, %union.anon.6 }
%union.anon.6 = type { ptr }

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.116 = external hidden unnamed_addr constant [44 x i8], align 1
@__PRETTY_FUNCTION__._ZNK21VmaBlockMetadata_TLSF17GetNextAllocationEP16VmaAllocHandle_T = external hidden unnamed_addr constant [86 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 @_ZNK21VmaBlockMetadata_TLSF5Block6IsFreeEv(ptr noundef nonnull align 8 dereferenceable(48)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK21VmaBlockMetadata_TLSF17GetNextAllocationEP16VmaAllocHandle_T(ptr noundef nonnull align 8 dereferenceable(400) %0, ptr noundef %1) unnamed_addr #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %10, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = call noundef zeroext i1 @_ZNK21VmaBlockMetadata_TLSF5Block6IsFreeEv(ptr noundef nonnull align 8 dereferenceable(48) %11)
  br i1 %12, label %14, label %13

13:                                               ; preds = %2
  br label %14

14:                                               ; preds = %13, %2
  %15 = phi i1 [ false, %2 ], [ 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.116, ptr noundef @.str.2, i32 noundef 10711, ptr noundef @__PRETTY_FUNCTION__._ZNK21VmaBlockMetadata_TLSF17GetNextAllocationEP16VmaAllocHandle_T) #5
  unreachable

18:                                               ; No predecessors!
  br label %19

19:                                               ; preds = %18, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  store ptr %22, ptr %7, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %33, %19
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i32 2, ptr %8, align 4
  br label %37

27:                                               ; preds = %23
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call noundef zeroext i1 @_ZNK21VmaBlockMetadata_TLSF5Block6IsFreeEv(ptr noundef nonnull align 8 dereferenceable(48) %28)
  br i1 %29, label %32, label %30

30:                                               ; preds = %27
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %31, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %37

32:                                               ; preds = %27
  br label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  store ptr %36, ptr %7, align 8, !tbaa !5
  br label %23, !llvm.loop !12

37:                                               ; preds = %30, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %38 = load i32, ptr %8, align 4
  switch i32 %38, label %40 [
    i32 2, label %39
  ]

39:                                               ; preds = %37
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %40

40:                                               ; preds = %39, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %41 = load ptr, ptr %3, align 8
  ret ptr %41
}

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 = { 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, !6, i64 16}
!10 = !{!"_ZTSN21VmaBlockMetadata_TLSF5BlockE", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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.116 = external hidden unnamed_addr constant [44 x i8], align 1
@__PRETTY_FUNCTION__._ZNK21VmaBlockMetadata_TLSF17GetNextAllocationEP16VmaAllocHandle_T = external hidden unnamed_addr constant [86 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 @_ZNK21VmaBlockMetadata_TLSF5Block6IsFreeEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZNK21VmaBlockMetadata_TLSF17GetNextAllocationEP16VmaAllocHandle_T(ptr nocapture noundef nonnull readnone align 8 dereferenceable(400) %0, ptr noundef nonnull %1) unnamed_addr #1 align 2 {
  %3 = tail call noundef zeroext i1 @_ZNK21VmaBlockMetadata_TLSF5Block6IsFreeEv(ptr noundef nonnull align 8 dereferenceable(48) %1)
  br i1 %3, label %4, label %.preheader

4:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.116, ptr noundef nonnull @.str.2, i32 noundef 10711, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK21VmaBlockMetadata_TLSF17GetNextAllocationEP16VmaAllocHandle_T) #2
  unreachable

.preheader:                                       ; preds = %2, %5
  %.pn = phi ptr [ %.09, %5 ], [ %1, %2 ]
  %.09.in = getelementptr inbounds i8, ptr %.pn, i64 16
  %.09 = load ptr, ptr %.09.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.09, null
  br i1 %.not, label %7, label %5

5:                                                ; preds = %.preheader
  %6 = tail call noundef zeroext i1 @_ZNK21VmaBlockMetadata_TLSF5Block6IsFreeEv(ptr noundef nonnull align 8 dereferenceable(48) %.09)
  br i1 %6, label %.preheader, label %7, !llvm.loop !11

7:                                                ; preds = %5, %.preheader
  ret ptr %.09
}

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 = { 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, !10, i64 16}
!6 = !{!"_ZTSN21VmaBlockMetadata_TLSF5BlockE", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !8, i64 40}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass