; LLVM IR from ippeb/ACM-ICPC :: dynamic_programming/LCS/lcs_length_iterative.ll (Z10lcs_lengthPcS_)

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

@L = external dso_local global [1000 x [1000 x i32]], align 16
@i = external dso_local global i32, align 4
@j = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@n = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z10lcs_lengthPcS_(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = call i64 @strlen(ptr noundef %5) #3
  %7 = trunc i64 %6 to i32
  store i32 %7, ptr @m, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call i64 @strlen(ptr noundef %8) #3
  %10 = trunc i64 %9 to i32
  store i32 %10, ptr @n, align 4, !tbaa !9
  %11 = load i32, ptr @m, align 4, !tbaa !9
  store i32 %11, ptr @i, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %103, %2
  %13 = load i32, ptr @i, align 4, !tbaa !9
  %14 = icmp sge i32 %13, 0
  br i1 %14, label %15, label %106

15:                                               ; preds = %12
  %16 = load i32, ptr @n, align 4, !tbaa !9
  store i32 %16, ptr @j, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %99, %15
  %18 = load i32, ptr @j, align 4, !tbaa !9
  %19 = icmp sge i32 %18, 0
  br i1 %19, label %20, label %102

20:                                               ; preds = %17
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr @i, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = sext i8 %25 to i32
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %36, label %28

28:                                               ; preds = %20
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr @j, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %29, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %43

36:                                               ; preds = %28, %20
  %37 = load i32, ptr @i, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %38
  %40 = load i32, ptr @j, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1000 x i32], ptr %39, i64 0, i64 %41
  store i32 0, ptr %42, align 4, !tbaa !9
  br label %98

43:                                               ; preds = %28
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load i32, ptr @i, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = sext i8 %48 to i32
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load i32, ptr @j, 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 = icmp eq i32 %49, %55
  br i1 %56, label %57, label %74

57:                                               ; preds = %43
  %58 = load i32, ptr @i, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %60
  %62 = load i32, ptr @j, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1000 x i32], ptr %61, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = add nsw i32 1, %66
  %68 = load i32, ptr @i, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %69
  %71 = load i32, ptr @j, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [1000 x i32], ptr %70, i64 0, i64 %72
  store i32 %67, ptr %73, align 4, !tbaa !9
  br label %97

74:                                               ; preds = %43
  %75 = load i32, ptr @i, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %77
  %79 = load i32, ptr @j, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [1000 x i32], ptr %78, i64 0, i64 %80
  %82 = load i32, ptr @i, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %83
  %85 = load i32, ptr @j, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [1000 x i32], ptr %84, i64 0, i64 %87
  %89 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %81, ptr noundef nonnull align 4 dereferenceable(4) %88)
  %90 = load i32, ptr %89, align 4, !tbaa !9
  %91 = load i32, ptr @i, align 4, !tbaa !9
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %92
  %94 = load i32, ptr @j, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [1000 x i32], ptr %93, i64 0, i64 %95
  store i32 %90, ptr %96, align 4, !tbaa !9
  br label %97

97:                                               ; preds = %74, %57
  br label %98

98:                                               ; preds = %97, %36
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr @j, align 4, !tbaa !9
  %101 = add nsw i32 %100, -1
  store i32 %101, ptr @j, align 4, !tbaa !9
  br label %17, !llvm.loop !12

102:                                              ; preds = %17
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr @i, align 4, !tbaa !9
  %105 = add nsw i32 %104, -1
  store i32 %105, ptr @i, align 4, !tbaa !9
  br label %12, !llvm.loop !14

106:                                              ; preds = %12
  %107 = load i32, ptr @L, align 16, !tbaa !9
  ret i32 %107
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

; 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)) #2

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 = { 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 #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 = { 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"

@L = external dso_local global [1000 x [1000 x i32]], align 16
@i = external dso_local local_unnamed_addr global i32, align 4
@j = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z10lcs_lengthPcS_(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) #3
  %4 = trunc i64 %3 to i32
  store i32 %4, ptr @m, align 4, !tbaa !5
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %6 = trunc i64 %5 to i32
  store i32 %6, ptr @n, align 4, !tbaa !5
  store i32 %4, ptr @i, align 4, !tbaa !5
  %7 = icmp sgt i32 %4, -1
  br i1 %7, label %.lr.ph11, label %._crit_edge12

.lr.ph11:                                         ; preds = %2
  %8 = icmp sgt i32 %6, -1
  br i1 %8, label %.lr.ph11.split, label %.lr.ph11.split.us

.lr.ph11.split.us:                                ; preds = %.lr.ph11
  store i32 %6, ptr @j, align 4, !tbaa !5
  store i32 -1, ptr @i, align 4, !tbaa !5
  br label %._crit_edge12

.lr.ph11.split:                                   ; preds = %.lr.ph11, %._crit_edge
  %9 = phi i32 [ %51, %._crit_edge ], [ %4, %.lr.ph11 ]
  %10 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %10, ptr @j, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, -1
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph11.split, %45
  %12 = phi i32 [ %47, %45 ], [ %9, %.lr.ph11.split ]
  %storemerge89 = phi i32 [ %48, %45 ], [ %10, %.lr.ph11.split ]
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i8, ptr %0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = icmp eq i8 %15, 0
  %.pre = zext nneg i32 %storemerge89 to i64
  br i1 %16, label %.lr.ph._crit_edge, label %17

17:                                               ; preds = %.lr.ph
  %18 = getelementptr inbounds i8, ptr %1, i64 %.pre
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = icmp eq i8 %19, 0
  br i1 %20, label %.lr.ph._crit_edge, label %22

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %17
  %21 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %13, i64 %.pre
  store i32 0, ptr %21, align 4, !tbaa !5
  br label %45

22:                                               ; preds = %17
  %23 = icmp eq i8 %15, %19
  %24 = add nsw i32 %12, 1
  %25 = sext i32 %24 to i64
  br i1 %23, label %26, label %33

26:                                               ; preds = %22
  %27 = add nuw nsw i32 %storemerge89, 1
  %28 = zext nneg i32 %27 to i64
  %29 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %25, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  %32 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %13, i64 %.pre
  store i32 %31, ptr %32, align 4, !tbaa !5
  br label %45

33:                                               ; preds = %22
  %34 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %25, i64 %.pre
  %35 = add nuw nsw i32 %storemerge89, 1
  %36 = zext nneg i32 %35 to i64
  %37 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %13, i64 %36
  %38 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %34, ptr noundef nonnull align 4 dereferenceable(4) %37)
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load i32, ptr @i, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = load i32, ptr @j, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %41, i64 %43
  store i32 %39, ptr %44, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %.lr.ph._crit_edge, %33, %26
  %46 = phi i32 [ %storemerge89, %.lr.ph._crit_edge ], [ %42, %33 ], [ %storemerge89, %26 ]
  %47 = phi i32 [ %12, %.lr.ph._crit_edge ], [ %40, %33 ], [ %12, %26 ]
  %48 = add nsw i32 %46, -1
  store i32 %48, ptr @j, align 4, !tbaa !5
  %49 = icmp sgt i32 %46, 0
  br i1 %49, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %45, %.lr.ph11.split
  %50 = phi i32 [ %9, %.lr.ph11.split ], [ %47, %45 ]
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr @i, align 4, !tbaa !5
  %52 = icmp sgt i32 %50, 0
  br i1 %52, label %.lr.ph11.split, label %._crit_edge12, !llvm.loop !12

._crit_edge12:                                    ; preds = %._crit_edge, %.lr.ph11.split.us, %2
  %53 = load i32, ptr @L, align 16, !tbaa !5
  ret i32 %53
}

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

; 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

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 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 = { 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11, !13}
!13 = !{!"llvm.loop.unswitch.partial.disable"}


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