; LLVM IR from Ayon-SSP/The-SDE-Prep :: 3]_CP/DP/Longest Common Subsequence (Longest Common Substring Length)

; 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 uwtable
define dso_local noundef i32 @_Z10lcs_lengthNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_ii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  %20 = zext i32 %19 to i64
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  %23 = zext i32 %22 to i64
  %24 = call ptr @llvm.stacksave.p0()
  store ptr %24, ptr %9, align 8
  %25 = mul nuw i64 %20, %23
  %26 = alloca i32, i64 %25, align 16
  store i64 %20, ptr %10, align 8
  store i64 %23, ptr %11, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %57, %4
  %28 = load i32, ptr %12, align 4, !tbaa !9
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = icmp sle i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %60

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %53, %32
  %34 = load i32, ptr %14, align 4, !tbaa !9
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 5, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %56

38:                                               ; preds = %33
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %44, label %41

41:                                               ; preds = %38
  %42 = load i32, ptr %14, align 4, !tbaa !9
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %52

44:                                               ; preds = %41, %38
  %45 = load i32, ptr %12, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = mul nsw i64 %46, %23
  %48 = getelementptr inbounds i32, ptr %26, i64 %47
  %49 = load i32, ptr %14, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i32, ptr %48, i64 %50
  store i32 0, ptr %51, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %44, %41
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %14, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %14, align 4, !tbaa !9
  br label %33, !llvm.loop !11

56:                                               ; preds = %37
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %12, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %12, align 4, !tbaa !9
  br label %27, !llvm.loop !13

60:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  store i32 -2147483648, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  store i32 1, ptr %16, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %127, %60
  %62 = load i32, ptr %16, align 4, !tbaa !9
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = icmp sle i32 %62, %63
  br i1 %64, label %66, label %65

65:                                               ; preds = %61
  store i32 8, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  br label %130

66:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  store i32 1, ptr %17, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %123, %66
  %68 = load i32, ptr %17, align 4, !tbaa !9
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = icmp sle i32 %68, %69
  br i1 %70, label %72, label %71

71:                                               ; preds = %67
  store i32 11, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  br label %126

72:                                               ; preds = %67
  %73 = load i32, ptr %16, align 4, !tbaa !9
  %74 = sub nsw i32 %73, 1
  %75 = sext i32 %74 to i64
  %76 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %75)
  %77 = load i8, ptr %76, align 1, !tbaa !14
  %78 = sext i8 %77 to i32
  %79 = load i32, ptr %17, align 4, !tbaa !9
  %80 = sub nsw i32 %79, 1
  %81 = sext i32 %80 to i64
  %82 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %81)
  %83 = load i8, ptr %82, align 1, !tbaa !14
  %84 = sext i8 %83 to i32
  %85 = icmp eq i32 %78, %84
  br i1 %85, label %86, label %105

86:                                               ; preds = %72
  %87 = load i32, ptr %16, align 4, !tbaa !9
  %88 = sub nsw i32 %87, 1
  %89 = sext i32 %88 to i64
  %90 = mul nsw i64 %89, %23
  %91 = getelementptr inbounds i32, ptr %26, i64 %90
  %92 = load i32, ptr %17, align 4, !tbaa !9
  %93 = sub nsw i32 %92, 1
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds i32, ptr %91, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !9
  %97 = add nsw i32 1, %96
  %98 = load i32, ptr %16, align 4, !tbaa !9
  %99 = sext i32 %98 to i64
  %100 = mul nsw i64 %99, %23
  %101 = getelementptr inbounds i32, ptr %26, i64 %100
  %102 = load i32, ptr %17, align 4, !tbaa !9
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds i32, ptr %101, i64 %103
  store i32 %97, ptr %104, align 4, !tbaa !9
  br label %113

105:                                              ; preds = %72
  %106 = load i32, ptr %16, align 4, !tbaa !9
  %107 = sext i32 %106 to i64
  %108 = mul nsw i64 %107, %23
  %109 = getelementptr inbounds i32, ptr %26, i64 %108
  %110 = load i32, ptr %17, align 4, !tbaa !9
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds i32, ptr %109, i64 %111
  store i32 0, ptr %112, align 4, !tbaa !9
  br label %113

113:                                              ; preds = %105, %86
  %114 = load i32, ptr %16, align 4, !tbaa !9
  %115 = sext i32 %114 to i64
  %116 = mul nsw i64 %115, %23
  %117 = getelementptr inbounds i32, ptr %26, i64 %116
  %118 = load i32, ptr %17, align 4, !tbaa !9
  %119 = sext i32 %118 to i64
  %120 = getelementptr inbounds i32, ptr %117, i64 %119
  %121 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %15, ptr noundef nonnull align 4 dereferenceable(4) %120)
  %122 = load i32, ptr %121, align 4, !tbaa !9
  store i32 %122, ptr %15, align 4, !tbaa !9
  br label %123

123:                                              ; preds = %113
  %124 = load i32, ptr %17, align 4, !tbaa !9
  %125 = add nsw i32 %124, 1
  store i32 %125, ptr %17, align 4, !tbaa !9
  br label %67, !llvm.loop !15

126:                                              ; preds = %71
  br label %127

127:                                              ; preds = %126
  %128 = load i32, ptr %16, align 4, !tbaa !9
  %129 = add nsw i32 %128, 1
  store i32 %129, ptr %16, align 4, !tbaa !9
  br label %61, !llvm.loop !16

130:                                              ; preds = %65
  %131 = load i32, ptr %15, align 4, !tbaa !9
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  %132 = load ptr, ptr %9, align 8
  call void @llvm.stackrestore.p0(ptr %132)
  ret i32 %131
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

attributes #0 = { mustprogress 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 }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { inlinehint 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 #5 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


; 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 nounwind uwtable
define dso_local noundef i32 @_Z10lcs_lengthNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_ii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  %6 = add i32 %2, 1
  %7 = zext i32 %6 to i64
  %8 = add i32 %3, 1
  %9 = zext i32 %8 to i64
  %10 = mul nuw i64 %9, %7
  %11 = alloca i32, i64 %10, align 16
  %.not39 = icmp slt i32 %2, 0
  br i1 %.not39, label %._crit_edge41.thread, label %.preheader36.lr.ph

._crit_edge41.thread:                             ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #5
  br label %._crit_edge47

.preheader36.lr.ph:                               ; preds = %4
  %.not3537 = icmp slt i32 %3, 0
  br i1 %.not3537, label %._crit_edge41, label %.preheader36.preheader

.preheader36.preheader:                           ; preds = %.preheader36.lr.ph
  %12 = shl nuw nsw i64 %9, 2
  %smax = tail call i32 @llvm.smax.i32(i32 %6, i32 1)
  %wide.trip.count57 = zext nneg i32 %smax to i64
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %11, i8 0, i64 %12, i1 false), !tbaa !5
  %exitcond58.peel = icmp slt i32 %6, 2
  br i1 %exitcond58.peel, label %._crit_edge41, label %.preheader36

.preheader36:                                     ; preds = %.preheader36.preheader, %.preheader36
  %indvar = phi i64 [ %indvar.next, %.preheader36 ], [ 1, %.preheader36.preheader ]
  %13 = mul nuw nsw i64 %indvar, %9
  %14 = getelementptr inbounds i32, ptr %11, i64 %13
  store i32 0, ptr %14, align 4, !tbaa !5
  %indvar.next = add nuw nsw i64 %indvar, 1
  %exitcond58 = icmp eq i64 %indvar.next, %wide.trip.count57
  br i1 %exitcond58, label %._crit_edge41, label %.preheader36, !llvm.loop !9

._crit_edge41:                                    ; preds = %.preheader36.preheader, %.preheader36, %.preheader36.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #5
  store i32 -2147483648, ptr %5, align 4, !tbaa !5
  %.not3345 = icmp eq i32 %2, 0
  %.not3442 = icmp slt i32 %3, 1
  %or.cond = or i1 %.not3345, %.not3442
  br i1 %or.cond, label %._crit_edge47, label %.preheader

.preheader:                                       ; preds = %._crit_edge41, %._crit_edge44
  %indvars.iv64 = phi i64 [ %indvars.iv.next65, %._crit_edge44 ], [ 1, %._crit_edge41 ]
  %15 = add nsw i64 %indvars.iv64, -1
  %16 = mul nuw nsw i64 %indvars.iv64, %9
  %17 = getelementptr inbounds i32, ptr %11, i64 %16
  %18 = mul nuw nsw i64 %15, %9
  %19 = getelementptr inbounds i32, ptr %11, i64 %18
  br label %21

._crit_edge47:                                    ; preds = %._crit_edge44, %._crit_edge41.thread, %._crit_edge41
  %20 = phi i32 [ -2147483648, %._crit_edge41 ], [ -2147483648, %._crit_edge41.thread ], [ %36, %._crit_edge44 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #5
  ret i32 %20

._crit_edge44:                                    ; preds = %32
  %indvars.iv.next65 = add nuw nsw i64 %indvars.iv64, 1
  %exitcond68.not = icmp eq i64 %indvars.iv.next65, %7
  br i1 %exitcond68.not, label %._crit_edge47, label %.preheader, !llvm.loop !12

21:                                               ; preds = %.preheader, %32
  %indvars.iv59 = phi i64 [ 1, %.preheader ], [ %indvars.iv.next60, %32 ]
  %22 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %15)
  %23 = load i8, ptr %22, align 1, !tbaa !13
  %24 = add nsw i64 %indvars.iv59, -1
  %25 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %24)
  %26 = load i8, ptr %25, align 1, !tbaa !13
  %27 = icmp eq i8 %23, %26
  br i1 %27, label %28, label %32

28:                                               ; preds = %21
  %29 = getelementptr inbounds i32, ptr %19, i64 %24
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  br label %32

32:                                               ; preds = %21, %28
  %.sink = phi i32 [ %31, %28 ], [ 0, %21 ]
  %33 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv59
  store i32 %.sink, ptr %33, align 4, !tbaa !5
  %34 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv59
  %35 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %34)
  %36 = load i32, ptr %35, align 4, !tbaa !5
  store i32 %36, ptr %5, align 4, !tbaa !5
  %indvars.iv.next60 = add nuw nsw i64 %indvars.iv59, 1
  %exitcond63.not = icmp eq i64 %indvars.iv.next60, %9
  br i1 %exitcond63.not, label %._crit_edge44, label %21, !llvm.loop !14
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 1}
!12 = distinct !{!12, !10}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !10}


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