; LLVM IR from 6leetcode/6leetcode :: questions/Algorithms/0010. Regular Expression Matching (Testing)

; 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 i8, align 1
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = sext i8 %9 to i32
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %17

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

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %37

22:                                               ; preds = %17
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = sext i8 %24 to i32
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = icmp eq i32 %25, %28
  br i1 %29, label %35, label %30

30:                                               ; preds = %22
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 46
  br label %35

35:                                               ; preds = %30, %22
  %36 = phi i1 [ true, %22 ], [ %34, %30 ]
  br label %37

37:                                               ; preds = %35, %17
  %38 = phi i1 [ false, %17 ], [ %36, %35 ]
  %39 = zext i1 %38 to i8
  store i8 %39, ptr %6, align 1, !tbaa !10
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 1
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  %44 = icmp eq i32 %43, 42
  br i1 %44, label %45, label %62

45:                                               ; preds = %37
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i64 2
  %49 = call zeroext i1 @isMatch(ptr noundef %46, ptr noundef %48)
  br i1 %49, label %60, label %50

50:                                               ; preds = %45
  %51 = load i8, ptr %6, align 1, !tbaa !10, !range !12, !noundef !13
  %52 = trunc i8 %51 to i1
  br i1 %52, label %53, label %58

53:                                               ; preds = %50
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 1
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = call zeroext i1 @isMatch(ptr noundef %55, ptr noundef %56)
  br label %58

58:                                               ; preds = %53, %50
  %59 = phi i1 [ false, %50 ], [ %57, %53 ]
  br label %60

60:                                               ; preds = %58, %45
  %61 = phi i1 [ true, %45 ], [ %59, %58 ]
  store i1 %61, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %73

62:                                               ; preds = %37
  %63 = load i8, ptr %6, align 1, !tbaa !10, !range !12, !noundef !13
  %64 = trunc i8 %63 to i1
  br i1 %64, label %65, label %71

65:                                               ; preds = %62
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 1
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 1
  %70 = call zeroext i1 @isMatch(ptr noundef %67, ptr noundef %69)
  br label %71

71:                                               ; preds = %65, %62
  %72 = phi i1 [ false, %62 ], [ %70, %65 ]
  store i1 %72, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %73

73:                                               ; preds = %71, %60
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  br label %74

74:                                               ; preds = %73, %12
  %75 = load i1, ptr %3, align 1
  ret i1 %75
}

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

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

!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 = !{!"_Bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}


; 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 nosync nounwind memory(argmem: read) uwtable
define dso_local zeroext i1 @isMatch(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %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.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %tailrecurse.outer.backedge
  %5 = phi i8 [ %23, %tailrecurse.outer.backedge ], [ %3, %2 ]
  %.tr24.ph43 = phi ptr [ %.tr24.ph.be, %tailrecurse.outer.backedge ], [ %1, %2 ]
  %.tr.ph42 = phi ptr [ %.tr.ph.be, %tailrecurse.outer.backedge ], [ %0, %2 ]
  %6 = load i8, ptr %.tr.ph42, align 1, !tbaa !5
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %.thread.us, label %.lr.ph.split

.thread.us:                                       ; preds = %.lr.ph, %.thread19.us
  %.tr2434.us = phi ptr [ %10, %.thread19.us ], [ %.tr24.ph43, %.lr.ph ]
  %7 = getelementptr inbounds i8, ptr %.tr2434.us, i64 1
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = icmp eq i8 %8, 42
  br i1 %9, label %.thread19.us, label %.thread18

.thread19.us:                                     ; preds = %.thread.us
  %10 = getelementptr inbounds i8, ptr %.tr2434.us, i64 2
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = icmp eq i8 %11, 0
  br i1 %12, label %tailrecurse.outer._crit_edge, label %.thread.us

.lr.ph.split:                                     ; preds = %.lr.ph
  %13 = icmp ne i8 %6, %5
  %14 = icmp ne i8 %5, 46
  %spec.select.not = and i1 %14, %13
  %15 = getelementptr inbounds i8, ptr %.tr24.ph43, i64 1
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = icmp eq i8 %16, 42
  br i1 %17, label %20, label %25

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer.backedge, %.thread19.us, %2
  %.tr.ph.lcssa33 = phi ptr [ %0, %2 ], [ %.tr.ph42, %.thread19.us ], [ %.tr.ph.be, %tailrecurse.outer.backedge ]
  %18 = load i8, ptr %.tr.ph.lcssa33, align 1, !tbaa !5
  %19 = icmp eq i8 %18, 0
  br label %.thread18

20:                                               ; preds = %.lr.ph.split
  %21 = getelementptr inbounds i8, ptr %.tr24.ph43, i64 2
  %22 = tail call zeroext i1 @isMatch(ptr noundef nonnull %.tr.ph42, ptr noundef nonnull %21)
  %brmerge = or i1 %spec.select.not, %22
  br i1 %brmerge, label %.thread18, label %tailrecurse.outer.backedge

tailrecurse.outer.backedge:                       ; preds = %25, %20
  %23 = phi i8 [ %5, %20 ], [ %16, %25 ]
  %.tr24.ph.be = phi ptr [ %.tr24.ph43, %20 ], [ %15, %25 ]
  %.tr.ph.be = getelementptr inbounds i8, ptr %.tr.ph42, i64 1
  %24 = icmp eq i8 %23, 0
  br i1 %24, label %tailrecurse.outer._crit_edge, label %.lr.ph

25:                                               ; preds = %.lr.ph.split
  br i1 %spec.select.not, label %.thread18, label %tailrecurse.outer.backedge

.thread18:                                        ; preds = %20, %25, %.thread.us, %tailrecurse.outer._crit_edge
  %.1 = phi i1 [ %19, %tailrecurse.outer._crit_edge ], [ false, %.thread.us ], [ %22, %20 ], [ false, %25 ]
  ret i1 %.1
}

attributes #0 = { nofree nosync 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" }

!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"}


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