; 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.VmaBlockVector = type <{ ptr, ptr, i32, [4 x i8], i64, i64, i64, i64, i8, [3 x i8], i32, float, [4 x i8], i64, ptr, %class.VmaRWMutex, %class.VmaVector.15, i32, i8, [3 x i8] }>
%class.VmaRWMutex = type { %"class.std::shared_mutex" }
%"class.std::shared_mutex" = type { %"class.std::__shared_mutex_pthread" }
%"class.std::__shared_mutex_pthread" = type { %union.pthread_rwlock_t }
%union.pthread_rwlock_t = type { %struct.__pthread_rwlock_arch_t }
%struct.__pthread_rwlock_arch_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i8, [7 x i8], i64, i32 }
%class.VmaVector.15 = type { %struct.VmaStlAllocator.16, ptr, i64, i64 }
%struct.VmaStlAllocator.16 = type { ptr }

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.57 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__._ZN14VmaBlockVector6RemoveEP20VmaDeviceMemoryBlock = external hidden unnamed_addr constant [52 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 i64 @_ZNK9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14VmaBlockVector6RemoveEP20VmaDeviceMemoryBlock(ptr noundef nonnull align 8 dereferenceable(181) %0, ptr noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %28, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds %class.VmaBlockVector, ptr %7, i32 0, i32 16
  %12 = call noundef i64 @_ZNK9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %11)
  %13 = icmp ult i64 %10, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %8
  store i32 2, ptr %6, align 4
  br label %31

15:                                               ; preds = %8
  %16 = getelementptr inbounds %class.VmaBlockVector, ptr %7, i32 0, i32 16
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(32) %16, i64 noundef %18)
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = icmp eq ptr %20, %21
  br i1 %22, label %23, label %27

23:                                               ; preds = %15
  %24 = getelementptr inbounds %class.VmaBlockVector, ptr %7, i32 0, i32 16
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  call void @_ZL15VmaVectorRemoveIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEvR9VmaVectorIT_T0_Em(ptr noundef nonnull align 8 dereferenceable(32) %24, i64 noundef %26)
  store i32 1, ptr %6, align 4
  br label %31

27:                                               ; preds = %15
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = add i32 %29, 1
  store i32 %30, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !11

31:                                               ; preds = %23, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %32 = load i32, ptr %6, align 4
  switch i32 %32, label %35 [
    i32 2, label %33
    i32 1, label %34
  ]

33:                                               ; preds = %31
  call void @__assert_fail(ptr noundef @.str.57, ptr noundef @.str.2, i32 noundef 12804, ptr noundef @__PRETTY_FUNCTION__._ZN14VmaBlockVector6RemoveEP20VmaDeviceMemoryBlock) #5
  unreachable

34:                                               ; preds = %31
  ret void

35:                                               ; preds = %31
  unreachable
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL15VmaVectorRemoveIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEvR9VmaVectorIT_T0_Em(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #3

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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.57 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__._ZN14VmaBlockVector6RemoveEP20VmaDeviceMemoryBlock = external hidden unnamed_addr constant [52 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 i64 @_ZNK9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14VmaBlockVector6RemoveEP20VmaDeviceMemoryBlock(ptr noundef nonnull align 8 dereferenceable(181) %0, ptr noundef readnone %1) local_unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 144
  %4 = tail call noundef i64 @_ZNK9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %3)
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

5:                                                ; preds = %.lr.ph
  %6 = add i32 %.0614, 1
  %7 = zext i32 %6 to i64
  %8 = tail call noundef i64 @_ZNK9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %3)
  %9 = icmp ugt i64 %8, %7
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !5

.lr.ph:                                           ; preds = %2, %5
  %10 = phi i64 [ %7, %5 ], [ 0, %2 ]
  %.0614 = phi i32 [ %6, %5 ], [ 0, %2 ]
  %11 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(32) %3, i64 noundef %10)
  %12 = load ptr, ptr %11, align 8, !tbaa !7
  %13 = icmp eq ptr %12, %1
  br i1 %13, label %14, label %5

._crit_edge:                                      ; preds = %5, %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.57, ptr noundef nonnull @.str.2, i32 noundef 12804, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN14VmaBlockVector6RemoveEP20VmaDeviceMemoryBlock) #3
  unreachable

14:                                               ; preds = %.lr.ph
  tail call void @_ZL15VmaVectorRemoveIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEvR9VmaVectorIT_T0_Em(ptr noundef nonnull align 8 dereferenceable(32) %3, i64 noundef %10)
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL15VmaVectorRemoveIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEvR9VmaVectorIT_T0_Em(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #2

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 = { 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 #3 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}


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