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

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.62 = external hidden unnamed_addr constant [62 x i8], align 1
@__PRETTY_FUNCTION__._ZN21VmaBlockMetadata_TLSF15CheckCorruptionEPKv = external hidden unnamed_addr constant [70 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 hidden noundef zeroext i1 @_ZL21VmaValidateMagicValuePKvm(ptr noundef, i64 noundef) #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 uwtable
define dso_local noundef i32 @_ZN21VmaBlockMetadata_TLSF15CheckCorruptionEPKv(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
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = getelementptr inbounds %class.VmaBlockMetadata_TLSF, ptr %6, i32 0, i32 10
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !19
  store ptr %10, ptr %5, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %31, %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %35

15:                                               ; preds = %11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call noundef zeroext i1 @_ZNK21VmaBlockMetadata_TLSF5Block6IsFreeEv(ptr noundef nonnull align 8 dereferenceable(48) %16)
  br i1 %17, label %30, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !21
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !22
  %26 = add i64 %22, %25
  %27 = call noundef zeroext i1 @_ZL21VmaValidateMagicValuePKvm(ptr noundef %19, i64 noundef %26)
  br i1 %27, label %29, label %28

28:                                               ; preds = %18
  call void @__assert_fail(ptr noundef @.str.62, ptr noundef @.str.2, i32 noundef 10504, ptr noundef @__PRETTY_FUNCTION__._ZN21VmaBlockMetadata_TLSF15CheckCorruptionEPKv) #5
  unreachable

29:                                               ; preds = %18
  br label %30

30:                                               ; preds = %29, %15
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %"class.VmaBlockMetadata_TLSF::Block", ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !19
  store ptr %34, ptr %5, align 8, !tbaa !5
  br label %11, !llvm.loop !23

35:                                               ; preds = %14
  ret i32 0
}

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

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.62 = external hidden unnamed_addr constant [62 x i8], align 1
@__PRETTY_FUNCTION__._ZN21VmaBlockMetadata_TLSF15CheckCorruptionEPKv = external hidden unnamed_addr constant [70 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 hidden noundef zeroext i1 @_ZL21VmaValidateMagicValuePKvm(ptr noundef, i64 noundef) local_unnamed_addr #1

; 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 i32 @_ZN21VmaBlockMetadata_TLSF15CheckCorruptionEPKv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(400) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 368
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.0.in7 = getelementptr inbounds i8, ptr %4, 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 = %13, %2
  ret i32 0

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

6:                                                ; preds = %.lr.ph
  %7 = load i64, ptr %.010, align 8, !tbaa !20
  %8 = getelementptr inbounds i8, ptr %.010, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !21
  %10 = add i64 %9, %7
  %11 = tail call noundef zeroext i1 @_ZL21VmaValidateMagicValuePKvm(ptr noundef %1, i64 noundef %10)
  br i1 %11, label %13, label %12

12:                                               ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.62, ptr noundef nonnull @.str.2, i32 noundef 10504, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN21VmaBlockMetadata_TLSF15CheckCorruptionEPKv) #2
  unreachable

13:                                               ; preds = %.lr.ph, %6
  %.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 !22
}

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, !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 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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