; LLVM IR from khushmmehta/Scorch-V :: src/ScorchVkEngine/Abstractions/VulkanMemoryAllocator.ll (ZN20VmaCurrentBudgetDataC2Ev)

; 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.VmaCurrentBudgetData = type { [16 x %"struct.std::atomic"], [16 x %"struct.std::atomic"], [16 x %"struct.std::atomic.9"], [16 x %"struct.std::atomic.9"], %"struct.std::atomic", %class.VmaRWMutex, [16 x i64], [16 x i64], [16 x i64] }
%"struct.std::atomic.9" = type { %"struct.std::__atomic_base.10" }
%"struct.std::__atomic_base.10" = type { i64 }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%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 }

; 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
define dso_local void @_ZN20VmaCurrentBudgetDataC2Ev(ptr noundef nonnull align 8 dereferenceable(832) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 0
  %6 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 1
  %7 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 2
  %8 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 3
  %9 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 4
  %10 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 5
  call void @_ZN10VmaRWMutexC2Ev(ptr noundef nonnull align 8 dereferenceable(56) %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %48, %1
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = icmp ult i32 %12, 16
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %11
  %16 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 0
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds [16 x %"struct.std::atomic"], ptr %16, i64 0, i64 %18
  %20 = call noundef i32 @_ZNSt13__atomic_baseIjEaSEj(ptr noundef nonnull align 4 dereferenceable(4) %19, i32 noundef 0) #3
  %21 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 1
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds [16 x %"struct.std::atomic"], ptr %21, i64 0, i64 %23
  %25 = call noundef i32 @_ZNSt13__atomic_baseIjEaSEj(ptr noundef nonnull align 4 dereferenceable(4) %24, i32 noundef 0) #3
  %26 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 2
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds [16 x %"struct.std::atomic.9"], ptr %26, i64 0, i64 %28
  %30 = call noundef i64 @_ZNSt13__atomic_baseImEaSEm(ptr noundef nonnull align 8 dereferenceable(8) %29, i64 noundef 0) #3
  %31 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 3
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [16 x %"struct.std::atomic.9"], ptr %31, i64 0, i64 %33
  %35 = call noundef i64 @_ZNSt13__atomic_baseImEaSEm(ptr noundef nonnull align 8 dereferenceable(8) %34, i64 noundef 0) #3
  %36 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 6
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds [16 x i64], ptr %36, i64 0, i64 %38
  store i64 0, ptr %39, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 7
  %41 = load i32, ptr %3, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds [16 x i64], ptr %40, i64 0, i64 %42
  store i64 0, ptr %43, align 8, !tbaa !11
  %44 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 8
  %45 = load i32, ptr %3, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds [16 x i64], ptr %44, i64 0, i64 %46
  store i64 0, ptr %47, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %15
  %49 = load i32, ptr %3, align 4, !tbaa !9
  %50 = add i32 %49, 1
  store i32 %50, ptr %3, align 4, !tbaa !9
  br label %11, !llvm.loop !13

51:                                               ; preds = %14
  %52 = getelementptr inbounds %struct.VmaCurrentBudgetData, ptr %4, i32 0, i32 4
  %53 = call noundef i32 @_ZNSt13__atomic_baseIjEaSEj(ptr noundef nonnull align 4 dereferenceable(4) %52, i32 noundef 0) #3
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt13__atomic_baseIjEaSEj(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #1 align 2

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

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 = { 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, !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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"struct.std::atomic.9" = type { %"struct.std::__atomic_base.10" }
%"struct.std::__atomic_base.10" = type { i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN20VmaCurrentBudgetDataC2Ev(ptr noundef nonnull align 8 dereferenceable(832) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 392
  tail call void @_ZN10VmaRWMutexC2Ev(ptr noundef nonnull align 8 dereferenceable(56) %2) #2
  %3 = getelementptr inbounds i8, ptr %0, i64 64
  %4 = getelementptr inbounds i8, ptr %0, i64 128
  %5 = getelementptr inbounds i8, ptr %0, i64 256
  %6 = getelementptr inbounds i8, ptr %0, i64 448
  %7 = getelementptr inbounds i8, ptr %0, i64 576
  %8 = getelementptr inbounds i8, ptr %0, i64 704
  br label %12

9:                                                ; preds = %12
  %10 = getelementptr inbounds i8, ptr %0, i64 384
  %11 = tail call noundef i32 @_ZNSt13__atomic_baseIjEaSEj(ptr noundef nonnull align 4 dereferenceable(4) %10, i32 noundef 0) #2
  ret void

12:                                               ; preds = %1, %12
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %12 ]
  %13 = getelementptr inbounds [16 x %"struct.std::atomic"], ptr %0, i64 0, i64 %indvars.iv
  %14 = tail call noundef i32 @_ZNSt13__atomic_baseIjEaSEj(ptr noundef nonnull align 4 dereferenceable(4) %13, i32 noundef 0) #2
  %15 = getelementptr inbounds [16 x %"struct.std::atomic"], ptr %3, i64 0, i64 %indvars.iv
  %16 = tail call noundef i32 @_ZNSt13__atomic_baseIjEaSEj(ptr noundef nonnull align 4 dereferenceable(4) %15, i32 noundef 0) #2
  %17 = getelementptr inbounds [16 x %"struct.std::atomic.9"], ptr %4, i64 0, i64 %indvars.iv
  %18 = tail call noundef i64 @_ZNSt13__atomic_baseImEaSEm(ptr noundef nonnull align 8 dereferenceable(8) %17, i64 noundef 0) #2
  %19 = getelementptr inbounds [16 x %"struct.std::atomic.9"], ptr %5, i64 0, i64 %indvars.iv
  %20 = tail call noundef i64 @_ZNSt13__atomic_baseImEaSEm(ptr noundef nonnull align 8 dereferenceable(8) %19, i64 noundef 0) #2
  %21 = getelementptr inbounds [16 x i64], ptr %6, i64 0, i64 %indvars.iv
  store i64 0, ptr %21, align 8, !tbaa !5
  %22 = getelementptr inbounds [16 x i64], ptr %7, i64 0, i64 %indvars.iv
  store i64 0, ptr %22, align 8, !tbaa !5
  %23 = getelementptr inbounds [16 x i64], ptr %8, i64 0, i64 %indvars.iv
  store i64 0, ptr %23, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 16
  br i1 %exitcond.not, label %9, label %12, !llvm.loop !9
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN10VmaRWMutexC2Ev(ptr noundef nonnull align 8 dereferenceable(56)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt13__atomic_baseIjEaSEj(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNSt13__atomic_baseImEaSEm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #0 align 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 = { 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 #2 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass