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

; 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: nounwind uwtable
define dso_local i32 @strStrMethod3(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %15

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

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

16:                                               ; preds = %12
  br label %17

17:                                               ; preds = %62, %16
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %19, i64 %21
  store ptr %22, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %23, ptr %8, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %44, %18
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %42

29:                                               ; preds = %24
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %42

34:                                               ; preds = %29
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = sext i8 %36 to i32
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = sext i8 %39 to i32
  %41 = icmp eq i32 %37, %40
  br label %42

42:                                               ; preds = %34, %29, %24
  %43 = phi i1 [ false, %29 ], [ false, %24 ], [ %41, %34 ]
  br i1 %43, label %44, label %49

44:                                               ; preds = %42
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i32 1
  store ptr %46, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i32 1
  store ptr %48, ptr %8, align 8, !tbaa !5
  br label %24, !llvm.loop !12

49:                                               ; preds = %42
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i8, ptr %50, align 1, !tbaa !11
  %52 = sext i8 %51 to i32
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %49
  %55 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %55, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %65

56:                                               ; preds = %49
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load i8, ptr %57, align 1, !tbaa !11
  %59 = sext i8 %58 to i32
  %60 = icmp eq i32 %59, 0
  br i1 %60, label %61, label %62

61:                                               ; preds = %56
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %65

62:                                               ; preds = %56
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %6, align 4, !tbaa !9
  br label %17

65:                                               ; preds = %61, %54, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %66 = load i32, ptr %3, align 4
  ret i32 %66
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !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 norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @strStrMethod3(ptr noundef readonly %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp ne ptr %0, null
  %4 = icmp ne ptr %1, null
  %or.cond = and i1 %3, %4
  br i1 %or.cond, label %.preheader, label %.loopexit

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

.lr.ph:                                           ; preds = %.preheader, %.thread
  %indvars.iv = phi i64 [ %indvars.iv.next, %.thread ], [ 0, %.preheader ]
  %6 = phi i8 [ %21, %.thread ], [ %5, %.preheader ]
  %7 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  br label %8

8:                                                ; preds = %.lr.ph, %12
  %9 = phi i8 [ %6, %.lr.ph ], [ %15, %12 ]
  %.027 = phi ptr [ %1, %.lr.ph ], [ %14, %12 ]
  %.01626 = phi ptr [ %7, %.lr.ph ], [ %13, %12 ]
  %10 = load i8, ptr %.027, align 1, !tbaa !5
  %11 = icmp eq i8 %9, %10
  br i1 %11, label %12, label %.critedge.thread

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %.01626, i64 1
  %14 = getelementptr inbounds i8, ptr %.027, i64 1
  %15 = load i8, ptr %13, align 1, !tbaa !5
  %.not = icmp eq i8 %15, 0
  br i1 %.not, label %.critedge.loopexit, label %8, !llvm.loop !8

.critedge.loopexit:                               ; preds = %12
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge.loopexit36:                             ; preds = %.thread
  %17 = trunc nuw i64 %indvars.iv.next to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit36, %.critedge.loopexit, %.preheader
  %.017.lcssa = phi i32 [ 0, %.preheader ], [ %16, %.critedge.loopexit ], [ %17, %.critedge.loopexit36 ]
  %.0.lcssa = phi ptr [ %1, %.preheader ], [ %14, %.critedge.loopexit ], [ %1, %.critedge.loopexit36 ]
  %.pr = load i8, ptr %.0.lcssa, align 1, !tbaa !5
  %18 = icmp eq i8 %.pr, 0
  %spec.select = select i1 %18, i32 %.017.lcssa, i32 -1
  br label %.loopexit

.critedge.thread:                                 ; preds = %8
  %19 = icmp eq i8 %10, 0
  br i1 %19, label %.loopexit.loopexit, label %.thread

.thread:                                          ; preds = %.critedge.thread
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %.not25 = icmp eq i8 %21, 0
  br i1 %.not25, label %.critedge.loopexit36, label %.lr.ph

.loopexit.loopexit:                               ; preds = %.critedge.thread
  %22 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.critedge, %2
  %.018 = phi i32 [ -1, %2 ], [ %spec.select, %.critedge ], [ %22, %.loopexit.loopexit ]
  ret i32 %.018
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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