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

; 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::tabling::ParsingTokenWalker" = type { %"class.vl::Object", ptr, %"class.vl::Ptr.61", i64, %"class.vl::parsing::tabling::ParsingTokenWalker::TokenLookAhead", %"class.vl::parsing::tabling::ParsingTokenWalker::ReduceLookAhead" }
%"class.vl::Object" = type { ptr }
%"class.vl::Ptr.61" = type { ptr, ptr, ptr, ptr }
%"class.vl::parsing::tabling::ParsingTokenWalker::TokenLookAhead" = type { %"class.vl::Object", %"class.vl::collections::IEnumerable.120", ptr }
%"class.vl::collections::IEnumerable.120" = type { %"class.vl::Interface" }
%"class.vl::Interface" = type { ptr }
%"class.vl::parsing::tabling::ParsingTokenWalker::ReduceLookAhead" = type { %"class.vl::Object", %"class.vl::collections::IEnumerable.120", ptr }
%"class.vl::regex::RegexToken" = type { i64, i64, i64, ptr, i64, i8, i64, i64, i64, i64 }

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZNK2vl7parsing7tabling18ParsingTokenWalker12GetNextIndexEl(ptr noundef nonnull align 8 dereferenceable(104) %0, i64 noundef %1) #1 align 2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %6 = load ptr, ptr %4, align 8
  %7 = load i64, ptr %5, align 8, !tbaa !9
  %8 = icmp eq i64 %7, -2
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  store i64 -1, ptr %3, align 8
  br label %51

10:                                               ; preds = %2
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = icmp sle i64 -1, %11
  br i1 %12, label %13, label %50

13:                                               ; preds = %10
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = getelementptr inbounds %"class.vl::parsing::tabling::ParsingTokenWalker", ptr %6, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = call noundef i64 @_ZNK2vl11collections9ArrayBaseINS_5regex10RegexTokenEE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %16)
  %18 = icmp slt i64 %14, %17
  br i1 %18, label %19, label %50

19:                                               ; preds = %13
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = add nsw i64 %20, 1
  store i64 %21, ptr %5, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %47, %19
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = icmp sle i64 0, %23
  br i1 %24, label %25, label %31

25:                                               ; preds = %22
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds %"class.vl::parsing::tabling::ParsingTokenWalker", ptr %6, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = call noundef i64 @_ZNK2vl11collections9ArrayBaseINS_5regex10RegexTokenEE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %28)
  %30 = icmp slt i64 %26, %29
  br label %31

31:                                               ; preds = %25, %22
  %32 = phi i1 [ false, %22 ], [ %30, %25 ]
  br i1 %32, label %33, label %48

33:                                               ; preds = %31
  %34 = getelementptr inbounds %"class.vl::parsing::tabling::ParsingTokenWalker", ptr %6, i32 0, i32 2
  %35 = call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTableEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %34)
  %36 = getelementptr inbounds %"class.vl::parsing::tabling::ParsingTokenWalker", ptr %6, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = load i64, ptr %5, align 8, !tbaa !9
  %39 = call noundef nonnull align 8 dereferenceable(80) ptr @_ZN2vl11collections4ListINS_5regex10RegexTokenES3_EixEl(ptr noundef nonnull align 8 dereferenceable(33) %37, i64 noundef %38)
  %40 = getelementptr inbounds %"class.vl::regex::RegexToken", ptr %39, i32 0, i32 2
  %41 = load i64, ptr %40, align 8, !tbaa !18
  %42 = call noundef zeroext i1 @_ZN2vl7parsing7tabling12ParsingTable12IsInputTokenEl(ptr noundef nonnull align 8 dereferenceable(656) %35, i64 noundef %41)
  br i1 %42, label %43, label %44

43:                                               ; preds = %33
  br label %48

44:                                               ; preds = %33
  %45 = load i64, ptr %5, align 8, !tbaa !9
  %46 = add nsw i64 %45, 1
  store i64 %46, ptr %5, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %44
  br label %22, !llvm.loop !21

48:                                               ; preds = %43, %31
  %49 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %49, ptr %3, align 8
  br label %51

50:                                               ; preds = %13, %10
  store i64 -3, ptr %3, align 8
  br label %51

51:                                               ; preds = %50, %48, %9
  %52 = load i64, ptr %3, align 8
  ret i64 %52
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2vl7parsing7tabling12ParsingTable12IsInputTokenEl(ptr noundef nonnull align 8 dereferenceable(656), i64 noundef) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(80) ptr @_ZN2vl11collections4ListINS_5regex10RegexTokenES3_EixEl(ptr noundef nonnull align 8 dereferenceable(33), i64 noundef) #1 align 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" }

!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 = !{!"_ZTSN2vl7parsing7tabling18ParsingTokenWalkerE", !13, i64 0, !6, i64 8, !14, i64 16, !10, i64 48, !15, i64 56, !17, i64 80}
!13 = !{!"_ZTSN2vl6ObjectE"}
!14 = !{!"_ZTSN2vl3PtrINS_7parsing7tabling12ParsingTableEEE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"_ZTSN2vl7parsing7tabling18ParsingTokenWalker14TokenLookAheadE", !13, i64 0, !16, i64 8, !6, i64 16}
!16 = !{!"_ZTSN2vl11collections11IEnumerableIlEE"}
!17 = !{!"_ZTSN2vl7parsing7tabling18ParsingTokenWalker15ReduceLookAheadE", !13, i64 0, !16, i64 8, !6, i64 16}
!18 = !{!19, !10, i64 16}
!19 = !{!"_ZTSN2vl5regex10RegexTokenE", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !20, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72}
!20 = !{!"bool", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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 noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTableEEptEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i64 -3, -9223372036854775808) i64 @_ZNK2vl7parsing7tabling18ParsingTokenWalker12GetNextIndexEl(ptr noundef nonnull align 8 dereferenceable(104) %0, i64 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = icmp eq i64 %1, -2
  br i1 %3, label %.critedge, label %4

4:                                                ; preds = %2
  %5 = icmp sgt i64 %1, -2
  br i1 %5, label %6, label %.critedge

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = tail call noundef i64 @_ZNK2vl11collections9ArrayBaseINS_5regex10RegexTokenEE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %8)
  %10 = icmp sgt i64 %9, %1
  br i1 %10, label %.preheader, label %.critedge

.preheader:                                       ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  br label %12

12:                                               ; preds = %.preheader, %16
  %.0.in = phi i64 [ %.0, %16 ], [ %1, %.preheader ]
  %.0 = add nsw i64 %.0.in, 1
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = tail call noundef i64 @_ZNK2vl11collections9ArrayBaseINS_5regex10RegexTokenEE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %13)
  %15 = icmp slt i64 %.0, %14
  br i1 %15, label %16, label %.critedge

16:                                               ; preds = %12
  %17 = tail call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTableEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %11)
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = tail call noundef nonnull align 8 dereferenceable(80) ptr @_ZN2vl11collections4ListINS_5regex10RegexTokenES3_EixEl(ptr noundef nonnull align 8 dereferenceable(33) %18, i64 noundef %.0)
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  %21 = load i64, ptr %20, align 8, !tbaa !16
  %22 = tail call noundef zeroext i1 @_ZN2vl7parsing7tabling12ParsingTable12IsInputTokenEl(ptr noundef nonnull align 8 dereferenceable(656) %17, i64 noundef %21)
  br i1 %22, label %.critedge, label %12, !llvm.loop !19

.critedge:                                        ; preds = %12, %16, %4, %6, %2
  %.010 = phi i64 [ -1, %2 ], [ -3, %6 ], [ -3, %4 ], [ %.0, %16 ], [ %.0, %12 ]
  ret i64 %.010
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(80) ptr @_ZN2vl11collections4ListINS_5regex10RegexTokenES3_EixEl(ptr noundef nonnull align 8 dereferenceable(33), i64 noundef) local_unnamed_addr #1 align 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" }

!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, !8, i64 8}
!6 = !{!"_ZTSN2vl7parsing7tabling18ParsingTokenWalkerE", !7, i64 0, !8, i64 8, !11, i64 16, !12, i64 48, !13, i64 56, !15, i64 80}
!7 = !{!"_ZTSN2vl6ObjectE"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN2vl3PtrINS_7parsing7tabling12ParsingTableEEE", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24}
!12 = !{!"long", !9, i64 0}
!13 = !{!"_ZTSN2vl7parsing7tabling18ParsingTokenWalker14TokenLookAheadE", !7, i64 0, !14, i64 8, !8, i64 16}
!14 = !{!"_ZTSN2vl11collections11IEnumerableIlEE"}
!15 = !{!"_ZTSN2vl7parsing7tabling18ParsingTokenWalker15ReduceLookAheadE", !7, i64 0, !14, i64 8, !8, i64 16}
!16 = !{!17, !12, i64 16}
!17 = !{!"_ZTSN2vl5regex10RegexTokenE", !12, i64 0, !12, i64 8, !12, i64 16, !8, i64 24, !12, i64 32, !18, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72}
!18 = !{!"bool", !9, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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