; 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.VmaMutexLockRead = type { ptr }
%class.VmaDedicatedAllocationList = type { i8, %class.VmaRWMutex, %class.VmaIntrusiveLinkedList }
%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.VmaIntrusiveLinkedList = type { ptr, ptr, i64 }

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [58 x i8], align 1
@__PRETTY_FUNCTION__._ZN26VmaDedicatedAllocationList8ValidateEv = external hidden unnamed_addr constant [44 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN26VmaDedicatedAllocationList8ValidateEv(ptr noundef nonnull align 8 dereferenceable(88) %0) #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca %struct.VmaMutexLockRead, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %10 = getelementptr inbounds %class.VmaDedicatedAllocationList, ptr %9, i32 0, i32 2
  %11 = call noundef i64 @_ZNK22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %10)
  store i64 %11, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %12 = getelementptr inbounds %class.VmaDedicatedAllocationList, ptr %9, i32 0, i32 1
  %13 = getelementptr inbounds %class.VmaDedicatedAllocationList, ptr %9, i32 0, i32 0
  %14 = load i8, ptr %13, align 8, !tbaa !11, !range !18, !noundef !19
  %15 = trunc i8 %14 to i1
  call void @_ZN16VmaMutexLockReadC2ER10VmaRWMutexb(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(56) %12, i1 noundef zeroext %15)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %16 = getelementptr inbounds %class.VmaDedicatedAllocationList, ptr %9, i32 0, i32 2
  %17 = invoke noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE5FrontEv(ptr noundef nonnull align 8 dereferenceable(24) %16)
          to label %18 unwind label %23

18:                                               ; preds = %1
  store ptr %17, ptr %6, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %34, %18
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %27, label %22

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

23:                                               ; preds = %30, %1
  %24 = landingpad { ptr, i32 }
          cleanup
  %25 = extractvalue { ptr, i32 } %24, 0
  store ptr %25, ptr %7, align 8
  %26 = extractvalue { ptr, i32 } %24, 1
  store i32 %26, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @_ZN16VmaMutexLockReadD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %44

27:                                               ; preds = %19
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = add i64 %28, 1
  store i64 %29, ptr %4, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %27
  %31 = getelementptr inbounds %class.VmaDedicatedAllocationList, ptr %9, i32 0, i32 2
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = invoke noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE7GetNextEPK15VmaAllocation_T(ptr noundef %32)
          to label %34 unwind label %23

34:                                               ; preds = %30
  store ptr %33, ptr %6, align 8, !tbaa !5
  br label %19, !llvm.loop !20

35:                                               ; preds = %22
  br label %36

36:                                               ; preds = %35
  %37 = load i64, ptr %4, align 8, !tbaa !9
  %38 = load i64, ptr %3, align 8, !tbaa !9
  %39 = icmp eq i64 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  call void @__assert_fail(ptr noundef @.str.22, ptr noundef @.str.2, i32 noundef 6270, ptr noundef @__PRETTY_FUNCTION__._ZN26VmaDedicatedAllocationList8ValidateEv) #5
  unreachable

41:                                               ; preds = %36
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  call void @_ZN16VmaMutexLockReadD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret i1 true

44:                                               ; preds = %23
  %45 = load ptr, ptr %7, align 8
  %46 = load i32, ptr %8, align 4
  %47 = insertvalue { ptr, i32 } poison, ptr %45, 0
  %48 = insertvalue { ptr, i32 } %47, i32 %46, 1
  resume { ptr, i32 } %48
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN16VmaMutexLockReadC2ER10VmaRWMutexb(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(56), i1 noundef zeroext) unnamed_addr #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE7GetNextEPK15VmaAllocation_T(ptr noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN16VmaMutexLockReadD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 2

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 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 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 }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS26VmaDedicatedAllocationList", !13, i64 0, !14, i64 8, !17, i64 64}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTS10VmaRWMutex", !15, i64 0}
!15 = !{!"_ZTSSt12shared_mutex", !16, i64 0}
!16 = !{!"_ZTSSt22__shared_mutex_pthread", !7, i64 0}
!17 = !{!"_ZTS22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE", !6, i64 0, !6, i64 8, !10, i64 16}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = distinct !{!20, !21}
!21 = !{!"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"

%struct.VmaMutexLockRead = type { ptr }

@.str.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [58 x i8], align 1
@__PRETTY_FUNCTION__._ZN26VmaDedicatedAllocationList8ValidateEv = external hidden unnamed_addr constant [44 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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) local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN26VmaDedicatedAllocationList8ValidateEv(ptr noundef nonnull align 8 dereferenceable(88) %0) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %struct.VmaMutexLockRead, align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 64
  %4 = tail call noundef i64 @_ZNK22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i8, ptr %0, align 8, !tbaa !5, !range !16, !noundef !17
  %7 = trunc nuw i8 %6 to i1
  call void @_ZN16VmaMutexLockReadC2ER10VmaRWMutexb(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(56) %5, i1 noundef zeroext %7)
  %8 = call noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE5FrontEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not9 = icmp eq ptr %8, null
  br i1 %.not9, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %13, %1
  %.0.lcssa = phi i64 [ 0, %1 ], [ %14, %13 ]
  %9 = icmp eq i64 %.0.lcssa, %4
  br i1 %9, label %16, label %15

10:                                               ; preds = %.lr.ph
  %11 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN16VmaMutexLockReadD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  resume { ptr, i32 } %11

.lr.ph:                                           ; preds = %1, %13
  %.011 = phi i64 [ %14, %13 ], [ 0, %1 ]
  %.0710 = phi ptr [ %12, %13 ], [ %8, %1 ]
  %12 = invoke noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE7GetNextEPK15VmaAllocation_T(ptr noundef nonnull %.0710)
          to label %13 unwind label %10

13:                                               ; preds = %.lr.ph
  %14 = add i64 %.011, 1
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

15:                                               ; preds = %._crit_edge
  call void @__assert_fail(ptr noundef nonnull @.str.22, ptr noundef nonnull @.str.2, i32 noundef 6270, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN26VmaDedicatedAllocationList8ValidateEv) #5
  unreachable

16:                                               ; preds = %._crit_edge
  call void @_ZN16VmaMutexLockReadD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret i1 true
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN16VmaMutexLockReadC2ER10VmaRWMutexb(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(56), i1 noundef zeroext) unnamed_addr #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE7GetNextEPK15VmaAllocation_T(ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN16VmaMutexLockReadD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 2

attributes #0 = { mustprogress 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 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 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 }
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, !7, i64 0}
!6 = !{!"_ZTS26VmaDedicatedAllocationList", !7, i64 0, !10, i64 8, !13, i64 64}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS10VmaRWMutex", !11, i64 0}
!11 = !{!"_ZTSSt12shared_mutex", !12, i64 0}
!12 = !{!"_ZTSSt22__shared_mutex_pthread", !8, i64 0}
!13 = !{!"_ZTS22VmaIntrusiveLinkedListI36VmaDedicatedAllocationListItemTraitsE", !14, i64 0, !14, i64 8, !15, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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