; LLVM IR from JessonYue/LeetCodeLearning :: Array/zhangjianan/20200603实现 strStr/strStr.ll (Z6strStrPcS_)

; 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z6strStrPcS_(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
  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) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call i64 @strlen(ptr noundef %11) #4
  %13 = trunc i64 %12 to i32
  store i32 %13, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i64 @strlen(ptr noundef %14) #4
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %7, align 4, !tbaa !9
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %87

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %81, %20
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 2, ptr %8, align 4
  br label %84

26:                                               ; preds = %21
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %27, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 0
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = sext i8 %35 to i32
  %37 = icmp eq i32 %32, %36
  br i1 %37, label %38, label %80

38:                                               ; preds = %26
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 1
  br i1 %40, label %41, label %43

41:                                               ; preds = %38
  %42 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %42, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %84

43:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %74, %43
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  store i32 5, ptr %8, align 4
  br label %77

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

65:                                               ; preds = %49
  store i32 5, ptr %8, align 4
  br label %77

66:                                               ; preds = %49
  %67 = load i32, ptr %10, align 4, !tbaa !9
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = sub nsw i32 %68, 1
  %70 = icmp eq i32 %67, %69
  br i1 %70, label %71, label %73

71:                                               ; preds = %66
  %72 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %72, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %77

73:                                               ; preds = %66
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %10, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %10, align 4, !tbaa !9
  br label %44, !llvm.loop !12

77:                                               ; preds = %71, %65, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %78 = load i32, ptr %8, align 4
  switch i32 %78, label %84 [
    i32 5, label %79
  ]

79:                                               ; preds = %77
  br label %80

80:                                               ; preds = %79, %26
  br label %81

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

84:                                               ; preds = %77, %41, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %85 = load i32, ptr %8, align 4
  switch i32 %85, label %87 [
    i32 2, label %86
  ]

86:                                               ; preds = %84
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %87

87:                                               ; preds = %86, %84, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %88 = load i32, ptr %3, align 4
  ret i32 %88
}

; 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 = { mustprogress 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++ 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: mustprogress nofree nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef i32 @_Z6strStrPcS_(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #2
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #2
  %.fr = freeze i64 %4
  %5 = trunc i64 %.fr to i32
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %.loopexit, label %.preheader33

.preheader33:                                     ; preds = %2
  %7 = trunc i64 %3 to i32
  %.not3038 = icmp sgt i32 %7, 0
  br i1 %.not3038, label %.lr.ph41, label %.loopexit

.lr.ph41:                                         ; preds = %.preheader33
  %8 = load i8, ptr %1, align 1, !tbaa !5
  %9 = icmp eq i32 %5, 1
  %10 = add i64 %.fr, 4294967295
  br i1 %9, label %.lr.ph41.split.us.preheader, label %.lr.ph41.split

.lr.ph41.split.us.preheader:                      ; preds = %.lr.ph41
  %wide.trip.count64 = and i64 %3, 2147483647
  br label %.lr.ph41.split.us

.lr.ph41.split.us:                                ; preds = %.lr.ph41.split.us.preheader, %.thread.us
  %indvars.iv61 = phi i64 [ 0, %.lr.ph41.split.us.preheader ], [ %indvars.iv.next62, %.thread.us ]
  %11 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv61
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = icmp eq i8 %12, %8
  br i1 %13, label %.loopexit.loopexit.split.loop.exit68, label %.thread.us

.thread.us:                                       ; preds = %.lr.ph41.split.us
  %indvars.iv.next62 = add nuw nsw i64 %indvars.iv61, 1
  %exitcond65.not = icmp eq i64 %indvars.iv.next62, %wide.trip.count64
  br i1 %exitcond65.not, label %.loopexit, label %.lr.ph41.split.us, !llvm.loop !8

.lr.ph41.split:                                   ; preds = %.lr.ph41
  %14 = icmp sgt i32 %5, 1
  br i1 %14, label %.lr.ph41.split.split.us.preheader, label %.loopexit

.lr.ph41.split.split.us.preheader:                ; preds = %.lr.ph41.split
  %15 = and i64 %10, 4294967295
  %wide.trip.count = and i64 %3, 2147483647
  %16 = getelementptr inbounds i8, ptr %1, i64 1
  br label %.lr.ph41.split.split.us

.lr.ph41.split.split.us:                          ; preds = %.lr.ph41.split.split.us.preheader, %.thread.us47
  %indvars.iv58 = phi i64 [ 0, %.lr.ph41.split.split.us.preheader ], [ %indvars.iv.next59, %.thread.us47 ]
  %17 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv58
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = icmp eq i8 %18, %8
  br i1 %19, label %.preheader.us.preheader, label %.thread.us47

.preheader.us.preheader:                          ; preds = %.lr.ph41.split.split.us
  %invariant.gep = getelementptr inbounds i8, ptr %0, i64 %indvars.iv58
  %gep73 = getelementptr inbounds i8, ptr %invariant.gep, i64 1
  %20 = load i8, ptr %gep73, align 1, !tbaa !5
  %21 = load i8, ptr %16, align 1, !tbaa !5
  %.not.us74 = icmp eq i8 %20, %21
  br i1 %.not.us74, label %.lr.ph, label %.thread.us47

.preheader.us:                                    ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv75, 1
  %gep = getelementptr inbounds i8, ptr %invariant.gep, i64 %indvars.iv.next
  %22 = load i8, ptr %gep, align 1, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %.not.us = icmp eq i8 %22, %24
  br i1 %.not.us, label %.lr.ph, label %.thread.us47

.thread.us47:                                     ; preds = %.preheader.us, %.preheader.us.preheader, %.lr.ph41.split.split.us
  %indvars.iv.next59 = add nuw nsw i64 %indvars.iv58, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next59, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph41.split.split.us, !llvm.loop !8

.lr.ph:                                           ; preds = %.preheader.us.preheader, %.preheader.us
  %indvars.iv75 = phi i64 [ %indvars.iv.next, %.preheader.us ], [ 1, %.preheader.us.preheader ]
  %25 = icmp eq i64 %indvars.iv75, %15
  br i1 %25, label %.loopexit.loopexit53, label %.preheader.us

.loopexit.loopexit53:                             ; preds = %.lr.ph
  %26 = trunc nuw nsw i64 %indvars.iv58 to i32
  br label %.loopexit

.loopexit.loopexit.split.loop.exit68:             ; preds = %.lr.ph41.split.us
  %27 = trunc nuw nsw i64 %indvars.iv61 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.thread.us47, %.thread.us, %.loopexit.loopexit.split.loop.exit68, %.lr.ph41.split, %.loopexit.loopexit53, %.preheader33, %2
  %.4 = phi i32 [ 0, %2 ], [ -1, %.preheader33 ], [ %26, %.loopexit.loopexit53 ], [ -1, %.lr.ph41.split ], [ %27, %.loopexit.loopexit.split.loop.exit68 ], [ -1, %.thread.us ], [ -1, %.thread.us47 ]
  ret i32 %.4
}

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

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


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