; 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 }
%class.VmaDeviceMemoryBlock = type { ptr, ptr, i32, i32, ptr, %class.VmaMutex, %class.VmaMappingHysteresis, i32, ptr }
%class.VmaMutex = type { %"class.std::mutex" }
%"class.std::mutex" = type { %"class.std::__mutex_base" }
%"class.std::__mutex_base" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%class.VmaMappingHysteresis = type { i32, i32, i32 }

; 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 @_ZNK9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) #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) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14VmaBlockVector23IncrementallySortBlocksEv(ptr noundef nonnull align 8 dereferenceable(181) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %class.VmaBlockVector, ptr %5, i32 0, i32 18
  %7 = load i8, ptr %6, align 4, !tbaa !9, !range !20, !noundef !21
  %8 = trunc i8 %7 to i1
  br i1 %8, label %10, label %9

9:                                                ; preds = %1
  br label %59

10:                                               ; preds = %1
  %11 = getelementptr inbounds %class.VmaBlockVector, ptr %5, i32 0, i32 10
  %12 = load i32, ptr %11, align 4, !tbaa !22
  %13 = icmp ne i32 %12, 4
  br i1 %13, label %14, label %59

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 1, ptr %3, align 8, !tbaa !23
  br label %15

15:                                               ; preds = %53, %14
  %16 = load i64, ptr %3, align 8, !tbaa !23
  %17 = getelementptr inbounds %class.VmaBlockVector, ptr %5, i32 0, i32 16
  %18 = call noundef i64 @_ZNK9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %17)
  %19 = icmp ult i64 %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  store i32 2, ptr %4, align 4
  br label %56

21:                                               ; preds = %15
  %22 = getelementptr inbounds %class.VmaBlockVector, ptr %5, i32 0, i32 16
  %23 = load i64, ptr %3, align 8, !tbaa !23
  %24 = sub i64 %23, 1
  %25 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(32) %22, i64 noundef %24)
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds %class.VmaDeviceMemoryBlock, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !24
  %29 = load ptr, ptr %28, align 8, !tbaa !30
  %30 = getelementptr inbounds ptr, ptr %29, i64 6
  %31 = load ptr, ptr %30, align 8
  %32 = call noundef i64 %31(ptr noundef nonnull align 8 dereferenceable(33) %28)
  %33 = getelementptr inbounds %class.VmaBlockVector, ptr %5, i32 0, i32 16
  %34 = load i64, ptr %3, align 8, !tbaa !23
  %35 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(32) %33, i64 noundef %34)
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = getelementptr inbounds %class.VmaDeviceMemoryBlock, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !24
  %39 = load ptr, ptr %38, align 8, !tbaa !30
  %40 = getelementptr inbounds ptr, ptr %39, i64 6
  %41 = load ptr, ptr %40, align 8
  %42 = call noundef i64 %41(ptr noundef nonnull align 8 dereferenceable(33) %38)
  %43 = icmp ugt i64 %32, %42
  br i1 %43, label %44, label %52

44:                                               ; preds = %21
  %45 = getelementptr inbounds %class.VmaBlockVector, ptr %5, i32 0, i32 16
  %46 = load i64, ptr %3, align 8, !tbaa !23
  %47 = sub i64 %46, 1
  %48 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(32) %45, i64 noundef %47)
  %49 = getelementptr inbounds %class.VmaBlockVector, ptr %5, i32 0, i32 16
  %50 = load i64, ptr %3, align 8, !tbaa !23
  %51 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(32) %49, i64 noundef %50)
  call void @_ZSt4swapIP20VmaDeviceMemoryBlockENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS5_ESt18is_move_assignableIS5_EEE5valueEvE4typeERS5_SE_(ptr noundef nonnull align 8 dereferenceable(8) %48, ptr noundef nonnull align 8 dereferenceable(8) %51) #4
  store i32 1, ptr %4, align 4
  br label %56

52:                                               ; preds = %21
  br label %53

53:                                               ; preds = %52
  %54 = load i64, ptr %3, align 8, !tbaa !23
  %55 = add i64 %54, 1
  store i64 %55, ptr %3, align 8, !tbaa !23
  br label %15, !llvm.loop !32

56:                                               ; preds = %44, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  %57 = load i32, ptr %4, align 4
  switch i32 %57, label %60 [
    i32 2, label %58
    i32 1, label %59
  ]

58:                                               ; preds = %56
  br label %59

59:                                               ; preds = %58, %56, %10, %9
  ret void

60:                                               ; preds = %56
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIP20VmaDeviceMemoryBlockENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS5_ESt18is_move_assignableIS5_EEE5valueEvE4typeERS5_SE_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

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 = { 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 = { inlinehint 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 #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, !13, i64 180}
!10 = !{!"_ZTS14VmaBlockVector", !6, i64 0, !6, i64 8, !11, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !13, i64 56, !11, i64 60, !14, i64 64, !12, i64 72, !6, i64 80, !15, i64 88, !18, i64 144, !11, i64 176, !13, i64 180}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!"_ZTS10VmaRWMutex", !16, i64 0}
!16 = !{!"_ZTSSt12shared_mutex", !17, i64 0}
!17 = !{!"_ZTSSt22__shared_mutex_pthread", !7, i64 0}
!18 = !{!"_ZTS9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EE", !19, i64 0, !6, i64 8, !12, i64 16, !12, i64 24}
!19 = !{!"_ZTS15VmaStlAllocatorIP20VmaDeviceMemoryBlockE", !6, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!10, !11, i64 60}
!23 = !{!12, !12, i64 0}
!24 = !{!25, !6, i64 0}
!25 = !{!"_ZTS20VmaDeviceMemoryBlock", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !26, i64 32, !29, i64 72, !11, i64 84, !6, i64 88}
!26 = !{!"_ZTS8VmaMutex", !27, i64 0}
!27 = !{!"_ZTSSt5mutex", !28, i64 0}
!28 = !{!"_ZTSSt12__mutex_base", !7, i64 0}
!29 = !{!"_ZTS20VmaMappingHysteresis", !11, i64 0, !11, i64 4, !11, i64 8}
!30 = !{!31, !31, i64 0}
!31 = !{!"vtable pointer", !8, i64 0}
!32 = distinct !{!32, !33}
!33 = !{!"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 nounwind uwtable
declare dso_local noundef i64 @_ZNK9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 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 #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14VmaBlockVector23IncrementallySortBlocksEv(ptr noundef nonnull align 8 dereferenceable(181) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 180
  %3 = load i8, ptr %2, align 4, !tbaa !5, !range !19, !noundef !20
  %4 = trunc nuw i8 %3 to i1
  %5 = getelementptr inbounds i8, ptr %0, i64 60
  %6 = load i32, ptr %5, align 4
  %.not = icmp ne i32 %6, 4
  %or.cond.not = select i1 %4, i1 %.not, i1 false
  br i1 %or.cond.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 144
  %8 = tail call noundef i64 @_ZNK9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %7)
  %9 = icmp ugt i64 %8, 1
  br i1 %9, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %29
  %.011 = phi i64 [ %30, %29 ], [ 1, %.preheader ]
  %10 = add i64 %.011, -1
  %11 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(32) %7, i64 noundef %10)
  %12 = load ptr, ptr %11, align 8, !tbaa !21
  %13 = load ptr, ptr %12, align 8, !tbaa !22
  %14 = load ptr, ptr %13, align 8, !tbaa !28
  %15 = getelementptr inbounds i8, ptr %14, i64 48
  %16 = load ptr, ptr %15, align 8
  %17 = tail call noundef i64 %16(ptr noundef nonnull align 8 dereferenceable(33) %13)
  %18 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(32) %7, i64 noundef %.011)
  %19 = load ptr, ptr %18, align 8, !tbaa !21
  %20 = load ptr, ptr %19, align 8, !tbaa !22
  %21 = load ptr, ptr %20, align 8, !tbaa !28
  %22 = getelementptr inbounds i8, ptr %21, i64 48
  %23 = load ptr, ptr %22, align 8
  %24 = tail call noundef i64 %23(ptr noundef nonnull align 8 dereferenceable(33) %20)
  %25 = icmp ugt i64 %17, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %.lr.ph
  %27 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(32) %7, i64 noundef %10)
  %28 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(32) %7, i64 noundef %.011)
  tail call void @_ZSt4swapIP20VmaDeviceMemoryBlockENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS5_ESt18is_move_assignableIS5_EEE5valueEvE4typeERS5_SE_(ptr noundef nonnull align 8 dereferenceable(8) %27, ptr noundef nonnull align 8 dereferenceable(8) %28) #3
  br label %.loopexit

29:                                               ; preds = %.lr.ph
  %30 = add nuw i64 %.011, 1
  %31 = tail call noundef i64 @_ZNK9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %7)
  %32 = icmp ult i64 %30, %31
  br i1 %32, label %.lr.ph, label %.loopexit, !llvm.loop !30

.loopexit:                                        ; preds = %29, %.preheader, %26, %1
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIP20VmaDeviceMemoryBlockENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS5_ESt18is_move_assignableIS5_EEE5valueEvE4typeERS5_SE_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #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 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 = { inlinehint 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, !12, i64 180}
!6 = !{!"_ZTS14VmaBlockVector", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !12, i64 56, !10, i64 60, !13, i64 64, !11, i64 72, !7, i64 80, !14, i64 88, !17, i64 144, !10, i64 176, !12, i64 180}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = !{!"_ZTS10VmaRWMutex", !15, i64 0}
!15 = !{!"_ZTSSt12shared_mutex", !16, i64 0}
!16 = !{!"_ZTSSt22__shared_mutex_pthread", !8, i64 0}
!17 = !{!"_ZTS9VmaVectorIP20VmaDeviceMemoryBlock15VmaStlAllocatorIS1_EE", !18, i64 0, !7, i64 8, !11, i64 16, !11, i64 24}
!18 = !{!"_ZTS15VmaStlAllocatorIP20VmaDeviceMemoryBlockE", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!7, !7, i64 0}
!22 = !{!23, !7, i64 0}
!23 = !{!"_ZTS20VmaDeviceMemoryBlock", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !7, i64 24, !24, i64 32, !27, i64 72, !10, i64 84, !7, i64 88}
!24 = !{!"_ZTS8VmaMutex", !25, i64 0}
!25 = !{!"_ZTSSt5mutex", !26, i64 0}
!26 = !{!"_ZTSSt12__mutex_base", !8, i64 0}
!27 = !{!"_ZTS20VmaMappingHysteresis", !10, i64 0, !10, i64 4, !10, i64 8}
!28 = !{!29, !29, i64 0}
!29 = !{!"vtable pointer", !9, i64 0}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}


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