; LLVM IR from ncduy0303/Competitive-Programming :: Dynamic Programming/Digit DP.ll (Z4memoiii)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@num = external dso_local global %"class.std::vector", align 8
@dp = external dso_local global [10 x [90 x [2 x i64]]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z4memoiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @num) #3
  %15 = icmp eq i64 %13, %14
  br i1 %15, label %16, label %19

16:                                               ; preds = %3
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  store i64 %18, ptr %4, align 8
  br label %90

19:                                               ; preds = %3
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [10 x [90 x [2 x i64]]], ptr @dp, i64 0, i64 %21
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [90 x [2 x i64]], ptr %22, i64 0, i64 %24
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [2 x i64], ptr %25, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = icmp ne i64 %29, -1
  br i1 %30, label %31, label %42

31:                                               ; preds = %19
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10 x [90 x [2 x i64]]], ptr @dp, i64 0, i64 %33
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [90 x [2 x i64]], ptr %34, i64 0, i64 %36
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2 x i64], ptr %37, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !9
  store i64 %41, ptr %4, align 8
  br label %90

42:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %42
  br label %51

46:                                               ; preds = %42
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @num, i64 noundef %48) #3
  %50 = load i32, ptr %49, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %46, %45
  %52 = phi i32 [ 9, %45 ], [ %50, %46 ]
  store i32 %52, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %76, %51
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = icmp sle i32 %54, %55
  br i1 %56, label %58, label %57

57:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %79

58:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %59 = load i32, ptr %10, align 4, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = icmp slt i32 %59, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %58
  br label %65

63:                                               ; preds = %58
  %64 = load i32, ptr %7, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %63, %62
  %66 = phi i32 [ 1, %62 ], [ %64, %63 ]
  store i32 %66, ptr %11, align 4, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = load i32, ptr %10, align 4, !tbaa !5
  %71 = add nsw i32 %69, %70
  %72 = load i32, ptr %11, align 4, !tbaa !5
  %73 = call noundef i64 @_Z4memoiii(i32 noundef %68, i32 noundef %71, i32 noundef %72)
  %74 = load i64, ptr %8, align 8, !tbaa !9
  %75 = add nsw i64 %74, %73
  store i64 %75, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %76

76:                                               ; preds = %65
  %77 = load i32, ptr %10, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %10, align 4, !tbaa !5
  br label %53, !llvm.loop !11

79:                                               ; preds = %57
  %80 = load i64, ptr %8, align 8, !tbaa !9
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [10 x [90 x [2 x i64]]], ptr @dp, i64 0, i64 %82
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [90 x [2 x i64]], ptr %83, i64 0, i64 %85
  %87 = load i32, ptr %7, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [2 x i64], ptr %86, i64 0, i64 %88
  store i64 %80, ptr %89, align 8, !tbaa !9
  store i64 %80, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %90

90:                                               ; preds = %79, %31, %16
  %91 = load i64, ptr %4, align 8
  ret i64 %91
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

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


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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@num = external dso_local global %"class.std::vector", align 8
@dp = external dso_local local_unnamed_addr global [10 x [90 x [2 x i64]]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z4memoiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @num) #1
  %6 = icmp eq i64 %5, %4
  %7 = sext i32 %1 to i64
  br i1 %6, label %25, label %8

8:                                                ; preds = %3
  %9 = sext i32 %2 to i64
  %10 = getelementptr inbounds [10 x [90 x [2 x i64]]], ptr @dp, i64 0, i64 %4, i64 %7, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %.not = icmp eq i64 %11, -1
  br i1 %.not, label %12, label %25

12:                                               ; preds = %8
  %.not31 = icmp eq i32 %2, 0
  br i1 %.not31, label %13, label %.lr.ph

13:                                               ; preds = %12
  %14 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @num, i64 noundef %4) #1
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %.not3233 = icmp slt i32 %15, 0
  br i1 %.not3233, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %12, %13
  %16 = phi i32 [ %15, %13 ], [ 9, %12 ]
  %17 = add nsw i32 %0, 1
  br label %18

._crit_edge:                                      ; preds = %18, %13
  %.027.lcssa = phi i64 [ 0, %13 ], [ %23, %18 ]
  store i64 %.027.lcssa, ptr %10, align 8, !tbaa !5
  br label %25

18:                                               ; preds = %.lr.ph, %18
  %.02635 = phi i32 [ 0, %.lr.ph ], [ %24, %18 ]
  %.02734 = phi i64 [ 0, %.lr.ph ], [ %23, %18 ]
  %19 = icmp slt i32 %.02635, %16
  %20 = select i1 %19, i32 1, i32 %2
  %21 = add nsw i32 %.02635, %1
  %22 = tail call noundef i64 @_Z4memoiii(i32 noundef %17, i32 noundef %21, i32 noundef %20)
  %23 = add nsw i64 %22, %.02734
  %24 = add nuw i32 %.02635, 1
  %exitcond.not = icmp eq i32 %.02635, %16
  br i1 %exitcond.not, label %._crit_edge, label %18, !llvm.loop !11

25:                                               ; preds = %3, %8, %._crit_edge
  %.0 = phi i64 [ %.027.lcssa, %._crit_edge ], [ %11, %8 ], [ %7, %3 ]
  ret i64 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 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 = { 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 = !{!"long long", !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"}


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