; LLVM IR from int32bit/leetcode :: algorithms/RegularExpressionMatching (match)

; 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"

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @isMatch(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = sext i8 %10 to i32
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %18

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = icmp eq i32 %16, 0
  store i1 %17, ptr %3, align 1
  br label %101

18:                                               ; preds = %2
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 1
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %30, label %24

24:                                               ; preds = %18
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 1
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = icmp ne i32 %28, 42
  br i1 %29, label %30, label %55

30:                                               ; preds = %24, %18
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %48, label %35

35:                                               ; preds = %30
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = sext i8 %37 to i32
  %39 = icmp ne i32 %38, 46
  br i1 %39, label %40, label %49

40:                                               ; preds = %35
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i8, ptr %44, align 1, !tbaa !9
  %46 = sext i8 %45 to i32
  %47 = icmp ne i32 %43, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %40, %30
  store i1 false, ptr %3, align 1
  br label %101

49:                                               ; preds = %40, %35
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i64 1
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 1
  %54 = call zeroext i1 @isMatch(ptr noundef %51, ptr noundef %53)
  store i1 %54, ptr %3, align 1
  br label %101

55:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 -1, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = call i64 @strlen(ptr noundef %56) #4
  %58 = trunc i64 %57 to i32
  store i32 %58, ptr %7, align 4, !tbaa !10
  br label %59

59:                                               ; preds = %96, %55
  %60 = load i32, ptr %6, align 4, !tbaa !10
  %61 = load i32, ptr %7, align 4, !tbaa !10
  %62 = icmp slt i32 %60, %61
  br i1 %62, label %63, label %84

63:                                               ; preds = %59
  %64 = load i32, ptr %6, align 4, !tbaa !10
  %65 = icmp slt i32 %64, 0
  br i1 %65, label %82, label %66

66:                                               ; preds = %63
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load i8, ptr %67, align 1, !tbaa !9
  %69 = sext i8 %68 to i32
  %70 = icmp eq i32 %69, 46
  br i1 %70, label %82, label %71

71:                                               ; preds = %66
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = load i32, ptr %6, align 4, !tbaa !10
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i8, ptr %72, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !9
  %77 = sext i8 %76 to i32
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load i8, ptr %78, align 1, !tbaa !9
  %80 = sext i8 %79 to i32
  %81 = icmp eq i32 %77, %80
  br label %82

82:                                               ; preds = %71, %66, %63
  %83 = phi i1 [ true, %66 ], [ true, %63 ], [ %81, %71 ]
  br label %84

84:                                               ; preds = %82, %59
  %85 = phi i1 [ false, %59 ], [ %83, %82 ]
  br i1 %85, label %86, label %99

86:                                               ; preds = %84
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = load i32, ptr %6, align 4, !tbaa !10
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds i8, ptr %87, i64 %89
  %91 = getelementptr inbounds i8, ptr %90, i64 1
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds i8, ptr %92, i64 2
  %94 = call zeroext i1 @isMatch(ptr noundef %91, ptr noundef %93)
  br i1 %94, label %95, label %96

95:                                               ; preds = %86
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %100

96:                                               ; preds = %86
  %97 = load i32, ptr %6, align 4, !tbaa !10
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %6, align 4, !tbaa !10
  br label %59, !llvm.loop !12

99:                                               ; preds = %84
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %100

100:                                              ; preds = %99, %95
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %101

101:                                              ; preds = %100, %49, %48, %13
  %102 = load i1, ptr %3, align 1
  ret i1 %102
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind willreturn memory(read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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: nofree nounwind memory(argmem: read) uwtable
define dso_local zeroext i1 @isMatch(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i8, ptr %1, align 1, !tbaa !5
  %4 = icmp eq i8 %3, 0
  br i1 %4, label %tailrecurse._crit_edge, label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  %.tr.lcssa = phi ptr [ %0, %2 ], [ %14, %tailrecurse ]
  %5 = load i8, ptr %.tr.lcssa, align 1, !tbaa !5
  %6 = icmp eq i8 %5, 0
  br label %.critedge

.lr.ph:                                           ; preds = %2, %tailrecurse
  %7 = phi i8 [ %9, %tailrecurse ], [ %3, %2 ]
  %.tr3241 = phi ptr [ %8, %tailrecurse ], [ %1, %2 ]
  %.tr40 = phi ptr [ %14, %tailrecurse ], [ %0, %2 ]
  %.fr49 = freeze i8 %7
  %8 = getelementptr inbounds i8, ptr %.tr3241, i64 1
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %cond = icmp eq i8 %9, 42
  br i1 %cond, label %16, label %10

10:                                               ; preds = %.lr.ph
  %11 = load i8, ptr %.tr40, align 1, !tbaa !5
  %12 = icmp eq i8 %11, 0
  br i1 %12, label %.critedge, label %13

13:                                               ; preds = %10
  %.not29 = icmp eq i8 %.fr49, 46
  %.not30 = icmp eq i8 %11, %.fr49
  %or.cond = or i1 %.not29, %.not30
  br i1 %or.cond, label %tailrecurse, label %.critedge

tailrecurse:                                      ; preds = %13
  %14 = getelementptr inbounds i8, ptr %.tr40, i64 1
  %15 = icmp eq i8 %9, 0
  br i1 %15, label %tailrecurse._crit_edge, label %.lr.ph

16:                                               ; preds = %.lr.ph
  %17 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.tr40) #2
  %invariant.gep = getelementptr i8, ptr %.tr40, i64 1
  %18 = and i64 %17, 2147483648
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %.lr.ph43, label %.critedge

.lr.ph43:                                         ; preds = %16
  %20 = icmp eq i8 %.fr49, 46
  %21 = getelementptr inbounds i8, ptr %.tr3241, i64 2
  %wide.trip.count64 = and i64 %17, 2147483647
  br i1 %20, label %.critedge2.us, label %.critedge2.peel

.critedge2.peel:                                  ; preds = %.lr.ph43
  %22 = tail call zeroext i1 @isMatch(ptr noundef nonnull %.tr40, ptr noundef nonnull %21)
  br i1 %22, label %.critedge, label %23

23:                                               ; preds = %.critedge2.peel
  %exitcond.peel.not = icmp eq i64 %wide.trip.count64, 0
  br i1 %exitcond.peel.not, label %.critedge, label %.lr.ph43.split.peel.next

.critedge2.us:                                    ; preds = %.lr.ph43, %.critedge2.us
  %indvars.iv61 = phi i64 [ %indvars.iv.next62, %.critedge2.us ], [ -1, %.lr.ph43 ]
  %gep.us = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv61
  %24 = tail call zeroext i1 @isMatch(ptr noundef nonnull %gep.us, ptr noundef nonnull %21)
  %indvars.iv.next62 = add nsw i64 %indvars.iv61, 1
  %exitcond65.not = icmp eq i64 %indvars.iv.next62, %wide.trip.count64
  %or.cond84 = select i1 %24, i1 true, i1 %exitcond65.not
  br i1 %or.cond84, label %.critedge, label %.critedge2.us, !llvm.loop !8

25:                                               ; preds = %.critedge2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count64
  br i1 %exitcond.not, label %.critedge, label %.lr.ph43.split.peel.next, !llvm.loop !10

.lr.ph43.split.peel.next:                         ; preds = %23, %25
  %indvars.iv = phi i64 [ %indvars.iv.next, %25 ], [ 0, %23 ]
  %26 = getelementptr inbounds i8, ptr %.tr40, i64 %indvars.iv
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = icmp eq i8 %27, %.fr49
  br i1 %28, label %.critedge2, label %.critedge

.critedge2:                                       ; preds = %.lr.ph43.split.peel.next
  %gep = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv
  %29 = tail call zeroext i1 @isMatch(ptr noundef nonnull %gep, ptr noundef nonnull %21)
  br i1 %29, label %.critedge, label %25

.critedge:                                        ; preds = %10, %13, %.lr.ph43.split.peel.next, %25, %.critedge2, %.critedge2.us, %.critedge2.peel, %23, %16, %tailrecurse._crit_edge
  %.1 = phi i1 [ %6, %tailrecurse._crit_edge ], [ false, %16 ], [ true, %.critedge2.peel ], [ false, %23 ], [ %24, %.critedge2.us ], [ true, %.critedge2 ], [ false, %25 ], [ false, %.lr.ph43.split.peel.next ], [ false, %13 ], [ false, %10 ]
  ret i1 %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { nofree nounwind memory(argmem: read) 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 nofree nounwind willreturn memory(argmem: read) "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 = { nounwind willreturn memory(read) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9, !11}
!11 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass