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

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2vl7parsing13ParsingWriter10HandleCharEw(ptr noundef nonnull align 8 dereferenceable(152) %0, i32 noundef signext %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %"class.vl::parsing::ParsingWriter", ptr %5, i32 0, i32 5
  %7 = getelementptr inbounds %"class.vl::parsing::ParsingWriter", ptr %5, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %6, i64 24, i1 false), !tbaa.struct !11
  %8 = load i32, ptr %4, align 4, !tbaa !9
  switch i32 %8, label %20 [
    i32 10, label %9
  ]

9:                                                ; preds = %2
  %10 = getelementptr inbounds %"class.vl::parsing::ParsingWriter", ptr %5, i32 0, i32 5
  %11 = getelementptr inbounds %"struct.vl::parsing::ParsingTextPos", ptr %10, i32 0, i32 0
  %12 = load i64, ptr %11, align 8, !tbaa !14
  %13 = add nsw i64 %12, 1
  store i64 %13, ptr %11, align 8, !tbaa !14
  %14 = getelementptr inbounds %"class.vl::parsing::ParsingWriter", ptr %5, i32 0, i32 5
  %15 = getelementptr inbounds %"struct.vl::parsing::ParsingTextPos", ptr %14, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !25
  %17 = add nsw i64 %16, 1
  store i64 %17, ptr %15, align 8, !tbaa !25
  %18 = getelementptr inbounds %"class.vl::parsing::ParsingWriter", ptr %5, i32 0, i32 5
  %19 = getelementptr inbounds %"struct.vl::parsing::ParsingTextPos", ptr %18, i32 0, i32 2
  store i64 0, ptr %19, align 8, !tbaa !26
  br label %29

20:                                               ; preds = %2
  %21 = getelementptr inbounds %"class.vl::parsing::ParsingWriter", ptr %5, i32 0, i32 5
  %22 = getelementptr inbounds %"struct.vl::parsing::ParsingTextPos", ptr %21, i32 0, i32 0
  %23 = load i64, ptr %22, align 8, !tbaa !14
  %24 = add nsw i64 %23, 1
  store i64 %24, ptr %22, align 8, !tbaa !14
  %25 = getelementptr inbounds %"class.vl::parsing::ParsingWriter", ptr %5, i32 0, i32 5
  %26 = getelementptr inbounds %"struct.vl::parsing::ParsingTextPos", ptr %25, i32 0, i32 2
  %27 = load i64, ptr %26, align 8, !tbaa !26
  %28 = add nsw i64 %27, 1
  store i64 %28, ptr %26, align 8, !tbaa !26
  br label %29

29:                                               ; preds = %20, %9
  ret void
}

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

!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 = !{!"wchar_t", !7, i64 0}
!11 = !{i64 0, i64 8, !12, i64 8, i64 8, !12, i64 16, i64 8, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !13, i64 80}
!15 = !{!"_ZTSN2vl7parsing13ParsingWriterE", !16, i64 0, !6, i64 8, !18, i64 16, !13, i64 48, !19, i64 56, !19, i64 80, !20, i64 104}
!16 = !{!"_ZTSN2vl6stream10TextWriterE", !17, i64 0}
!17 = !{!"_ZTSN2vl6ObjectE"}
!18 = !{!"_ZTSN2vl3PtrINS_7parsing25IParsingPrintNodeRecorderEEE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!19 = !{!"_ZTSN2vl7parsing14ParsingTextPosE", !13, i64 0, !13, i64 8, !13, i64 16}
!20 = !{!"_ZTSN2vl11collections4ListINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEES7_EE", !21, i64 0}
!21 = !{!"_ZTSN2vl11collections8ListBaseINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEES7_EE", !22, i64 0, !13, i64 24, !24, i64 32}
!22 = !{!"_ZTSN2vl11collections9ArrayBaseINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEEEE", !23, i64 0, !6, i64 8, !13, i64 16}
!23 = !{!"_ZTSN2vl11collections9ListStoreINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEELb0EEE", !17, i64 0}
!24 = !{!"bool", !7, i64 0}
!25 = !{!15, !13, i64 88}
!26 = !{!15, !13, i64 96}


; 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 nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN2vl7parsing13ParsingWriter10HandleCharEw(ptr nocapture noundef nonnull align 8 dereferenceable(152) %0, i32 noundef signext %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 80
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(24) %3, i64 24, i1 false), !tbaa.struct !5
  %cond = icmp eq i32 %1, 10
  %5 = load i64, ptr %3, align 8, !tbaa !10
  %6 = add nsw i64 %5, 1
  store i64 %6, ptr %3, align 8, !tbaa !10
  br i1 %cond, label %7, label %12

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 88
  %9 = load i64, ptr %8, align 8, !tbaa !22
  %10 = add nsw i64 %9, 1
  store i64 %10, ptr %8, align 8, !tbaa !22
  %11 = getelementptr inbounds i8, ptr %0, i64 96
  store i64 0, ptr %11, align 8, !tbaa !23
  br label %16

12:                                               ; preds = %2
  %13 = getelementptr inbounds i8, ptr %0, i64 96
  %14 = load i64, ptr %13, align 8, !tbaa !23
  %15 = add nsw i64 %14, 1
  store i64 %15, ptr %13, align 8, !tbaa !23
  br label %16

16:                                               ; preds = %12, %7
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 = !{i64 0, i64 8, !6, i64 8, i64 8, !6, i64 16, i64 8, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !7, i64 80}
!11 = !{!"_ZTSN2vl7parsing13ParsingWriterE", !12, i64 0, !14, i64 8, !15, i64 16, !7, i64 48, !16, i64 56, !16, i64 80, !17, i64 104}
!12 = !{!"_ZTSN2vl6stream10TextWriterE", !13, i64 0}
!13 = !{!"_ZTSN2vl6ObjectE"}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"_ZTSN2vl3PtrINS_7parsing25IParsingPrintNodeRecorderEEE", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!16 = !{!"_ZTSN2vl7parsing14ParsingTextPosE", !7, i64 0, !7, i64 8, !7, i64 16}
!17 = !{!"_ZTSN2vl11collections4ListINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEES7_EE", !18, i64 0}
!18 = !{!"_ZTSN2vl11collections8ListBaseINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEES7_EE", !19, i64 0, !7, i64 24, !21, i64 32}
!19 = !{!"_ZTSN2vl11collections9ArrayBaseINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEEEE", !20, i64 0, !14, i64 8, !7, i64 16}
!20 = !{!"_ZTSN2vl11collections9ListStoreINS0_4PairIPNS_7parsing21ParsingTreeCustomBaseENS3_14ParsingTextPosEEELb0EEE", !13, i64 0}
!21 = !{!"bool", !8, i64 0}
!22 = !{!11, !7, i64 88}
!23 = !{!11, !7, i64 96}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass