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

; 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::ParsingTable::LookAheadInfo" = type { %"class.vl::collections::List.116", i64 }
%"class.vl::collections::List.116" = type { %"class.vl::collections::ListBase.base.122", %"class.vl::collections::IEnumerable.120" }
%"class.vl::collections::ListBase.base.122" = type <{ %"class.vl::collections::ArrayBase.base.121", i64, i8 }>
%"class.vl::collections::ArrayBase.base.121" = type { %"class.vl::collections::ListStore.119", ptr, i64 }
%"class.vl::collections::ListStore.119" = type { %"class.vl::Object" }
%"class.vl::Object" = type { ptr }
%"class.vl::collections::IEnumerable.120" = type { %"class.vl::Interface" }
%"class.vl::Interface" = type { ptr }

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN2vl11collections4ListIllEixEl(ptr noundef nonnull align 8 dereferenceable(33), i64 noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN2vl7parsing7tabling12ParsingTable13LookAheadInfo10TestPrefixENS_3PtrIS3_EES5_(ptr noundef %0, ptr noundef %1) #2 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %9 = getelementptr inbounds %"class.vl::parsing::tabling::ParsingTable::LookAheadInfo", ptr %8, i32 0, i32 0
  %10 = call noundef i64 @_ZNK2vl11collections9ArrayBaseIlE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %9)
  %11 = call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %12 = getelementptr inbounds %"class.vl::parsing::tabling::ParsingTable::LookAheadInfo", ptr %11, i32 0, i32 0
  %13 = call noundef i64 @_ZNK2vl11collections9ArrayBaseIlE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %12)
  %14 = icmp sgt i64 %10, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i32 2, ptr %3, align 4
  br label %53

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %38, %16
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %20 = getelementptr inbounds %"class.vl::parsing::tabling::ParsingTable::LookAheadInfo", ptr %19, i32 0, i32 0
  %21 = call noundef i64 @_ZNK2vl11collections9ArrayBaseIlE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %20)
  %22 = icmp slt i64 %18, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %17
  store i32 2, ptr %7, align 4
  br label %41

24:                                               ; preds = %17
  %25 = call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %26 = getelementptr inbounds %"class.vl::parsing::tabling::ParsingTable::LookAheadInfo", ptr %25, i32 0, i32 0
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2vl11collections4ListIllEixEl(ptr noundef nonnull align 8 dereferenceable(33) %26, i64 noundef %27)
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %31 = getelementptr inbounds %"class.vl::parsing::tabling::ParsingTable::LookAheadInfo", ptr %30, i32 0, i32 0
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2vl11collections4ListIllEixEl(ptr noundef nonnull align 8 dereferenceable(33) %31, i64 noundef %32)
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %35 = icmp ne i64 %29, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %24
  store i32 2, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %41

37:                                               ; preds = %24
  br label %38

38:                                               ; preds = %37
  %39 = load i64, ptr %6, align 8, !tbaa !9
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr %6, align 8, !tbaa !9
  br label %17, !llvm.loop !11

41:                                               ; preds = %36, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %42 = load i32, ptr %7, align 4
  switch i32 %42, label %55 [
    i32 2, label %43
    i32 1, label %53
  ]

43:                                               ; preds = %41
  %44 = call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %45 = getelementptr inbounds %"class.vl::parsing::tabling::ParsingTable::LookAheadInfo", ptr %44, i32 0, i32 0
  %46 = call noundef i64 @_ZNK2vl11collections9ArrayBaseIlE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %45)
  %47 = call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %48 = getelementptr inbounds %"class.vl::parsing::tabling::ParsingTable::LookAheadInfo", ptr %47, i32 0, i32 0
  %49 = call noundef i64 @_ZNK2vl11collections9ArrayBaseIlE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %48)
  %50 = icmp slt i64 %46, %49
  %51 = zext i1 %50 to i64
  %52 = select i1 %50, i32 0, i32 1
  store i32 %52, ptr %3, align 4
  br label %53

53:                                               ; preds = %43, %41, %15
  %54 = load i32, ptr %3, align 4
  ret i32 %54

55:                                               ; preds = %41
  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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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 i64 @_ZNK2vl11collections9ArrayBaseIlE5CountEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN2vl11collections4ListIllEixEl(ptr noundef nonnull align 8 dereferenceable(33), i64 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 3) i32 @_ZN2vl7parsing7tabling12ParsingTable13LookAheadInfo10TestPrefixENS_3PtrIS3_EES5_(ptr noundef nonnull %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %4 = tail call noundef i64 @_ZNK2vl11collections9ArrayBaseIlE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %5 = tail call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %6 = tail call noundef i64 @_ZNK2vl11collections9ArrayBaseIlE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %5)
  %7 = icmp sgt i64 %4, %6
  br i1 %7, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2
  %8 = tail call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %9 = tail call noundef i64 @_ZNK2vl11collections9ArrayBaseIlE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %8)
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

11:                                               ; preds = %.lr.ph
  %12 = add nuw nsw i64 %.0611, 1
  %13 = tail call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %14 = tail call noundef i64 @_ZNK2vl11collections9ArrayBaseIlE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %13)
  %15 = icmp slt i64 %12, %14
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %11
  %.0611 = phi i64 [ %12, %11 ], [ 0, %.preheader ]
  %16 = tail call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %17 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2vl11collections4ListIllEixEl(ptr noundef nonnull align 8 dereferenceable(33) %16, i64 noundef %.0611)
  %18 = load i64, ptr %17, align 8, !tbaa !7
  %19 = tail call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %20 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2vl11collections4ListIllEixEl(ptr noundef nonnull align 8 dereferenceable(33) %19, i64 noundef %.0611)
  %21 = load i64, ptr %20, align 8, !tbaa !7
  %.not = icmp eq i64 %18, %21
  br i1 %.not, label %11, label %.loopexit

._crit_edge:                                      ; preds = %11, %.preheader
  %22 = tail call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %23 = tail call noundef i64 @_ZNK2vl11collections9ArrayBaseIlE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %22)
  %24 = tail call noundef ptr @_ZNK2vl3PtrINS_7parsing7tabling12ParsingTable13LookAheadInfoEEptEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %25 = tail call noundef i64 @_ZNK2vl11collections9ArrayBaseIlE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %24)
  %26 = icmp sge i64 %23, %25
  %27 = zext i1 %26 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %2, %._crit_edge
  %.1 = phi i32 [ %27, %._crit_edge ], [ 2, %2 ], [ 2, %.lr.ph ]
  ret i32 %.1
}

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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}


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