; LLVM IR from vczh/herodb :: Kernel/Source/Vlpp.ll (ZN2vl7parsing13ParsingWriter11WriteStringEPKwl)

; 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.vl::parsing::ParsingWriter" = type { %"class.vl::stream::TextWriter", ptr, %"class.vl::Ptr.684", i64, %"struct.vl::parsing::ParsingTextPos", %"struct.vl::parsing::ParsingTextPos", %"class.vl::collections::List.707" }
%"class.vl::stream::TextWriter" = type { %"class.vl::Object" }
%"class.vl::Object" = type { ptr }
%"class.vl::Ptr.684" = type { ptr, ptr, ptr, ptr }
%"struct.vl::parsing::ParsingTextPos" = type { i64, i64, i64 }
%"class.vl::collections::List.707" = type { %"class.vl::collections::ListBase.base.713", %"class.vl::collections::IEnumerable.711" }
%"class.vl::collections::ListBase.base.713" = type <{ %"class.vl::collections::ArrayBase.base.712", i64, i8 }>
%"class.vl::collections::ArrayBase.base.712" = type { %"class.vl::collections::ListStore.710", ptr, i64 }
%"class.vl::collections::ListStore.710" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable.711" = type { %"class.vl::Interface" }
%"class.vl::Interface" = type { ptr }

; 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 void @_ZN2vl7parsing13ParsingWriter10HandleCharEw(ptr noundef nonnull align 8 dereferenceable(152), i32 noundef signext) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2vl7parsing13ParsingWriter11WriteStringEPKwl(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %"class.vl::parsing::ParsingWriter", ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = load ptr, ptr %10, align 8, !tbaa !22
  %14 = getelementptr inbounds ptr, ptr %13, i64 3
  %15 = load ptr, ptr %14, align 8
  call void %15(ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef %11, i64 noundef %12)
  %16 = getelementptr inbounds %"class.vl::parsing::ParsingWriter", ptr %8, i32 0, i32 2
  %17 = call noundef zeroext i1 @_ZNK2vl3PtrINS_7parsing25IParsingPrintNodeRecorderEEcvbEv(ptr noundef nonnull align 8 dereferenceable(32) %16)
  br i1 %17, label %19, label %18

18:                                               ; preds = %3
  br label %33

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %30, %19
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = icmp slt i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %33

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = getelementptr inbounds i32, ptr %26, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !24
  call void @_ZN2vl7parsing13ParsingWriter10HandleCharEw(ptr noundef nonnull align 8 dereferenceable(152) %8, i32 noundef signext %29)
  br label %30

30:                                               ; preds = %25
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = add nsw i64 %31, 1
  store i64 %32, ptr %7, align 8, !tbaa !9
  br label %20, !llvm.loop !26

33:                                               ; preds = %24, %18
  ret void
}

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 = { 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, !6, i64 8}
!12 = !{!"_ZTSN2vl7parsing13ParsingWriterE", !13, i64 0, !6, i64 8, !15, i64 16, !10, i64 48, !16, i64 56, !16, i64 80, !17, i64 104}
!13 = !{!"_ZTSN2vl6stream10TextWriterE", !14, i64 0}
!14 = !{!"_ZTSN2vl6ObjectE"}
!15 = !{!"_ZTSN2vl3PtrINS_7parsing25IParsingPrintNodeRecorderEEE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!"_ZTSN2vl7parsing14ParsingTextPosE", !10, i64 0, !10, i64 8, !10, i64 16}
!17 = !{!"_ZTSN2vl11collections4ListINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEES7_EE", !18, i64 0}
!18 = !{!"_ZTSN2vl11collections8ListBaseINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEES7_EE", !19, i64 0, !10, i64 24, !21, i64 32}
!19 = !{!"_ZTSN2vl11collections9ArrayBaseINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEEEE", !20, i64 0, !6, i64 8, !10, i64 16}
!20 = !{!"_ZTSN2vl11collections9ListStoreINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEELb0EEE", !14, i64 0}
!21 = !{!"bool", !7, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !8, i64 0}
!24 = !{!25, !25, i64 0}
!25 = !{!"wchar_t", !7, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"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 void @_ZN2vl7parsing13ParsingWriter10HandleCharEw(ptr noundef nonnull align 8 dereferenceable(152), i32 noundef signext) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2vl7parsing13ParsingWriter11WriteStringEPKwl(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %5, align 8, !tbaa !20
  %7 = getelementptr inbounds i8, ptr %6, i64 24
  %8 = load ptr, ptr %7, align 8
  tail call void %8(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef %1, i64 noundef %2)
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = tail call noundef zeroext i1 @_ZNK2vl3PtrINS_7parsing25IParsingPrintNodeRecorderEEcvbEv(ptr noundef nonnull align 8 dereferenceable(32) %9)
  %11 = icmp sgt i64 %2, 0
  %or.cond = and i1 %10, %11
  br i1 %or.cond, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.07 = phi i64 [ %14, %.lr.ph ], [ 0, %3 ]
  %12 = getelementptr inbounds i32, ptr %1, i64 %.07
  %13 = load i32, ptr %12, align 4, !tbaa !22
  tail call void @_ZN2vl7parsing13ParsingWriter10HandleCharEw(ptr noundef nonnull align 8 dereferenceable(152) %0, i32 noundef signext %13)
  %14 = add nuw nsw i64 %.07, 1
  %exitcond.not = icmp eq i64 %14, %2
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !24

.loopexit:                                        ; preds = %.lr.ph, %3
  ret void
}

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" }

!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, !9, i64 8}
!6 = !{!"_ZTSN2vl7parsing13ParsingWriterE", !7, i64 0, !9, i64 8, !12, i64 16, !13, i64 48, !14, i64 56, !14, i64 80, !15, i64 104}
!7 = !{!"_ZTSN2vl6stream10TextWriterE", !8, i64 0}
!8 = !{!"_ZTSN2vl6ObjectE"}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTSN2vl3PtrINS_7parsing25IParsingPrintNodeRecorderEEE", !9, i64 0, !9, i64 8, !9, i64 16, !9, i64 24}
!13 = !{!"long", !10, i64 0}
!14 = !{!"_ZTSN2vl7parsing14ParsingTextPosE", !13, i64 0, !13, i64 8, !13, i64 16}
!15 = !{!"_ZTSN2vl11collections4ListINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEES7_EE", !16, i64 0}
!16 = !{!"_ZTSN2vl11collections8ListBaseINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEES7_EE", !17, i64 0, !13, i64 24, !19, i64 32}
!17 = !{!"_ZTSN2vl11collections9ArrayBaseINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEEEE", !18, i64 0, !9, i64 8, !13, i64 16}
!18 = !{!"_ZTSN2vl11collections9ListStoreINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEELb0EEE", !8, i64 0}
!19 = !{!"bool", !10, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"vtable pointer", !11, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"wchar_t", !10, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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