; LLVM IR from wuzhouhui/leetcode :: 28_my_strstr (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: nounwind uwtable
define dso_local i32 @strStr(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %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
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %17

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

17:                                               ; preds = %14, %2
  store i32 -1, ptr %3, align 4
  br label %86

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call i64 @strlen(ptr noundef %19) #4
  %21 = trunc i64 %20 to i32
  store i32 %21, ptr %6, align 4, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i64 @strlen(ptr noundef %22) #4
  %24 = trunc i64 %23 to i32
  store i32 %24, ptr %7, align 4, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %18
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %85

29:                                               ; preds = %18
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %85

33:                                               ; preds = %29
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %81, %33
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = sub nsw i32 %35, %36
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = icmp sge i32 %37, %38
  br i1 %39, label %40, label %84

40:                                               ; preds = %34
  %41 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %41, ptr %9, align 4, !tbaa !9
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %65, %40
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !11
  %48 = icmp ne i8 %47, 0
  br i1 %48, label %49, label %70

49:                                               ; preds = %42
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = sext i8 %54 to i32
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %56, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !11
  %61 = sext i8 %60 to i32
  %62 = icmp ne i32 %55, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %49
  br label %70

64:                                               ; preds = %49
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %9, align 4, !tbaa !9
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %10, align 4, !tbaa !9
  br label %42, !llvm.loop !12

70:                                               ; preds = %63, %42
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !11
  %76 = sext i8 %75 to i32
  %77 = icmp eq i32 %76, 0
  br i1 %77, label %78, label %80

78:                                               ; preds = %70
  %79 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %79, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %85

80:                                               ; preds = %70
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %8, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %8, align 4, !tbaa !9
  br label %34, !llvm.loop !14

84:                                               ; preds = %34
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %85

85:                                               ; preds = %84, %78, %32, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  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 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %86

86:                                               ; preds = %85, %17
  %87 = load i32, ptr %3, align 4
  ret i32 %87
}

; 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !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 nounwind memory(argmem: read) uwtable
define dso_local i32 @strStr(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 %5, label %.thread

5:                                                ; preds = %2
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #2
  %7 = trunc i64 %6 to i32
  %8 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #2
  %9 = trunc i64 %8 to i32
  %10 = icmp slt i32 %7, %9
  br i1 %10, label %.thread, label %11

11:                                               ; preds = %5
  %12 = icmp eq i32 %9, 0
  br i1 %12, label %.thread, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %11
  %13 = load i8, ptr %1, align 1, !tbaa !5
  %.not3237 = icmp eq i8 %13, 0
  br i1 %.not3237, label %.thread, label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %21
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %21 ], [ 0, %.preheader.lr.ph ]
  br label %14

14:                                               ; preds = %.preheader, %18
  %indvars.iv47 = phi i64 [ %indvars.iv45, %.preheader ], [ %indvars.iv.next48, %18 ]
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %18 ]
  %15 = phi i8 [ %13, %.preheader ], [ %20, %18 ]
  %16 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv47
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %.not33 = icmp eq i8 %17, %15
  br i1 %.not33, label %18, label %21

18:                                               ; preds = %14
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %.not32 = icmp eq i8 %20, 0
  br i1 %.not32, label %.thread.loopexit, label %14, !llvm.loop !8

21:                                               ; preds = %14
  %indvars.iv.next46 = add nuw i64 %indvars.iv45, 1
  %indvars = trunc i64 %indvars.iv.next46 to i32
  %22 = sub nsw i32 %7, %indvars
  %.not = icmp slt i32 %22, %9
  br i1 %.not, label %.thread, label %.preheader, !llvm.loop !10

.thread.loopexit:                                 ; preds = %18
  %indvars49.le = trunc i64 %indvars.iv45 to i32
  br label %.thread

.thread:                                          ; preds = %21, %.thread.loopexit, %.preheader.lr.ph, %5, %11, %2
  %.1 = phi i32 [ -1, %2 ], [ -1, %5 ], [ 0, %11 ], [ 0, %.preheader.lr.ph ], [ %indvars49.le, %.thread.loopexit ], [ -1, %21 ]
  ret i32 %.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}


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