; LLVM IR from Py-Contributors/AlgorithmsAndDataStructure :: C++/Algorithms/DynamicPrograming (Lcs)

; 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 @_Z3lcsNSt7__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
  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
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = add nsw i32 %17, 1
  %19 = zext i32 %18 to i64
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  %22 = zext i32 %21 to i64
  %23 = call ptr @llvm.stacksave.p0()
  store ptr %23, ptr %9, align 8
  %24 = mul nuw i64 %19, %22
  %25 = alloca i32, i64 %24, align 16
  store i64 %19, ptr %10, align 8
  store i64 %22, 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 %26

26:                                               ; preds = %51, %4
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %32, label %31

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

32:                                               ; preds = %26
  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 = %47, %32
  %34 = load i32, ptr %14, align 4, !tbaa !9
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  %37 = icmp slt i32 %34, %36
  br i1 %37, label %39, label %38

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

39:                                               ; preds = %33
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = mul nsw i64 %41, %22
  %43 = getelementptr inbounds i32, ptr %25, i64 %42
  %44 = load i32, ptr %14, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %43, i64 %45
  store i32 0, ptr %46, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %39
  %48 = load i32, ptr %14, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %14, align 4, !tbaa !9
  br label %33, !llvm.loop !11

50:                                               ; preds = %38
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %12, align 4, !tbaa !9
  br label %26, !llvm.loop !13

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

55:                                               ; preds = %132, %54
  %56 = load i32, ptr %15, align 4, !tbaa !9
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  %59 = icmp slt i32 %56, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %55
  store i32 8, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %135

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

62:                                               ; preds = %128, %61
  %63 = load i32, ptr %16, align 4, !tbaa !9
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  %66 = icmp slt i32 %63, %65
  br i1 %66, label %68, label %67

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

68:                                               ; preds = %62
  %69 = load i32, ptr %15, align 4, !tbaa !9
  %70 = sub nsw i32 %69, 1
  %71 = sext i32 %70 to i64
  %72 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %71)
  %73 = load i8, ptr %72, align 1, !tbaa !14
  %74 = sext i8 %73 to i32
  %75 = load i32, ptr %16, align 4, !tbaa !9
  %76 = sub nsw i32 %75, 1
  %77 = sext i32 %76 to i64
  %78 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %77)
  %79 = load i8, ptr %78, align 1, !tbaa !14
  %80 = sext i8 %79 to i32
  %81 = icmp eq i32 %74, %80
  br i1 %81, label %82, label %101

82:                                               ; preds = %68
  %83 = load i32, ptr %15, align 4, !tbaa !9
  %84 = sub nsw i32 %83, 1
  %85 = sext i32 %84 to i64
  %86 = mul nsw i64 %85, %22
  %87 = getelementptr inbounds i32, ptr %25, i64 %86
  %88 = load i32, ptr %16, align 4, !tbaa !9
  %89 = sub nsw i32 %88, 1
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i32, ptr %87, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !9
  %93 = add nsw i32 1, %92
  %94 = load i32, ptr %15, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = mul nsw i64 %95, %22
  %97 = getelementptr inbounds i32, ptr %25, i64 %96
  %98 = load i32, ptr %16, align 4, !tbaa !9
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds i32, ptr %97, i64 %99
  store i32 %93, ptr %100, align 4, !tbaa !9
  br label %127

101:                                              ; preds = %68
  %102 = load i32, ptr %15, align 4, !tbaa !9
  %103 = sub nsw i32 %102, 1
  %104 = sext i32 %103 to i64
  %105 = mul nsw i64 %104, %22
  %106 = getelementptr inbounds i32, ptr %25, i64 %105
  %107 = load i32, ptr %16, align 4, !tbaa !9
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds i32, ptr %106, i64 %108
  %110 = load i32, ptr %15, align 4, !tbaa !9
  %111 = sext i32 %110 to i64
  %112 = mul nsw i64 %111, %22
  %113 = getelementptr inbounds i32, ptr %25, i64 %112
  %114 = load i32, ptr %16, align 4, !tbaa !9
  %115 = sub nsw i32 %114, 1
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds i32, ptr %113, i64 %116
  %118 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %109, ptr noundef nonnull align 4 dereferenceable(4) %117)
  %119 = load i32, ptr %118, align 4, !tbaa !9
  %120 = load i32, ptr %15, align 4, !tbaa !9
  %121 = sext i32 %120 to i64
  %122 = mul nsw i64 %121, %22
  %123 = getelementptr inbounds i32, ptr %25, i64 %122
  %124 = load i32, ptr %16, align 4, !tbaa !9
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds i32, ptr %123, i64 %125
  store i32 %119, ptr %126, align 4, !tbaa !9
  br label %127

127:                                              ; preds = %101, %82
  br label %128

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

131:                                              ; preds = %67
  br label %132

132:                                              ; preds = %131
  %133 = load i32, ptr %15, align 4, !tbaa !9
  %134 = add nsw i32 %133, 1
  store i32 %134, ptr %15, align 4, !tbaa !9
  br label %55, !llvm.loop !16

135:                                              ; preds = %60
  %136 = load i32, ptr %8, align 4, !tbaa !9
  %137 = sext i32 %136 to i64
  %138 = mul nsw i64 %137, %22
  %139 = getelementptr inbounds i32, ptr %25, i64 %138
  %140 = load i32, ptr %7, align 4, !tbaa !9
  %141 = sext i32 %140 to i64
  %142 = getelementptr inbounds i32, ptr %139, i64 %141
  %143 = load i32, ptr %142, align 4, !tbaa !9
  store i32 1, ptr %13, align 4
  %144 = load ptr, ptr %9, align 8
  call void @llvm.stackrestore.p0(ptr %144)
  ret i32 %143
}

; 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 @_Z3lcsNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_ii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = add i32 %3, 1
  %6 = zext i32 %5 to i64
  %7 = add i32 %2, 1
  %8 = zext i32 %7 to i64
  %9 = mul nuw i64 %6, %8
  %10 = alloca i32, i64 %9, align 16
  %.not41 = icmp slt i32 %3, 0
  br i1 %.not41, label %._crit_edge48, label %.preheader38.lr.ph

.preheader38.lr.ph:                               ; preds = %4
  %.not3639 = icmp slt i32 %2, 0
  br i1 %.not3639, label %.preheader37, label %.preheader38.preheader

.preheader38.preheader:                           ; preds = %.preheader38.lr.ph
  %11 = shl i64 %9, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %10, i8 0, i64 %11, i1 false), !tbaa !5
  br label %.preheader37

.preheader37:                                     ; preds = %.preheader38.lr.ph, %.preheader38.preheader
  %.not3446 = icmp eq i32 %3, 0
  %.not3543 = icmp slt i32 %2, 1
  %or.cond = or i1 %.not3446, %.not3543
  br i1 %or.cond, label %._crit_edge48, label %.preheader

.preheader:                                       ; preds = %.preheader37, %._crit_edge45
  %indvars.iv54 = phi i64 [ %indvars.iv.next55, %._crit_edge45 ], [ 1, %.preheader37 ]
  %12 = add nsw i64 %indvars.iv54, -1
  %13 = mul nuw nsw i64 %12, %8
  %14 = getelementptr inbounds i32, ptr %10, i64 %13
  %15 = mul nuw nsw i64 %indvars.iv54, %8
  %16 = getelementptr inbounds i32, ptr %10, i64 %15
  br label %23

._crit_edge48:                                    ; preds = %._crit_edge45, %4, %.preheader37
  %17 = sext i32 %3 to i64
  %18 = mul nsw i64 %17, %8
  %19 = getelementptr inbounds i32, ptr %10, i64 %18
  %20 = sext i32 %2 to i64
  %21 = getelementptr inbounds i32, ptr %19, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  ret i32 %22

._crit_edge45:                                    ; preds = %39
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %exitcond58.not = icmp eq i64 %indvars.iv.next55, %6
  br i1 %exitcond58.not, label %._crit_edge48, label %.preheader, !llvm.loop !9

23:                                               ; preds = %.preheader, %39
  %indvars.iv = phi i64 [ 1, %.preheader ], [ %indvars.iv.next, %39 ]
  %24 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %12)
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = add nsw i64 %indvars.iv, -1
  %27 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %26)
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = icmp eq i8 %25, %28
  br i1 %29, label %30, label %34

30:                                               ; preds = %23
  %31 = getelementptr inbounds i32, ptr %14, i64 %26
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  br label %39

34:                                               ; preds = %23
  %35 = getelementptr inbounds i32, ptr %14, i64 %indvars.iv
  %36 = getelementptr inbounds i32, ptr %16, i64 %26
  %37 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %35, ptr noundef nonnull align 4 dereferenceable(4) %36)
  %38 = load i32, ptr %37, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %30, %34
  %.sink = phi i32 [ %33, %30 ], [ %38, %34 ]
  %40 = getelementptr inbounds i32, ptr %16, i64 %indvars.iv
  store i32 %.sink, ptr %40, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %8
  br i1 %exitcond.not, label %._crit_edge45, label %23, !llvm.loop !12
}

; 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 #1

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

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 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass