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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN30VmaBlockBufferImageGranularity5ClearEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN21VmaBlockMetadata_TLSF5ClearEv(ptr noundef nonnull align 8 dereferenceable(400) %0) unnamed_addr #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 1
  store i64 0, ptr %6, align 8, !tbaa !9
  %7 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 2
  store i64 0, ptr %7, align 8, !tbaa !19
  %8 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 3
  store i64 0, ptr %8, align 8, !tbaa !20
  %9 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 4
  store i32 0, ptr %9, align 8, !tbaa !21
  %10 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 10
  %11 = load ptr, ptr %10, align 8, !tbaa !22
  %12 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %11, i32 0, i32 0
  store i64 0, ptr %12, align 8, !tbaa !23
  %13 = call noundef i64 @_ZNK16VmaBlockMetadata7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(33) %5)
  %14 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 10
  %15 = load ptr, ptr %14, align 8, !tbaa !22
  %16 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %15, i32 0, i32 1
  store i64 %13, ptr %16, align 8, !tbaa !25
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %17 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 10
  %18 = load ptr, ptr %17, align 8, !tbaa !22
  %19 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %18, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !26
  store ptr %20, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 10
  %22 = load ptr, ptr %21, align 8, !tbaa !22
  %23 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %22, i32 0, i32 2
  store ptr null, ptr %23, align 8, !tbaa !26
  br label %24

24:                                               ; preds = %27, %1
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %34

27:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %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 !26
  store ptr %30, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 9
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE4FreeEPS1_(ptr noundef nonnull align 8 dereferenceable(48) %31, ptr noundef %32)
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %33, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %24, !llvm.loop !27

34:                                               ; preds = %24
  %35 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 8
  %36 = load ptr, ptr %35, align 8, !tbaa !29
  %37 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 7
  %38 = load i32, ptr %37, align 8, !tbaa !30
  %39 = zext i32 %38 to i64
  %40 = mul i64 %39, 8
  call void @llvm.memset.p0.i64(ptr align 8 %36, i8 0, i64 %40, i1 false)
  %41 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 6
  %42 = getelementptr inbounds [58 x i32], ptr %41, i64 0, i64 0
  %43 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 5
  %44 = load i8, ptr %43, align 4, !tbaa !31
  %45 = zext i8 %44 to i64
  %46 = mul i64 %45, 4
  call void @llvm.memset.p0.i64(ptr align 8 %42, i8 0, i64 %46, i1 false)
  %47 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %5, i32 0, i32 11
  call void @_ZN30VmaBlockBufferImageGranularity5ClearEv(ptr noundef nonnull align 8 dereferenceable(24) %47)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE4FreeEPS1_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef) #1 align 2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 }

!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, !12, i64 40}
!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 = !{!10, !12, i64 48}
!20 = !{!10, !12, i64 56}
!21 = !{!10, !14, i64 64}
!22 = !{!10, !6, i64 368}
!23 = !{!24, !12, i64 0}
!24 = !{!"_ZTSN21VmaBlockMetadata_TLSF5BlockE", !12, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40}
!25 = !{!24, !12, i64 8}
!26 = !{!24, !6, i64 16}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = !{!10, !6, i64 312}
!30 = !{!10, !14, i64 304}
!31 = !{!10, !7, i64 68}


; 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 i64 @_ZNK16VmaBlockMetadata7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(33)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN30VmaBlockBufferImageGranularity5ClearEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN21VmaBlockMetadata_TLSF5ClearEv(ptr noundef nonnull align 8 dereferenceable(400) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = getelementptr inbounds i8, ptr %0, i64 368
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(28) %2, i8 0, i64 28, i1 false)
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  store i64 0, ptr %4, align 8, !tbaa !18
  %5 = tail call noundef i64 @_ZNK16VmaBlockMetadata7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(33) %0)
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  store i64 %5, ptr %7, align 8, !tbaa !20
  %8 = getelementptr inbounds i8, ptr %6, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !21
  store ptr null, ptr %8, align 8, !tbaa !21
  %.not5 = icmp eq ptr %9, null
  br i1 %.not5, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %10 = getelementptr inbounds i8, ptr %0, i64 320
  br label %11

11:                                               ; preds = %.lr.ph, %11
  %.06 = phi ptr [ %9, %.lr.ph ], [ %13, %11 ]
  %12 = getelementptr inbounds i8, ptr %.06, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !21
  tail call void @_ZN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE4FreeEPS1_(ptr noundef nonnull align 8 dereferenceable(48) %10, ptr noundef nonnull %.06)
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %._crit_edge, label %11, !llvm.loop !22

._crit_edge:                                      ; preds = %11, %1
  %14 = getelementptr inbounds i8, ptr %0, i64 312
  %15 = load ptr, ptr %14, align 8, !tbaa !24
  %16 = getelementptr inbounds i8, ptr %0, i64 304
  %17 = load i32, ptr %16, align 8, !tbaa !25
  %18 = zext i32 %17 to i64
  %19 = shl nuw nsw i64 %18, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %15, i8 0, i64 %19, i1 false)
  %20 = getelementptr inbounds i8, ptr %0, i64 72
  %21 = getelementptr inbounds i8, ptr %0, i64 68
  %22 = load i8, ptr %21, align 4, !tbaa !26
  %23 = zext i8 %22 to i64
  %24 = shl nuw nsw i64 %23, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %20, i8 0, i64 %24, i1 false)
  %25 = getelementptr inbounds i8, ptr %0, i64 376
  tail call void @_ZN30VmaBlockBufferImageGranularity5ClearEv(ptr noundef nonnull align 8 dereferenceable(24) %25)
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE4FreeEPS1_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef) local_unnamed_addr #0 align 2

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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !8, i64 0}
!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 8}
!21 = !{!19, !11, i64 16}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!6, !11, i64 312}
!25 = !{!6, !13, i64 304}
!26 = !{!6, !9, i64 68}


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