; 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.VmaJsonWriter = type <{ ptr, %class.VmaVector.0, i8, [7 x i8] }>
%class.VmaVector.0 = type { %struct.VmaStlAllocator.1, ptr, i64, i64 }
%struct.VmaStlAllocator.1 = type { ptr }
%"struct.VmaJsonWriter::StackItem" = type { i32, i32, i8 }

@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN16VmaStringBuilder3AddEPKc(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) #0 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13VmaJsonWriter11WriteIndentEb(ptr noundef nonnull align 8 dereferenceable(41) %0, i1 noundef zeroext %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = zext i1 %1 to i8
  store i8 %7, ptr %4, align 1, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %class.VmaJsonWriter, ptr %8, i32 0, i32 1
  %10 = call noundef zeroext i1 @_ZNK9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32) %9)
  br i1 %10, label %43, label %11

11:                                               ; preds = %2
  %12 = getelementptr inbounds %class.VmaJsonWriter, ptr %8, i32 0, i32 1
  %13 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE4backEv(ptr noundef nonnull align 8 dereferenceable(32) %12)
  %14 = getelementptr inbounds %"struct.VmaJsonWriter::StackItem", ptr %13, i32 0, i32 2
  %15 = load i8, ptr %14, align 4, !tbaa !11, !range !15, !noundef !16
  %16 = trunc i8 %15 to i1
  br i1 %16, label %43, label %17

17:                                               ; preds = %11
  %18 = getelementptr inbounds %class.VmaJsonWriter, ptr %8, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  call void @_ZN16VmaStringBuilder10AddNewLineEv(ptr noundef nonnull align 8 dereferenceable(32) %19)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %20 = getelementptr inbounds %class.VmaJsonWriter, ptr %8, i32 0, i32 1
  %21 = call noundef i64 @_ZNK9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %20)
  store i64 %21, ptr %5, align 8, !tbaa !22
  %22 = load i64, ptr %5, align 8, !tbaa !22
  %23 = icmp ugt i64 %22, 0
  br i1 %23, label %24, label %30

24:                                               ; preds = %17
  %25 = load i8, ptr %4, align 1, !tbaa !9, !range !15, !noundef !16
  %26 = trunc i8 %25 to i1
  br i1 %26, label %27, label %30

27:                                               ; preds = %24
  %28 = load i64, ptr %5, align 8, !tbaa !22
  %29 = add i64 %28, -1
  store i64 %29, ptr %5, align 8, !tbaa !22
  br label %30

30:                                               ; preds = %27, %24, %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !22
  br label %31

31:                                               ; preds = %39, %30
  %32 = load i64, ptr %6, align 8, !tbaa !22
  %33 = load i64, ptr %5, align 8, !tbaa !22
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %36, label %35

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

36:                                               ; preds = %31
  %37 = getelementptr inbounds %class.VmaJsonWriter, ptr %8, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  call void @_ZN16VmaStringBuilder3AddEPKc(ptr noundef nonnull align 8 dereferenceable(32) %38, ptr noundef @.str)
  br label %39

39:                                               ; preds = %36
  %40 = load i64, ptr %6, align 8, !tbaa !22
  %41 = add i64 %40, 1
  store i64 %41, ptr %6, align 8, !tbaa !22
  br label %31, !llvm.loop !23

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

43:                                               ; preds = %42, %11, %2
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZN9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE4backEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN16VmaStringBuilder10AddNewLineEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"bool", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTSN13VmaJsonWriter9StackItemE", !13, i64 0, !14, i64 4, !10, i64 8}
!13 = !{!"_ZTSN13VmaJsonWriter15COLLECTION_TYPEE", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !6, i64 0}
!18 = !{!"_ZTS13VmaJsonWriter", !6, i64 0, !19, i64 8, !10, i64 40}
!19 = !{!"_ZTS9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE", !20, i64 0, !6, i64 8, !21, i64 16, !21, i64 24}
!20 = !{!"_ZTS15VmaStlAllocatorIN13VmaJsonWriter9StackItemEE", !6, i64 0}
!21 = !{!"long", !7, i64 0}
!22 = !{!21, !21, i64 0}
!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 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN16VmaStringBuilder3AddEPKc(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13VmaJsonWriter11WriteIndentEb(ptr noundef nonnull align 8 dereferenceable(41) %0, i1 noundef zeroext %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = tail call noundef zeroext i1 @_ZNK9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32) %3)
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %2
  %6 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZN9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE4backEv(ptr noundef nonnull align 8 dereferenceable(32) %3)
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load i8, ptr %7, align 4, !tbaa !5, !range !12, !noundef !13
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %5
  %11 = load ptr, ptr %0, align 8, !tbaa !14
  tail call void @_ZN16VmaStringBuilder10AddNewLineEv(ptr noundef nonnull align 8 dereferenceable(32) %11)
  %12 = tail call noundef i64 @_ZNK9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %3)
  %.not = icmp ne i64 %12, 0
  %13 = sext i1 %1 to i64
  %spec.select = add i64 %12, %13
  %14 = icmp ne i64 %spec.select, 0
  %15 = and i1 %.not, %14
  br i1 %15, label %.lr.ph.split, label %.loopexit

.lr.ph.split:                                     ; preds = %10, %.lr.ph.split
  %.08 = phi i64 [ %17, %.lr.ph.split ], [ 0, %10 ]
  %16 = load ptr, ptr %0, align 8, !tbaa !14
  tail call void @_ZN16VmaStringBuilder3AddEPKc(ptr noundef nonnull align 8 dereferenceable(32) %16, ptr noundef nonnull @.str)
  %17 = add nuw i64 %.08, 1
  %exitcond.not = icmp eq i64 %17, %spec.select
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph.split, !llvm.loop !20

.loopexit:                                        ; preds = %.lr.ph.split, %10, %5, %2
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZN9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE4backEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN16VmaStringBuilder10AddNewLineEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

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

attributes #0 = { 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 #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" }

!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 8}
!6 = !{!"_ZTSN13VmaJsonWriter9StackItemE", !7, i64 0, !10, i64 4, !11, i64 8}
!7 = !{!"_ZTSN13VmaJsonWriter15COLLECTION_TYPEE", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!15, !16, i64 0}
!15 = !{!"_ZTS13VmaJsonWriter", !16, i64 0, !17, i64 8, !11, i64 40}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"_ZTS9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE", !18, i64 0, !16, i64 8, !19, i64 16, !19, i64 24}
!18 = !{!"_ZTS15VmaStlAllocatorIN13VmaJsonWriter9StackItemEE", !16, i64 0}
!19 = !{!"long", !8, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass