; LLVM IR from kaynewbie/algorithm :: algorithm/LeetCode/Easy (implement-strStr)

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

@.str = external hidden unnamed_addr constant [15 x i8], align 1

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

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %12, %2
  store i32 -1, ptr %3, align 4
  br label %75

16:                                               ; preds = %12
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  store i32 0, ptr %3, align 4
  br label %75

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %23, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %24, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %8, align 4, !tbaa !10
  store i32 -1, ptr %9, align 4, !tbaa !10
  br label %25

25:                                               ; preds = %62, %22
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %67

30:                                               ; preds = %25
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = sext i8 %35 to i32
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %33, i32 noundef %36)
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1, !tbaa !9
  %40 = sext i8 %39 to i32
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  %44 = icmp eq i32 %40, %43
  br i1 %44, label %45, label %53

45:                                               ; preds = %30
  %46 = load i32, ptr %9, align 4, !tbaa !10
  %47 = icmp eq i32 %46, -1
  br i1 %47, label %48, label %50

48:                                               ; preds = %45
  %49 = load i32, ptr %8, align 4, !tbaa !10
  store i32 %49, ptr %9, align 4, !tbaa !10
  br label %50

50:                                               ; preds = %48, %45
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i32 1
  store ptr %52, ptr %7, align 8, !tbaa !5
  br label %62

53:                                               ; preds = %30
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load i8, ptr %54, align 1, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %53
  br label %67

59:                                               ; preds = %53
  store i32 -1, ptr %9, align 4, !tbaa !10
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %60, ptr %7, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %59
  br label %62

62:                                               ; preds = %61, %50
  %63 = load i32, ptr %8, align 4, !tbaa !10
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %8, align 4, !tbaa !10
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %65, i32 1
  store ptr %66, ptr %6, align 8, !tbaa !5
  br label %25, !llvm.loop !12

67:                                               ; preds = %58, %25
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load i8, ptr %68, align 1, !tbaa !9
  %70 = sext i8 %69 to i32
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %73

72:                                               ; preds = %67
  store i32 -1, ptr %9, align 4, !tbaa !10
  br label %73

73:                                               ; preds = %72, %67
  %74 = load i32, ptr %9, align 4, !tbaa !10
  store i32 %74, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %75

75:                                               ; preds = %73, %21, %15
  %76 = load i32, ptr %3, align 4
  ret i32 %76
}

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

declare i32 @printf(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 = { "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/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"

@.str = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @strStrMethod1(ptr noundef readonly %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %._crit_edge, label %5

5:                                                ; preds = %2
  %6 = load i8, ptr %1, align 1, !tbaa !5
  %7 = icmp eq i8 %6, 0
  br i1 %7, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %5
  %8 = load i8, ptr %0, align 1, !tbaa !5
  %.not31 = icmp eq i8 %8, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %22
  %9 = phi i8 [ %25, %22 ], [ %8, %.preheader ]
  %.035 = phi i32 [ %.2, %22 ], [ -1, %.preheader ]
  %.02034 = phi i32 [ %23, %22 ], [ 0, %.preheader ]
  %.02133 = phi ptr [ %.122, %22 ], [ %1, %.preheader ]
  %.02332 = phi ptr [ %24, %22 ], [ %0, %.preheader ]
  %10 = sext i8 %9 to i32
  %11 = load i8, ptr %.02133, align 1, !tbaa !5
  %12 = sext i8 %11 to i32
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %10, i32 noundef %12)
  %14 = load i8, ptr %.02332, align 1, !tbaa !5
  %15 = load i8, ptr %.02133, align 1, !tbaa !5
  %16 = icmp eq i8 %14, %15
  br i1 %16, label %17, label %20

17:                                               ; preds = %.lr.ph
  %18 = icmp eq i32 %.035, -1
  %spec.select = select i1 %18, i32 %.02034, i32 %.035
  %19 = getelementptr inbounds i8, ptr %.02133, i64 1
  br label %22

20:                                               ; preds = %.lr.ph
  %21 = icmp eq i8 %15, 0
  br i1 %21, label %._crit_edge, label %22

22:                                               ; preds = %20, %17
  %.122 = phi ptr [ %19, %17 ], [ %1, %20 ]
  %.2 = phi i32 [ %spec.select, %17 ], [ -1, %20 ]
  %23 = add nuw nsw i32 %.02034, 1
  %24 = getelementptr inbounds i8, ptr %.02332, i64 1
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %.not = icmp eq i8 %25, 0
  br i1 %.not, label %.._crit_edge.loopexit_crit_edge, label %.lr.ph, !llvm.loop !8

.._crit_edge.loopexit_crit_edge:                  ; preds = %22
  %.pre.pre = load i8, ptr %.122, align 1, !tbaa !5
  %26 = icmp eq i8 %.pre.pre, 0
  %27 = select i1 %26, i32 %.2, i32 -1
  br label %._crit_edge

._crit_edge:                                      ; preds = %20, %.preheader, %.._crit_edge.loopexit_crit_edge, %5, %2
  %.024 = phi i32 [ -1, %2 ], [ 0, %5 ], [ -1, %.preheader ], [ %27, %.._crit_edge.loopexit_crit_edge ], [ %.035, %20 ]
  ret i32 %.024
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { nofree 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 = { nofree nounwind "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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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