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

; 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.2 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [9 x i8], align 1
@__PRETTY_FUNCTION__._ZN13VmaJsonWriter10BeginValueEb = external hidden unnamed_addr constant [37 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.20 = 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13VmaJsonWriter10BeginValueEb(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 ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = zext i1 %1 to i8
  store i8 %6, ptr %4, align 1, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %class.VmaJsonWriter, ptr %7, i32 0, i32 1
  %9 = call noundef zeroext i1 @_ZNK9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32) %8)
  br i1 %9, label %59, label %10

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %11 = getelementptr inbounds %class.VmaJsonWriter, ptr %7, i32 0, i32 1
  %12 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE4backEv(ptr noundef nonnull align 8 dereferenceable(32) %11)
  store ptr %12, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.VmaJsonWriter::StackItem", ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %30

17:                                               ; preds = %10
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.VmaJsonWriter::StackItem", ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !15
  %21 = urem i32 %20, 2
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %30

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

26:                                               ; preds = %23
  br label %29

27:                                               ; preds = %23
  call void @__assert_fail(ptr noundef @.str.18, ptr noundef @.str.2, i32 noundef 5814, ptr noundef @__PRETTY_FUNCTION__._ZN13VmaJsonWriter10BeginValueEb) #5
  unreachable

28:                                               ; No predecessors!
  br label %29

29:                                               ; preds = %28, %26
  br label %30

30:                                               ; preds = %29, %17, %10
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.VmaJsonWriter::StackItem", ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %44

35:                                               ; preds = %30
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.VmaJsonWriter::StackItem", ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !15
  %39 = urem i32 %38, 2
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %35
  %42 = getelementptr inbounds %class.VmaJsonWriter, ptr %7, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !18
  call void @_ZN16VmaStringBuilder3AddEPKc(ptr noundef nonnull align 8 dereferenceable(32) %43, ptr noundef @.str.19)
  br label %54

44:                                               ; preds = %35, %30
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.VmaJsonWriter::StackItem", ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !15
  %48 = icmp ugt i32 %47, 0
  br i1 %48, label %49, label %52

49:                                               ; preds = %44
  %50 = getelementptr inbounds %class.VmaJsonWriter, ptr %7, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  call void @_ZN16VmaStringBuilder3AddEPKc(ptr noundef nonnull align 8 dereferenceable(32) %51, ptr noundef @.str.20)
  call void @_ZN13VmaJsonWriter11WriteIndentEb(ptr noundef nonnull align 8 dereferenceable(41) %7, i1 noundef zeroext false)
  br label %53

52:                                               ; preds = %44
  call void @_ZN13VmaJsonWriter11WriteIndentEb(ptr noundef nonnull align 8 dereferenceable(41) %7, i1 noundef zeroext false)
  br label %53

53:                                               ; preds = %52, %49
  br label %54

54:                                               ; preds = %53, %41
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %"struct.VmaJsonWriter::StackItem", ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !15
  %58 = add i32 %57, 1
  store i32 %58, ptr %56, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %59

59:                                               ; preds = %54, %2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13VmaJsonWriter11WriteIndentEb(ptr noundef nonnull align 8 dereferenceable(41), i1 noundef zeroext) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZN9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE4backEv(ptr noundef nonnull align 8 dereferenceable(32)) #3 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 = { 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 #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 = !{!"bool", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN13VmaJsonWriter9StackItemE", !13, i64 0, !14, i64 4, !10, i64 8}
!13 = !{!"_ZTSN13VmaJsonWriter15COLLECTION_TYPEE", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !14, i64 4}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!19, !6, i64 0}
!19 = !{!"_ZTS13VmaJsonWriter", !6, i64 0, !20, i64 8, !10, i64 40}
!20 = !{!"_ZTS9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE", !21, i64 0, !6, i64 8, !22, i64 16, !22, i64 24}
!21 = !{!"_ZTS15VmaStlAllocatorIN13VmaJsonWriter9StackItemEE", !6, i64 0}
!22 = !{!"long", !7, i64 0}


; 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.18 = external hidden unnamed_addr constant [9 x i8], align 1
@__PRETTY_FUNCTION__._ZN13VmaJsonWriter10BeginValueEb = external hidden unnamed_addr constant [37 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.20 = 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13VmaJsonWriter10BeginValueEb(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 %25, 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 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 0
  %9 = getelementptr inbounds i8, ptr %6, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !12
  br i1 %8, label %11, label %._crit_edge

11:                                               ; preds = %5
  %12 = and i32 %10, 1
  %13 = icmp ne i32 %12, 0
  %brmerge = or i1 %13, %1
  br i1 %brmerge, label %15, label %14

14:                                               ; preds = %11
  tail call void @__assert_fail(ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.2, i32 noundef 5814, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN13VmaJsonWriter10BeginValueEb) #3
  unreachable

15:                                               ; preds = %11
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %._crit_edge, label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %0, align 8, !tbaa !13
  tail call void @_ZN16VmaStringBuilder3AddEPKc(ptr noundef nonnull align 8 dereferenceable(32) %17, ptr noundef nonnull @.str.19)
  br label %21

._crit_edge:                                      ; preds = %5, %15
  %.not7 = icmp eq i32 %10, 0
  br i1 %.not7, label %20, label %18

18:                                               ; preds = %._crit_edge
  %19 = load ptr, ptr %0, align 8, !tbaa !13
  tail call void @_ZN16VmaStringBuilder3AddEPKc(ptr noundef nonnull align 8 dereferenceable(32) %19, ptr noundef nonnull @.str.20)
  tail call void @_ZN13VmaJsonWriter11WriteIndentEb(ptr noundef nonnull align 8 dereferenceable(41) %0, i1 noundef zeroext false)
  br label %21

20:                                               ; preds = %._crit_edge
  tail call void @_ZN13VmaJsonWriter11WriteIndentEb(ptr noundef nonnull align 8 dereferenceable(41) %0, i1 noundef zeroext false)
  br label %21

21:                                               ; preds = %18, %20, %16
  %22 = getelementptr inbounds i8, ptr %6, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = add i32 %23, 1
  store i32 %24, ptr %22, align 4, !tbaa !12
  br label %25

25:                                               ; preds = %21, %2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13VmaJsonWriter11WriteIndentEb(ptr noundef nonnull align 8 dereferenceable(41), i1 noundef zeroext) local_unnamed_addr #0 align 2

; 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 #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 = { 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 = { 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 = !{!"_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 = !{!6, !10, i64 4}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTS13VmaJsonWriter", !15, i64 0, !16, i64 8, !11, i64 40}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!"_ZTS9VmaVectorIN13VmaJsonWriter9StackItemE15VmaStlAllocatorIS1_EE", !17, i64 0, !15, i64 8, !18, i64 16, !18, i64 24}
!17 = !{!"_ZTS15VmaStlAllocatorIN13VmaJsonWriter9StackItemEE", !15, i64 0}
!18 = !{!"long", !8, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass