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

; 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::ObjectString" = type { %"class.vl::Object", ptr, ptr, i64, i64, i64 }
%"class.vl::Object" = type { ptr }
%"class.vl::stream::StringReader" = type <{ %"class.vl::stream::TextReader", %"class.vl::ObjectString", i64, i8, [7 x i8] }>
%"class.vl::stream::TextReader" = type { %"class.vl::Object" }

@.str.2 = external hidden unnamed_addr constant [1 x i32], align 4

; 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 noundef i64 @_ZNK2vl12ObjectStringIwE6LengthEv(ptr noundef nonnull align 8 dereferenceable(48)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl12ObjectStringIwEC2EPKwb(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef, i1 noundef zeroext) unnamed_addr #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK2vl12ObjectStringIwE3SubEll(ptr dead_on_unwind noalias writable sret(%"class.vl::ObjectString") align 8, ptr noundef nonnull align 8 dereferenceable(48), i64 noundef, i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef signext i32 @_ZNK2vl12ObjectStringIwEixEl(ptr noundef nonnull align 8 dereferenceable(48), i64 noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2vl6stream12StringReader8ReadLineEv(ptr dead_on_unwind noalias writable sret(%"class.vl::ObjectString") align 8 %0, ptr noundef nonnull align 8 dereferenceable(65) %1) unnamed_addr #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i1, align 1
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @_ZN2vl6stream12StringReader27PrepareIfLastCallIsReadLineEv(ptr noundef nonnull align 8 dereferenceable(65) %9)
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds ptr, ptr %10, i64 2
  %12 = load ptr, ptr %11, align 8
  %13 = call noundef zeroext i1 %12(ptr noundef nonnull align 8 dereferenceable(65) %9)
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  call void @_ZN2vl12ObjectStringIwEC2EPKwb(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef @.str.2, i1 noundef zeroext true)
  br label %53

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %16 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 2
  %17 = load i64, ptr %16, align 8, !tbaa !11
  store i64 %17, ptr %5, align 8, !tbaa !18
  br label %18

18:                                               ; preds = %38, %15
  %19 = load i64, ptr %5, align 8, !tbaa !18
  %20 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 1
  %21 = call noundef i64 @_ZNK2vl12ObjectStringIwE6LengthEv(ptr noundef nonnull align 8 dereferenceable(48) %20)
  %22 = icmp slt i64 %19, %21
  br i1 %22, label %23, label %39

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %24 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 1
  %25 = load i64, ptr %5, align 8, !tbaa !18
  %26 = call noundef signext i32 @_ZNK2vl12ObjectStringIwEixEl(ptr noundef nonnull align 8 dereferenceable(48) %24, i64 noundef %25)
  store i32 %26, ptr %6, align 4, !tbaa !19
  %27 = load i32, ptr %6, align 4, !tbaa !19
  %28 = icmp eq i32 %27, 13
  br i1 %28, label %32, label %29

29:                                               ; preds = %23
  %30 = load i32, ptr %6, align 4, !tbaa !19
  %31 = icmp eq i32 %30, 10
  br i1 %31, label %32, label %33

32:                                               ; preds = %29, %23
  store i32 3, ptr %7, align 4
  br label %36

33:                                               ; preds = %29
  %34 = load i64, ptr %5, align 8, !tbaa !18
  %35 = add nsw i64 %34, 1
  store i64 %35, ptr %5, align 8, !tbaa !18
  store i32 0, ptr %7, align 4
  br label %36

36:                                               ; preds = %33, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %37 = load i32, ptr %7, align 4
  switch i32 %37, label %54 [
    i32 0, label %38
    i32 3, label %39
  ]

38:                                               ; preds = %36
  br label %18, !llvm.loop !21

39:                                               ; preds = %36, %18
  store i1 false, ptr %8, align 1
  %40 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 1
  %41 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 2
  %42 = load i64, ptr %41, align 8, !tbaa !11
  %43 = load i64, ptr %5, align 8, !tbaa !18
  %44 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 2
  %45 = load i64, ptr %44, align 8, !tbaa !11
  %46 = sub nsw i64 %43, %45
  call void @_ZNK2vl12ObjectStringIwE3SubEll(ptr dead_on_unwind writable sret(%"class.vl::ObjectString") align 8 %0, ptr noundef nonnull align 8 dereferenceable(48) %40, i64 noundef %42, i64 noundef %46)
  %47 = load i64, ptr %5, align 8, !tbaa !18
  %48 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 2
  store i64 %47, ptr %48, align 8, !tbaa !11
  %49 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 3
  store i8 1, ptr %49, align 8, !tbaa !23
  store i1 true, ptr %8, align 1
  store i32 1, ptr %7, align 4
  %50 = load i1, ptr %8, align 1
  br i1 %50, label %52, label %51

51:                                               ; preds = %39
  call void @_ZN2vl12ObjectStringIwED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %0) #3
  br label %52

52:                                               ; preds = %51, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %53

53:                                               ; preds = %52, %14
  ret void

54:                                               ; preds = %36
  unreachable
}

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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !16, i64 56}
!12 = !{!"_ZTSN2vl6stream12StringReaderE", !13, i64 0, !15, i64 8, !16, i64 56, !17, i64 64}
!13 = !{!"_ZTSN2vl6stream10TextReaderE", !14, i64 0}
!14 = !{!"_ZTSN2vl6ObjectE"}
!15 = !{!"_ZTSN2vl12ObjectStringIwEE", !14, i64 0, !6, i64 8, !6, i64 16, !16, i64 24, !16, i64 32, !16, i64 40}
!16 = !{!"long", !7, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{!16, !16, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"wchar_t", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!12, !17, i64 64}


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

%"class.vl::ObjectString" = type { %"class.vl::Object", ptr, ptr, i64, i64, i64 }
%"class.vl::Object" = type { ptr }

@.str.2 = external hidden unnamed_addr constant [1 x i32], align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK2vl12ObjectStringIwE6LengthEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl12ObjectStringIwEC2EPKwb(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef, i1 noundef zeroext) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK2vl12ObjectStringIwE3SubEll(ptr dead_on_unwind noalias writable sret(%"class.vl::ObjectString") align 8, ptr noundef nonnull align 8 dereferenceable(48), i64 noundef, i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef signext i32 @_ZNK2vl12ObjectStringIwEixEl(ptr noundef nonnull align 8 dereferenceable(48), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl6stream12StringReader27PrepareIfLastCallIsReadLineEv(ptr noundef nonnull align 8 dereferenceable(65)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2vl6stream12StringReader8ReadLineEv(ptr dead_on_unwind noalias writable sret(%"class.vl::ObjectString") align 8 %0, ptr noundef nonnull align 8 dereferenceable(65) %1) unnamed_addr #1 align 2 {
  tail call void @_ZN2vl6stream12StringReader27PrepareIfLastCallIsReadLineEv(ptr noundef nonnull align 8 dereferenceable(65) %1)
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %5 = load ptr, ptr %4, align 8
  %6 = tail call noundef zeroext i1 %5(ptr noundef nonnull align 8 dereferenceable(65) %1)
  br i1 %6, label %7, label %8

7:                                                ; preds = %2
  tail call void @_ZN2vl12ObjectStringIwEC2EPKwb(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull @.str.2, i1 noundef zeroext true)
  br label %22

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %1, i64 56
  %10 = load i64, ptr %9, align 8, !tbaa !8
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = tail call noundef i64 @_ZNK2vl12ObjectStringIwE6LengthEv(ptr noundef nonnull align 8 dereferenceable(48) %11)
  %13 = icmp slt i64 %10, %12
  br i1 %13, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %8, %15
  %.014 = phi i64 [ %16, %15 ], [ %10, %8 ]
  %14 = tail call noundef signext i32 @_ZNK2vl12ObjectStringIwEixEl(ptr noundef nonnull align 8 dereferenceable(48) %11, i64 noundef %.014)
  switch i32 %14, label %15 [
    i32 13, label %.thread
    i32 10, label %.thread
  ]

15:                                               ; preds = %.lr.ph
  %16 = add nsw i64 %.014, 1
  %17 = tail call noundef i64 @_ZNK2vl12ObjectStringIwE6LengthEv(ptr noundef nonnull align 8 dereferenceable(48) %11)
  %18 = icmp slt i64 %16, %17
  br i1 %18, label %.lr.ph, label %.thread

.thread:                                          ; preds = %15, %.lr.ph, %.lr.ph, %8
  %.0.lcssa = phi i64 [ %10, %8 ], [ %.014, %.lr.ph ], [ %.014, %.lr.ph ], [ %16, %15 ]
  %19 = load i64, ptr %9, align 8, !tbaa !8
  %20 = sub nsw i64 %.0.lcssa, %19
  tail call void @_ZNK2vl12ObjectStringIwE3SubEll(ptr dead_on_unwind writable sret(%"class.vl::ObjectString") align 8 %0, ptr noundef nonnull align 8 dereferenceable(48) %11, i64 noundef %19, i64 noundef %20)
  store i64 %.0.lcssa, ptr %9, align 8, !tbaa !8
  %21 = getelementptr inbounds i8, ptr %1, i64 64
  store i8 1, ptr %21, align 8, !tbaa !17
  br label %22

22:                                               ; preds = %.thread, %7
  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, !6, i64 0}
!6 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !15, i64 56}
!9 = !{!"_ZTSN2vl6stream12StringReaderE", !10, i64 0, !12, i64 8, !15, i64 56, !16, i64 64}
!10 = !{!"_ZTSN2vl6stream10TextReaderE", !11, i64 0}
!11 = !{!"_ZTSN2vl6ObjectE"}
!12 = !{!"_ZTSN2vl12ObjectStringIwEE", !11, i64 0, !13, i64 8, !13, i64 16, !15, i64 24, !15, i64 32, !15, i64 40}
!13 = !{!"any pointer", !14, i64 0}
!14 = !{!"omnipotent char", !7, i64 0}
!15 = !{!"long", !14, i64 0}
!16 = !{!"bool", !14, i64 0}
!17 = !{!9, !16, i64 64}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass