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

; 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::regex::RegexLexerWalker" = type { %"class.vl::Object", ptr, ptr }
%"class.vl::Object" = 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 @_ZN2vl14regex_internal15PureInterpretor13GetStartStateEv(ptr noundef nonnull align 8 dereferenceable(8912952)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK2vl5regex16RegexLexerWalker13IsClosedTokenEPKwl(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i64 noundef %2) #2 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %12 = getelementptr inbounds %"class.vl::regex::RegexLexerWalker", ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = call noundef i64 @_ZN2vl14regex_internal15PureInterpretor13GetStartStateEv(ptr noundef nonnull align 8 dereferenceable(8912952) %13)
  store i64 %14, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %39, %3
  %16 = load i64, ptr %9, align 8, !tbaa !9
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = icmp slt i64 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 2, ptr %10, align 4
  br label %42

20:                                               ; preds = %15
  %21 = getelementptr inbounds %"class.vl::regex::RegexLexerWalker", ptr %11, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = getelementptr inbounds i32, ptr %23, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !14
  %27 = load i64, ptr %8, align 8, !tbaa !9
  %28 = call noundef i64 @_ZN2vl14regex_internal15PureInterpretor7TransitEwl(ptr noundef nonnull align 8 dereferenceable(8912952) %22, i32 noundef signext %26, i64 noundef %27)
  store i64 %28, ptr %8, align 8, !tbaa !9
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = icmp eq i64 %29, -1
  br i1 %30, label %31, label %32

31:                                               ; preds = %20
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %42

32:                                               ; preds = %20
  %33 = getelementptr inbounds %"class.vl::regex::RegexLexerWalker", ptr %11, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = call noundef zeroext i1 @_ZN2vl14regex_internal15PureInterpretor11IsDeadStateEl(ptr noundef nonnull align 8 dereferenceable(8912952) %34, i64 noundef %35)
  br i1 %36, label %37, label %38

37:                                               ; preds = %32
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %42

38:                                               ; preds = %32
  br label %39

39:                                               ; preds = %38
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = add nsw i64 %40, 1
  store i64 %41, ptr %9, align 8, !tbaa !9
  br label %15, !llvm.loop !16

42:                                               ; preds = %37, %31, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %43 = load i32, ptr %10, align 4
  switch i32 %43, label %45 [
    i32 2, label %44
  ]

44:                                               ; preds = %42
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %45

45:                                               ; preds = %44, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %46 = load i1, ptr %4, align 1
  ret i1 %46
}

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

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, !6, i64 8}
!12 = !{!"_ZTSN2vl5regex16RegexLexerWalkerE", !13, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!"_ZTSN2vl6ObjectE"}
!14 = !{!15, !15, i64 0}
!15 = !{!"wchar_t", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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 @_ZN2vl14regex_internal15PureInterpretor13GetStartStateEv(ptr noundef nonnull align 8 dereferenceable(8912952)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN2vl14regex_internal15PureInterpretor7TransitEwl(ptr noundef nonnull align 8 dereferenceable(8912952), i32 noundef signext, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZNK2vl5regex16RegexLexerWalker13IsClosedTokenEPKwl(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call noundef i64 @_ZN2vl14regex_internal15PureInterpretor13GetStartStateEv(ptr noundef nonnull align 8 dereferenceable(8912952) %5)
  %.not14 = icmp sgt i64 %2, 0
  br i1 %.not14, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %3
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = load i32, ptr %1, align 4, !tbaa !11
  %9 = tail call noundef i64 @_ZN2vl14regex_internal15PureInterpretor7TransitEwl(ptr noundef nonnull align 8 dereferenceable(8912952) %7, i32 noundef signext %8, i64 noundef %6)
  %10 = icmp eq i64 %9, -1
  br i1 %10, label %.critedge, label %.lr.ph24

11:                                               ; preds = %.lr.ph24
  %12 = add nuw nsw i64 %.0101623, 1
  %.not = icmp slt i64 %12, %2
  %exitcond.not = icmp eq i64 %12, %2
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !13

.lr.ph:                                           ; preds = %11
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds i32, ptr %1, i64 %12
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = tail call noundef i64 @_ZN2vl14regex_internal15PureInterpretor7TransitEwl(ptr noundef nonnull align 8 dereferenceable(8912952) %13, i32 noundef signext %15, i64 noundef %18)
  %17 = icmp eq i64 %16, -1
  br i1 %17, label %.critedge, label %.lr.ph24, !llvm.loop !13

.lr.ph24:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %18 = phi i64 [ %16, %.lr.ph ], [ %9, %.lr.ph.preheader ]
  %.0101623 = phi i64 [ %12, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.not1722 = phi i1 [ %.not, %.lr.ph ], [ true, %.lr.ph.preheader ]
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = tail call noundef zeroext i1 @_ZN2vl14regex_internal15PureInterpretor11IsDeadStateEl(ptr noundef nonnull align 8 dereferenceable(8912952) %19, i64 noundef %18)
  br i1 %20, label %.critedge, label %11

.critedge:                                        ; preds = %11, %.lr.ph, %.lr.ph24, %.lr.ph.preheader, %3
  %.not.lcssa = phi i1 [ false, %3 ], [ true, %.lr.ph.preheader ], [ %.not1722, %.lr.ph24 ], [ %.not, %.lr.ph ], [ %.not, %11 ]
  ret i1 %.not.lcssa
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2vl14regex_internal15PureInterpretor11IsDeadStateEl(ptr noundef nonnull align 8 dereferenceable(8912952), i64 noundef) local_unnamed_addr #0 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" }

!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 = !{!"_ZTSN2vl5regex16RegexLexerWalkerE", !7, i64 0, !8, i64 8, !8, i64 16}
!7 = !{!"_ZTSN2vl6ObjectE"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"wchar_t", !9, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass