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

%struct.VmaDetailedStatistics = type { %struct.VmaStatistics, i32, i64, i64, i64, i64 }
%struct.VmaStatistics = type { i32, i32, i64, i64 }
%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 hidden void @_ZL34VmaAddDetailedStatisticsAllocationR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64), i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK16VmaBlockMetadata7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(33)) #2 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL35VmaAddDetailedStatisticsUnusedRangeR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64), i64 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 void @_ZNK21VmaBlockMetadata_TLSF21AddDetailedStatisticsER21VmaDetailedStatistics(ptr noundef nonnull align 8 dereferenceable(400) %0, ptr noundef nonnull align 8 dereferenceable(64) %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.VmaDetailedStatistics, ptr %7, i32 0, i32 0
  %9 = getelementptr inbounds %struct.VmaStatistics, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = add i32 %10, 1
  store i32 %11, ptr %9, align 8, !tbaa !9
  %12 = call noundef i64 @_ZNK16VmaBlockMetadata7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(33) %6)
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.VmaDetailedStatistics, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.VmaStatistics, ptr %14, i32 0, i32 2
  %16 = load i64, ptr %15, align 8, !tbaa !14
  %17 = add i64 %16, %12
  store i64 %17, ptr %15, align 8, !tbaa !14
  %18 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %6, i32 0, i32 10
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %19, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !23
  %22 = icmp ugt i64 %21, 0
  br i1 %22, label %23, label %29

23:                                               ; preds = %2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %6, i32 0, i32 10
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %26, i32 0, i32 1
  %28 = load i64, ptr %27, align 8, !tbaa !23
  call void @_ZL35VmaAddDetailedStatisticsUnusedRangeR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64) %24, i64 noundef %28)
  br label %29

29:                                               ; preds = %23, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %30 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %6, i32 0, i32 10
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !25
  store ptr %33, ptr %5, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %52, %29
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %56

38:                                               ; preds = %34
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = call noundef zeroext i1 @_ZNK21VmaBlockMetadata_TLSF5Block6IsFreeEv(ptr noundef nonnull align 8 dereferenceable(48) %39)
  br i1 %40, label %41, label %46

41:                                               ; preds = %38
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !23
  call void @_ZL35VmaAddDetailedStatisticsUnusedRangeR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64) %42, i64 noundef %45)
  br label %51

46:                                               ; preds = %38
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %48, i32 0, i32 1
  %50 = load i64, ptr %49, align 8, !tbaa !23
  call void @_ZL34VmaAddDetailedStatisticsAllocationR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64) %47, i64 noundef %50)
  br label %51

51:                                               ; preds = %46, %41
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !25
  store ptr %55, ptr %5, align 8, !tbaa !5
  br label %34, !llvm.loop !26

56:                                               ; preds = %37
  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, !12, i64 0}
!10 = !{!"_ZTS21VmaDetailedStatistics", !11, i64 0, !12, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56}
!11 = !{!"_ZTS13VmaStatistics", !12, i64 0, !12, i64 4, !13, i64 8, !13, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !13, i64 8}
!15 = !{!16, !6, i64 368}
!16 = !{!"_ZTS21VmaBlockMetadata_TLSF", !17, i64 0, !13, i64 40, !13, i64 48, !13, i64 56, !12, i64 64, !7, i64 68, !7, i64 72, !12, i64 304, !6, i64 312, !19, i64 320, !6, i64 368, !22, i64 376}
!17 = !{!"_ZTS16VmaBlockMetadata", !13, i64 8, !6, i64 16, !13, i64 24, !18, i64 32}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"_ZTS16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE", !6, i64 0, !12, i64 8, !20, i64 16}
!20 = !{!"_ZTS9VmaVectorIN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE9ItemBlockE15VmaStlAllocatorIS4_EE", !21, i64 0, !6, i64 8, !13, i64 16, !13, i64 24}
!21 = !{!"_ZTS15VmaStlAllocatorIN16VmaPoolAllocatorIN21VmaBlockMetadata_TLSF5BlockEE9ItemBlockEE", !6, i64 0}
!22 = !{!"_ZTS30VmaBlockBufferImageGranularity", !13, i64 0, !12, i64 8, !6, i64 16}
!23 = !{!24, !13, i64 8}
!24 = !{!"_ZTSN21VmaBlockMetadata_TLSF5BlockE", !13, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40}
!25 = !{!24, !6, i64 16}
!26 = distinct !{!26, !27}
!27 = !{!"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 hidden void @_ZL34VmaAddDetailedStatisticsAllocationR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64), i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK16VmaBlockMetadata7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(33)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL35VmaAddDetailedStatisticsUnusedRangeR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64), i64 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 uwtable
define dso_local void @_ZNK21VmaBlockMetadata_TLSF21AddDetailedStatisticsER21VmaDetailedStatistics(ptr noundef nonnull align 8 dereferenceable(400) %0, ptr noundef nonnull align 8 dereferenceable(64) %1) unnamed_addr #0 align 2 {
  %3 = load i32, ptr %1, align 8, !tbaa !5
  %4 = add i32 %3, 1
  store i32 %4, ptr %1, align 8, !tbaa !5
  %5 = tail call noundef i64 @_ZNK16VmaBlockMetadata7GetSizeEv(ptr noundef nonnull align 8 dereferenceable(33) %0)
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %8 = add i64 %7, %5
  store i64 %8, ptr %6, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %0, i64 368
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !22
  %.not = icmp eq i64 %12, 0
  br i1 %.not, label %14, label %13

13:                                               ; preds = %2
  tail call void @_ZL35VmaAddDetailedStatisticsUnusedRangeR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64) %1, i64 noundef %12)
  %.pre = load ptr, ptr %9, align 8, !tbaa !13
  br label %14

14:                                               ; preds = %13, %2
  %15 = phi ptr [ %.pre, %13 ], [ %10, %2 ]
  %.0.in13 = getelementptr inbounds i8, ptr %15, i64 16
  %.014 = load ptr, ptr %.0.in13, align 8, !tbaa !24
  %.not1215 = icmp eq ptr %.014, null
  br i1 %.not1215, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %21, %14
  ret void

.lr.ph:                                           ; preds = %14, %21
  %.016 = phi ptr [ %.0, %21 ], [ %.014, %14 ]
  %16 = tail call noundef zeroext i1 @_ZNK21VmaBlockMetadata_TLSF5Block6IsFreeEv(ptr noundef nonnull align 8 dereferenceable(48) %.016)
  %17 = getelementptr inbounds i8, ptr %.016, i64 8
  %18 = load i64, ptr %17, align 8, !tbaa !22
  br i1 %16, label %19, label %20

19:                                               ; preds = %.lr.ph
  tail call void @_ZL35VmaAddDetailedStatisticsUnusedRangeR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64) %1, i64 noundef %18)
  br label %21

20:                                               ; preds = %.lr.ph
  tail call void @_ZL34VmaAddDetailedStatisticsAllocationR21VmaDetailedStatisticsm(ptr noundef nonnull align 8 dereferenceable(64) %1, i64 noundef %18)
  br label %21

21:                                               ; preds = %19, %20
  %.0.in = getelementptr inbounds i8, ptr %.016, i64 16
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !24
  %.not12 = icmp eq ptr %.0, null
  br i1 %.not12, label %._crit_edge, label %.lr.ph, !llvm.loop !25
}

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


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