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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2vl6stream12StringReader27PrepareIfLastCallIsReadLineEv(ptr noundef nonnull align 8 dereferenceable(65) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %3, i32 0, i32 3
  %5 = load i8, ptr %4, align 8, !tbaa !9, !range !16, !noundef !17
  %6 = trunc i8 %5 to i1
  br i1 %6, label %7, label %41

7:                                                ; preds = %1
  %8 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %3, i32 0, i32 3
  store i8 0, ptr %8, align 8, !tbaa !9
  %9 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %3, i32 0, i32 2
  %10 = load i64, ptr %9, align 8, !tbaa !18
  %11 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %3, i32 0, i32 1
  %12 = call noundef i64 @_ZNK2vl12ObjectStringIwE6LengthEv(ptr noundef nonnull align 8 dereferenceable(48) %11)
  %13 = icmp slt i64 %10, %12
  br i1 %13, label %14, label %24

14:                                               ; preds = %7
  %15 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %3, i32 0, i32 1
  %16 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %3, i32 0, i32 2
  %17 = load i64, ptr %16, align 8, !tbaa !18
  %18 = call noundef signext i32 @_ZNK2vl12ObjectStringIwEixEl(ptr noundef nonnull align 8 dereferenceable(48) %15, i64 noundef %17)
  %19 = icmp eq i32 %18, 13
  br i1 %19, label %20, label %24

20:                                               ; preds = %14
  %21 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %3, i32 0, i32 2
  %22 = load i64, ptr %21, align 8, !tbaa !18
  %23 = add nsw i64 %22, 1
  store i64 %23, ptr %21, align 8, !tbaa !18
  br label %24

24:                                               ; preds = %20, %14, %7
  %25 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %3, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !18
  %27 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %3, i32 0, i32 1
  %28 = call noundef i64 @_ZNK2vl12ObjectStringIwE6LengthEv(ptr noundef nonnull align 8 dereferenceable(48) %27)
  %29 = icmp slt i64 %26, %28
  br i1 %29, label %30, label %40

30:                                               ; preds = %24
  %31 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %3, i32 0, i32 1
  %32 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %3, i32 0, i32 2
  %33 = load i64, ptr %32, align 8, !tbaa !18
  %34 = call noundef signext i32 @_ZNK2vl12ObjectStringIwEixEl(ptr noundef nonnull align 8 dereferenceable(48) %31, i64 noundef %33)
  %35 = icmp eq i32 %34, 10
  br i1 %35, label %36, label %40

36:                                               ; preds = %30
  %37 = getelementptr inbounds %"class.vl::stream::StringReader", ptr %3, i32 0, i32 2
  %38 = load i64, ptr %37, align 8, !tbaa !18
  %39 = add nsw i64 %38, 1
  store i64 %39, ptr %37, align 8, !tbaa !18
  br label %40

40:                                               ; preds = %36, %30, %24
  br label %41

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


; 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 noundef i64 @_ZNK2vl12ObjectStringIwE6LengthEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #0 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
define dso_local void @_ZN2vl6stream12StringReader27PrepareIfLastCallIsReadLineEv(ptr noundef nonnull align 8 dereferenceable(65) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 64
  %3 = load i8, ptr %2, align 8, !tbaa !5, !range !15, !noundef !16
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %5, label %27

5:                                                ; preds = %1
  store i8 0, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 56
  %7 = load i64, ptr %6, align 8, !tbaa !17
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = tail call noundef i64 @_ZNK2vl12ObjectStringIwE6LengthEv(ptr noundef nonnull align 8 dereferenceable(48) %8)
  %10 = icmp slt i64 %7, %9
  %.pre1 = load i64, ptr %6, align 8, !tbaa !17
  br i1 %10, label %11, label %16

11:                                               ; preds = %5
  %12 = tail call noundef signext i32 @_ZNK2vl12ObjectStringIwEixEl(ptr noundef nonnull align 8 dereferenceable(48) %8, i64 noundef %.pre1)
  %13 = icmp eq i32 %12, 13
  %.pre = load i64, ptr %6, align 8, !tbaa !17
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  %15 = add nsw i64 %.pre, 1
  store i64 %15, ptr %6, align 8, !tbaa !17
  br label %16

16:                                               ; preds = %14, %11, %5
  %17 = phi i64 [ %15, %14 ], [ %.pre, %11 ], [ %.pre1, %5 ]
  %18 = tail call noundef i64 @_ZNK2vl12ObjectStringIwE6LengthEv(ptr noundef nonnull align 8 dereferenceable(48) %8)
  %19 = icmp slt i64 %17, %18
  br i1 %19, label %20, label %27

20:                                               ; preds = %16
  %21 = load i64, ptr %6, align 8, !tbaa !17
  %22 = tail call noundef signext i32 @_ZNK2vl12ObjectStringIwEixEl(ptr noundef nonnull align 8 dereferenceable(48) %8, i64 noundef %21)
  %23 = icmp eq i32 %22, 10
  br i1 %23, label %24, label %27

24:                                               ; preds = %20
  %25 = load i64, ptr %6, align 8, !tbaa !17
  %26 = add nsw i64 %25, 1
  store i64 %26, ptr %6, align 8, !tbaa !17
  br label %27

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


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