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

; 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 void @_ZN2vl6stream12StringReader27PrepareIfLastCallIsReadLineEv(ptr noundef nonnull align 8 dereferenceable(65)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2vl6stream12StringReader10ReadStringEl(ptr dead_on_unwind noalias writable sret(%"class.vl::ObjectString") align 8 %0, ptr noundef nonnull align 8 dereferenceable(65) %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
  %8 = alloca i1, align 1
  store ptr %0, ptr %4, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %9 = load ptr, ptr %5, align 8
  call void @_ZN2vl6stream12StringReader27PrepareIfLastCallIsReadLineEv(ptr noundef nonnull align 8 dereferenceable(65) %9)
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %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 = %3
  call void @_ZN2vl12ObjectStringIwEC2EPKwb(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef @.str.2, i1 noundef zeroext true)
  br label %38

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %16 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 1
  %17 = call noundef i64 @_ZNK2vl12ObjectStringIwE6LengthEv(ptr noundef nonnull align 8 dereferenceable(48) %16)
  %18 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 2
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = sub nsw i64 %17, %19
  store i64 %20, ptr %7, align 8, !tbaa !9
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = icmp sgt i64 %21, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %15
  %25 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %25, ptr %6, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %24, %15
  store i1 false, ptr %8, align 1
  %27 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 1
  %28 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 2
  %29 = load i64, ptr %28, align 8, !tbaa !13
  %30 = load i64, ptr %6, align 8, !tbaa !9
  call void @_ZNK2vl12ObjectStringIwE3SubEll(ptr dead_on_unwind writable sret(%"class.vl::ObjectString") align 8 %0, ptr noundef nonnull align 8 dereferenceable(48) %27, i64 noundef %29, i64 noundef %30)
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %9, i32 0, i32 2
  %33 = load i64, ptr %32, align 8, !tbaa !13
  %34 = add nsw i64 %33, %31
  store i64 %34, ptr %32, align 8, !tbaa !13
  store i1 true, ptr %8, align 1
  %35 = load i1, ptr %8, align 1
  br i1 %35, label %37, label %36

36:                                               ; preds = %26
  call void @_ZN2vl12ObjectStringIwED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %0) #3
  br label %37

37:                                               ; preds = %36, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %38

38:                                               ; preds = %37, %14
  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, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !10, i64 56}
!14 = !{!"_ZTSN2vl6stream12StringReaderE", !15, i64 0, !17, i64 8, !10, i64 56, !18, i64 64}
!15 = !{!"_ZTSN2vl6stream10TextReaderE", !16, i64 0}
!16 = !{!"_ZTSN2vl6ObjectE"}
!17 = !{!"_ZTSN2vl12ObjectStringIwEE", !16, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!18 = !{!"bool", !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"

%"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 void @_ZN2vl6stream12StringReader27PrepareIfLastCallIsReadLineEv(ptr noundef nonnull align 8 dereferenceable(65)) local_unnamed_addr #1 align 2

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

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

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = tail call noundef i64 @_ZNK2vl12ObjectStringIwE6LengthEv(ptr noundef nonnull align 8 dereferenceable(48) %10)
  %12 = getelementptr inbounds i8, ptr %1, i64 56
  %13 = load i64, ptr %12, align 8, !tbaa !8
  %14 = sub nsw i64 %11, %13
  %spec.select = tail call i64 @llvm.smin.i64(i64 %14, i64 %2)
  tail call void @_ZNK2vl12ObjectStringIwE3SubEll(ptr dead_on_unwind writable sret(%"class.vl::ObjectString") align 8 %0, ptr noundef nonnull align 8 dereferenceable(48) %10, i64 noundef %13, i64 noundef %spec.select)
  %15 = load i64, ptr %12, align 8, !tbaa !8
  %16 = add nsw i64 %15, %spec.select
  store i64 %16, ptr %12, align 8, !tbaa !8
  br label %17

17:                                               ; preds = %9, %8
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #2

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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


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