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

; 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 uwtable
declare dso_local void @_ZNK16VmaBlockMetadata18DebugLogAllocationEmmPv(ptr noundef nonnull align 8 dereferenceable(33), i64 noundef, i64 noundef, ptr noundef) #1 align 2

; 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 nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN21VmaBlockMetadata_TLSF5Block8UserDataEv(ptr noundef nonnull align 8 dereferenceable(48)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK21VmaBlockMetadata_TLSF22DebugLogAllAllocationsEv(ptr noundef nonnull align 8 dereferenceable(400) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %4, i32 0, i32 10
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %6, i32 0, i32 2
  %8 = load ptr, ptr %7, align 8, !tbaa !19
  store ptr %8, ptr %3, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %27, %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %31

13:                                               ; preds = %9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call noundef zeroext i1 @_ZNK21VmaBlockMetadata_TLSF5Block6IsFreeEv(ptr noundef nonnull align 8 dereferenceable(48) %14)
  br i1 %15, label %26, label %16

16:                                               ; preds = %13
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %17, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !21
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !22
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN21VmaBlockMetadata_TLSF5Block8UserDataEv(ptr noundef nonnull align 8 dereferenceable(48) %23)
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  call void @_ZNK16VmaBlockMetadata18DebugLogAllocationEmmPv(ptr noundef nonnull align 8 dereferenceable(33) %4, i64 noundef %19, i64 noundef %22, ptr noundef %25)
  br label %26

26:                                               ; preds = %16, %13
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !19
  store ptr %30, ptr %3, align 8, !tbaa !5
  br label %9, !llvm.loop !23

31:                                               ; preds = %12
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 368}
!10 = !{!"_ZTS21VmaBlockMetadata_TLSF", !11, i64 0, !12, i64 40, !12, i64 48, !12, i64 56, !14, i64 64, !7, i64 68, !7, i64 72, !14, i64 304, !6, i64 312, !15, i64 320, !6, i64 368, !18, i64 376}
!11 = !{!"_ZTS16VmaBlockMetadata", !12, i64 8, !6, i64 16, !12, i64 24, !13, i64 32}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTS16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE", !6, i64 0, !14, i64 8, !16, i64 16}
!16 = !{!"_ZTS9VmaVectorIN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE9ItemBlockE15VmaStlAllocatorIS4_EE", !17, i64 0, !6, i64 8, !12, i64 16, !12, i64 24}
!17 = !{!"_ZTS15VmaStlAllocatorIN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE9ItemBlockEE", !6, i64 0}
!18 = !{!"_ZTS30VmaBlockBufferImageGranularity", !12, i64 0, !14, i64 8, !6, i64 16}
!19 = !{!20, !6, i64 16}
!20 = !{!"_ZTSN21VmaBlockMetadata_TLSF5BlockE", !12, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40}
!21 = !{!20, !12, i64 0}
!22 = !{!20, !12, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"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"

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK16VmaBlockMetadata18DebugLogAllocationEmmPv(ptr noundef nonnull align 8 dereferenceable(33), i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #0 align 2

; 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
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN21VmaBlockMetadata_TLSF5Block8UserDataEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK21VmaBlockMetadata_TLSF22DebugLogAllAllocationsEv(ptr noundef nonnull align 8 dereferenceable(400) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 368
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.0.in7 = getelementptr inbounds i8, ptr %3, i64 16
  %.08 = load ptr, ptr %.0.in7, align 8, !tbaa !18
  %.not9 = icmp eq ptr %.08, null
  br i1 %.not9, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %11, %1
  ret void

.lr.ph:                                           ; preds = %1, %11
  %.010 = phi ptr [ %.0, %11 ], [ %.08, %1 ]
  %4 = tail call noundef zeroext i1 @_ZNK21VmaBlockMetadata_TLSF5Block6IsFreeEv(ptr noundef nonnull align 8 dereferenceable(48) %.010)
  br i1 %4, label %11, label %5

5:                                                ; preds = %.lr.ph
  %6 = load i64, ptr %.010, align 8, !tbaa !20
  %7 = getelementptr inbounds i8, ptr %.010, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !21
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN21VmaBlockMetadata_TLSF5Block8UserDataEv(ptr noundef nonnull align 8 dereferenceable(48) %.010)
  %10 = load ptr, ptr %9, align 8, !tbaa !22
  tail call void @_ZNK16VmaBlockMetadata18DebugLogAllocationEmmPv(ptr noundef nonnull align 8 dereferenceable(33) %0, i64 noundef %6, i64 noundef %8, ptr noundef %10)
  br label %11

11:                                               ; preds = %.lr.ph, %5
  %.0.in = getelementptr inbounds i8, ptr %.010, i64 16
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !18
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !23
}

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

!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, !11, i64 368}
!6 = !{!"_ZTS21VmaBlockMetadata_TLSF", !7, i64 0, !8, i64 40, !8, i64 48, !8, i64 56, !13, i64 64, !9, i64 68, !9, i64 72, !13, i64 304, !11, i64 312, !14, i64 320, !11, i64 368, !17, i64 376}
!7 = !{!"_ZTS16VmaBlockMetadata", !8, i64 8, !11, i64 16, !8, i64 24, !12, i64 32}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"bool", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!"_ZTS16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE", !11, i64 0, !13, i64 8, !15, i64 16}
!15 = !{!"_ZTS9VmaVectorIN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE9ItemBlockE15VmaStlAllocatorIS4_EE", !16, i64 0, !11, i64 8, !8, i64 16, !8, i64 24}
!16 = !{!"_ZTS15VmaStlAllocatorIN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE9ItemBlockEE", !11, i64 0}
!17 = !{!"_ZTS30VmaBlockBufferImageGranularity", !8, i64 0, !13, i64 8, !11, i64 16}
!18 = !{!19, !11, i64 16}
!19 = !{!"_ZTSN21VmaBlockMetadata_TLSF5BlockE", !8, i64 0, !8, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !9, i64 40}
!20 = !{!19, !8, i64 0}
!21 = !{!19, !8, i64 8}
!22 = !{!11, !11, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass