; LLVM IR from ravireddy07/cpp-book :: src/Subsequences/KorderedLCS.ll (Z11KOrderedLCSiiPiS_iii)

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

@dp = external dso_local global [2005 x [2005 x [8 x i32]]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z11KOrderedLCSiiPiS_iii(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6) #0 {
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %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
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  store i32 %0, ptr %9, align 4, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !9
  store i32 %4, ptr %13, align 4, !tbaa !5
  store i32 %5, ptr %14, align 4, !tbaa !5
  store i32 %6, ptr %15, align 4, !tbaa !5
  %21 = load i32, ptr %14, align 4, !tbaa !5
  %22 = load i32, ptr %9, align 4, !tbaa !5
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %28, label %24

24:                                               ; preds = %7
  %25 = load i32, ptr %15, align 4, !tbaa !5
  %26 = load i32, ptr %10, align 4, !tbaa !5
  %27 = icmp eq i32 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %24, %7
  store i32 0, ptr %8, align 4
  br label %137

29:                                               ; preds = %24
  %30 = load i32, ptr %14, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2005 x [2005 x [8 x i32]]], ptr @dp, i64 0, i64 %31
  %33 = load i32, ptr %15, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [2005 x [8 x i32]], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %13, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [8 x i32], ptr %35, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = icmp ne i32 %39, -1
  br i1 %40, label %41, label %52

41:                                               ; preds = %29
  %42 = load i32, ptr %14, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [2005 x [2005 x [8 x i32]]], ptr @dp, i64 0, i64 %43
  %45 = load i32, ptr %15, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [2005 x [8 x i32]], ptr %44, i64 0, i64 %46
  %48 = load i32, ptr %13, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [8 x i32], ptr %47, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  store i32 %51, ptr %8, align 4
  br label %137

52:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %53 = load ptr, ptr %11, align 8, !tbaa !9
  %54 = load i32, ptr %14, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %53, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = load ptr, ptr %12, align 8, !tbaa !9
  %59 = load i32, ptr %15, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = icmp eq i32 %57, %62
  br i1 %63, label %64, label %87

64:                                               ; preds = %52
  %65 = load i32, ptr %9, align 4, !tbaa !5
  %66 = load i32, ptr %10, align 4, !tbaa !5
  %67 = load ptr, ptr %11, align 8, !tbaa !9
  %68 = load ptr, ptr %12, align 8, !tbaa !9
  %69 = load i32, ptr %13, align 4, !tbaa !5
  %70 = load i32, ptr %14, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  %72 = load i32, ptr %15, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  %74 = call noundef i32 @_Z11KOrderedLCSiiPiS_iii(i32 noundef %65, i32 noundef %66, ptr noundef %67, ptr noundef %68, i32 noundef %69, i32 noundef %71, i32 noundef %73)
  %75 = add nsw i32 1, %74
  store i32 %75, ptr %16, align 4, !tbaa !5
  %76 = load i32, ptr %16, align 4, !tbaa !5
  %77 = load i32, ptr %14, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [2005 x [2005 x [8 x i32]]], ptr @dp, i64 0, i64 %78
  %80 = load i32, ptr %15, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [2005 x [8 x i32]], ptr %79, i64 0, i64 %81
  %83 = load i32, ptr %13, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [8 x i32], ptr %82, i64 0, i64 %84
  store i32 %76, ptr %85, align 4, !tbaa !5
  %86 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %86, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %136

87:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %88 = load i32, ptr %9, align 4, !tbaa !5
  %89 = load i32, ptr %10, align 4, !tbaa !5
  %90 = load ptr, ptr %11, align 8, !tbaa !9
  %91 = load ptr, ptr %12, align 8, !tbaa !9
  %92 = load i32, ptr %13, align 4, !tbaa !5
  %93 = load i32, ptr %14, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  %95 = load i32, ptr %15, align 4, !tbaa !5
  %96 = call noundef i32 @_Z11KOrderedLCSiiPiS_iii(i32 noundef %88, i32 noundef %89, ptr noundef %90, ptr noundef %91, i32 noundef %92, i32 noundef %94, i32 noundef %95)
  store i32 %96, ptr %18, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %97 = load i32, ptr %9, align 4, !tbaa !5
  %98 = load i32, ptr %10, align 4, !tbaa !5
  %99 = load ptr, ptr %11, align 8, !tbaa !9
  %100 = load ptr, ptr %12, align 8, !tbaa !9
  %101 = load i32, ptr %13, align 4, !tbaa !5
  %102 = load i32, ptr %14, align 4, !tbaa !5
  %103 = load i32, ptr %15, align 4, !tbaa !5
  %104 = add nsw i32 %103, 1
  %105 = call noundef i32 @_Z11KOrderedLCSiiPiS_iii(i32 noundef %97, i32 noundef %98, ptr noundef %99, ptr noundef %100, i32 noundef %101, i32 noundef %102, i32 noundef %104)
  store i32 %105, ptr %19, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  store i32 -1, ptr %20, align 4, !tbaa !5
  %106 = load i32, ptr %13, align 4, !tbaa !5
  %107 = icmp sgt i32 %106, 0
  br i1 %107, label %108, label %121

108:                                              ; preds = %87
  %109 = load i32, ptr %9, align 4, !tbaa !5
  %110 = load i32, ptr %10, align 4, !tbaa !5
  %111 = load ptr, ptr %11, align 8, !tbaa !9
  %112 = load ptr, ptr %12, align 8, !tbaa !9
  %113 = load i32, ptr %13, align 4, !tbaa !5
  %114 = sub nsw i32 %113, 1
  %115 = load i32, ptr %14, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  %117 = load i32, ptr %15, align 4, !tbaa !5
  %118 = add nsw i32 %117, 1
  %119 = call noundef i32 @_Z11KOrderedLCSiiPiS_iii(i32 noundef %109, i32 noundef %110, ptr noundef %111, ptr noundef %112, i32 noundef %114, i32 noundef %116, i32 noundef %118)
  %120 = add nsw i32 1, %119
  store i32 %120, ptr %20, align 4, !tbaa !5
  br label %121

121:                                              ; preds = %108, %87
  %122 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %19, ptr noundef nonnull align 4 dereferenceable(4) %20)
  %123 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %18, ptr noundef nonnull align 4 dereferenceable(4) %122)
  %124 = load i32, ptr %123, align 4, !tbaa !5
  store i32 %124, ptr %16, align 4, !tbaa !5
  %125 = load i32, ptr %16, align 4, !tbaa !5
  %126 = load i32, ptr %14, align 4, !tbaa !5
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [2005 x [2005 x [8 x i32]]], ptr @dp, i64 0, i64 %127
  %129 = load i32, ptr %15, align 4, !tbaa !5
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds [2005 x [8 x i32]], ptr %128, i64 0, i64 %130
  %132 = load i32, ptr %13, align 4, !tbaa !5
  %133 = sext i32 %132 to i64
  %134 = getelementptr inbounds [8 x i32], ptr %131, i64 0, i64 %133
  store i32 %125, ptr %134, align 4, !tbaa !5
  %135 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %135, ptr %8, align 4
  store i32 1, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  br label %136

136:                                              ; preds = %121, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %137

137:                                              ; preds = %136, %41, %28
  %138 = load i32, ptr %8, align 4
  ret i32 %138
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


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

@dp = external dso_local local_unnamed_addr global [2005 x [2005 x [8 x i32]]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z11KOrderedLCSiiPiS_iii(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6) local_unnamed_addr #0 {
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = icmp eq i32 %5, %0
  %12 = icmp eq i32 %6, %1
  %or.cond = or i1 %11, %12
  br i1 %or.cond, label %common.ret59, label %13

13:                                               ; preds = %7
  %14 = sext i32 %5 to i64
  %15 = sext i32 %6 to i64
  %16 = sext i32 %4 to i64
  %17 = getelementptr inbounds [2005 x [2005 x [8 x i32]]], ptr @dp, i64 0, i64 %14, i64 %15, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not = icmp eq i32 %18, -1
  br i1 %.not, label %19, label %common.ret59

19:                                               ; preds = %13
  %20 = getelementptr inbounds i32, ptr %2, i64 %14
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = getelementptr inbounds i32, ptr %3, i64 %15
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp eq i32 %21, %23
  br i1 %24, label %25, label %30

common.ret59:                                     ; preds = %40, %13, %7, %25
  %common.ret59.op = phi i32 [ %29, %25 ], [ 0, %7 ], [ %18, %13 ], [ %43, %40 ]
  ret i32 %common.ret59.op

25:                                               ; preds = %19
  %26 = add nsw i32 %5, 1
  %27 = add nsw i32 %6, 1
  %28 = tail call noundef i32 @_Z11KOrderedLCSiiPiS_iii(i32 noundef %0, i32 noundef %1, ptr noundef nonnull %2, ptr noundef nonnull %3, i32 noundef %4, i32 noundef %26, i32 noundef %27)
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %17, align 4, !tbaa !5
  br label %common.ret59

30:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #3
  %31 = add nsw i32 %5, 1
  %32 = tail call noundef i32 @_Z11KOrderedLCSiiPiS_iii(i32 noundef %0, i32 noundef %1, ptr noundef nonnull %2, ptr noundef nonnull %3, i32 noundef %4, i32 noundef %31, i32 noundef %6)
  store i32 %32, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #3
  %33 = add nsw i32 %6, 1
  %34 = tail call noundef i32 @_Z11KOrderedLCSiiPiS_iii(i32 noundef %0, i32 noundef %1, ptr noundef nonnull %2, ptr noundef nonnull %3, i32 noundef %4, i32 noundef %5, i32 noundef %33)
  store i32 %34, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %10) #3
  store i32 -1, ptr %10, align 4, !tbaa !5
  %35 = icmp sgt i32 %4, 0
  br i1 %35, label %36, label %40

36:                                               ; preds = %30
  %37 = add nsw i32 %4, -1
  %38 = tail call noundef i32 @_Z11KOrderedLCSiiPiS_iii(i32 noundef %0, i32 noundef %1, ptr noundef nonnull %2, ptr noundef nonnull %3, i32 noundef %37, i32 noundef %31, i32 noundef %33)
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %10, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %36, %30
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %42 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %41)
  %43 = load i32, ptr %42, align 4, !tbaa !5
  store i32 %43, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  br label %common.ret59
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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

; Function Attrs: mustprogress 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 = { 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 = { 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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass