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

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

@A = external dso_local global [1000 x i8], align 16
@B = external dso_local global [1000 x i8], align 16
@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
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z10lcs_lengthPcS_(ptr noundef, ptr noundef) #0

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.memset.p0.i64(ptr align 16 @L, i8 -1, i64 4000000, i1 false)
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @A, ptr noundef @B)
  %3 = call noundef i32 @_Z10lcs_lengthPcS_(ptr noundef @A, ptr noundef @B)
  %4 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %3)
  %5 = call i64 @strlen(ptr noundef @A) #5
  %6 = trunc i64 %5 to i32
  store i32 %6, ptr @m, align 4, !tbaa !5
  %7 = call i64 @strlen(ptr noundef @B) #5
  %8 = trunc i64 %7 to i32
  store i32 %8, ptr @n, align 4, !tbaa !5
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef 32)
  store i32 0, ptr @i, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %21, %0
  %11 = load i32, ptr @i, align 4, !tbaa !5
  %12 = load i32, ptr @m, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %14, label %24

14:                                               ; preds = %10
  %15 = load i32, ptr @i, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1000 x i8], ptr @A, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = sext i8 %18 to i32
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %19)
  br label %21

21:                                               ; preds = %14
  %22 = load i32, ptr @i, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @i, align 4, !tbaa !5
  br label %10, !llvm.loop !10

24:                                               ; preds = %10
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr @i, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %55, %24
  %27 = load i32, ptr @i, align 4, !tbaa !5
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %30, label %58

30:                                               ; preds = %26
  %31 = load i32, ptr @i, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1000 x i8], ptr @B, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !9
  %35 = sext i8 %34 to i32
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %35)
  store i32 0, ptr @j, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %50, %30
  %38 = load i32, ptr @j, align 4, !tbaa !5
  %39 = load i32, ptr @m, align 4, !tbaa !5
  %40 = icmp sle i32 %38, %39
  br i1 %40, label %41, label %53

41:                                               ; preds = %37
  %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 %43
  %45 = load i32, ptr @i, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1000 x i32], ptr %44, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %48)
  br label %50

50:                                               ; preds = %41
  %51 = load i32, ptr @j, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr @j, align 4, !tbaa !5
  br label %37, !llvm.loop !12

53:                                               ; preds = %37
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %55

55:                                               ; preds = %53
  %56 = load i32, ptr @i, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr @i, align 4, !tbaa !5
  br label %26, !llvm.loop !13

58:                                               ; preds = %26
  %59 = load i32, ptr %1, align 4
  ret i32 %59
}

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #4

declare i32 @printf(ptr noundef, ...) #4

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 = { mustprogress norecurse 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 = { "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 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 = distinct !{!13, !11}


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

@A = external dso_local global [1000 x i8], align 16
@B = external dso_local global [1000 x i8], align 16
@L = external dso_local local_unnamed_addr 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
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z10lcs_lengthPcS_(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4000000) @L, i8 -1, i64 4000000, i1 false)
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @A, ptr noundef nonnull @B)
  %2 = tail call noundef i32 @_Z10lcs_lengthPcS_(ptr noundef nonnull @A, ptr noundef nonnull @B)
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %2)
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @A) #5
  %5 = trunc i64 %4 to i32
  store i32 %5, ptr @m, align 4, !tbaa !5
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @B) #5
  %7 = trunc i64 %6 to i32
  store i32 %7, ptr @n, align 4, !tbaa !5
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef 32)
  store i32 0, ptr @i, align 4, !tbaa !5
  %9 = load i32, ptr @m, align 4, !tbaa !5
  %.not7 = icmp slt i32 %9, 0
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %storemerge8 = phi i32 [ %16, %.lr.ph ], [ 0, %0 ]
  %10 = sext i32 %storemerge8 to i64
  %11 = getelementptr inbounds [1000 x i8], ptr @A, i64 0, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = sext i8 %12 to i32
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %13)
  %15 = load i32, ptr @i, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @i, align 4, !tbaa !5
  %17 = load i32, ptr @m, align 4, !tbaa !5
  %.not.not = icmp slt i32 %15, %17
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %0
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  store i32 0, ptr @i, align 4, !tbaa !5
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %.not414 = icmp slt i32 %19, 0
  br i1 %.not414, label %._crit_edge18, label %.lr.ph17

.lr.ph17:                                         ; preds = %._crit_edge, %._crit_edge13
  %storemerge315 = phi i32 [ %37, %._crit_edge13 ], [ 0, %._crit_edge ]
  %20 = sext i32 %storemerge315 to i64
  %21 = getelementptr inbounds [1000 x i8], ptr @B, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %23)
  store i32 0, ptr @j, align 4, !tbaa !5
  %25 = load i32, ptr @m, align 4, !tbaa !5
  %.not69 = icmp slt i32 %25, 0
  br i1 %.not69, label %._crit_edge13, label %.lr.ph12

.lr.ph12:                                         ; preds = %.lr.ph17, %.lr.ph12
  %storemerge510 = phi i32 [ %33, %.lr.ph12 ], [ 0, %.lr.ph17 ]
  %26 = sext i32 %storemerge510 to i64
  %27 = load i32, ptr @i, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000 x [1000 x i32]], ptr @L, i64 0, i64 %26, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %30)
  %32 = load i32, ptr @j, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @j, align 4, !tbaa !5
  %34 = load i32, ptr @m, align 4, !tbaa !5
  %.not6.not = icmp slt i32 %32, %34
  br i1 %.not6.not, label %.lr.ph12, label %._crit_edge13, !llvm.loop !12

._crit_edge13:                                    ; preds = %.lr.ph12, %.lr.ph17
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %36 = load i32, ptr @i, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr @i, align 4, !tbaa !5
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %.not4.not = icmp slt i32 %36, %38
  br i1 %.not4.not, label %.lr.ph17, label %._crit_edge18, !llvm.loop !13

._crit_edge18:                                    ; preds = %._crit_edge13, %._crit_edge
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

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 = { 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 = { mustprogress norecurse 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nofree nounwind "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 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 = distinct !{!13, !11}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass