; LLVM IR from div-bargali/Data-Structures-and-Algorithms :: C++/Algorithms/Dynamic-Programming/Matrix-Chain-Multiplication/matrix_chain_multi_d8b40c9d (BUPii)

; 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 [100 x [100 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z15matrix_chain_BUPii(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 16 @dp, i8 0, i64 40000, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %89, %2
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 1, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %18 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %18, ptr %8, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %76, %17
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = icmp sle i32 %20, %21
  br i1 %22, label %23, label %88

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = icmp eq i32 %24, %25
  %27 = zext i1 %26 to i64
  %28 = select i1 %26, i32 0, i32 2147483647
  store i32 %28, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %29 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %29, ptr %10, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %73, %23
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 7, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %76

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100 x [100 x i32]], ptr @dp, i64 0, i64 %37
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100 x i32], ptr %38, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100 x [100 x i32]], ptr @dp, i64 0, i64 %45
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100 x i32], ptr %46, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = add nsw i32 %42, %50
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = sub nsw i32 %53, 1
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %52, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = mul nsw i32 %57, %62
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr %64, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !9
  %69 = mul nsw i32 %63, %68
  %70 = add nsw i32 %51, %69
  store i32 %70, ptr %11, align 4, !tbaa !9
  %71 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %72 = load i32, ptr %71, align 4, !tbaa !9
  store i32 %72, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %73

73:                                               ; preds = %35
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %10, align 4, !tbaa !9
  br label %30, !llvm.loop !11

76:                                               ; preds = %34
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = load i32, ptr %7, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [100 x [100 x i32]], ptr @dp, i64 0, i64 %79
  %81 = load i32, ptr %8, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [100 x i32], ptr %80, i64 0, i64 %82
  store i32 %77, ptr %83, align 4, !tbaa !9
  %84 = load i32, ptr %7, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %7, align 4, !tbaa !9
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %19, !llvm.loop !13

88:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %5, align 4, !tbaa !9
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %5, align 4, !tbaa !9
  br label %12, !llvm.loop !14

92:                                               ; preds = %16
  %93 = load i32, ptr %4, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [100 x i32], ptr getelementptr inbounds ([100 x [100 x i32]], ptr @dp, i64 0, i64 1), i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !9
  ret i32 %96
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = distinct !{!14, !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"

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z15matrix_chain_BUPii(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40000) @dp, i8 0, i64 40000, i1 false)
  %.not34 = icmp slt i32 %1, 1
  br i1 %.not34, label %._crit_edge36, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %2
  %invariant.gep = getelementptr i8, ptr %0, i64 -4
  %5 = add nuw i32 %1, 1
  %wide.trip.count = zext i32 %5 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %31
  %indvars.iv40 = phi i64 [ 1, %.preheader.lr.ph ], [ %indvars.iv.next41, %31 ]
  br label %9

._crit_edge36:                                    ; preds = %31, %2
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds [100 x i32], ptr getelementptr inbounds (i8, ptr @dp, i64 400), i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  ret i32 %8

9:                                                ; preds = %.preheader, %._crit_edge
  %indvars.iv42 = phi i64 [ %indvars.iv40, %.preheader ], [ %indvars.iv.next43, %._crit_edge ]
  %indvars.iv = phi i64 [ 1, %.preheader ], [ %indvars.iv.next, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %10 = icmp eq i64 %indvars.iv, %indvars.iv42
  %11 = select i1 %10, i32 0, i32 2147483647
  store i32 %11, ptr %3, align 4, !tbaa !5
  %12 = icmp ult i64 %indvars.iv, %indvars.iv42
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9
  %gep = getelementptr i32, ptr %invariant.gep, i64 %indvars.iv
  %13 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv42
  br label %16

._crit_edge:                                      ; preds = %16, %9
  %14 = phi i32 [ %11, %9 ], [ %30, %16 ]
  %15 = getelementptr inbounds [100 x [100 x i32]], ptr @dp, i64 0, i64 %indvars.iv, i64 %indvars.iv42
  store i32 %14, ptr %15, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  %exitcond48.not = icmp eq i64 %indvars.iv.next43, %wide.trip.count
  br i1 %exitcond48.not, label %31, label %9, !llvm.loop !9

16:                                               ; preds = %.lr.ph, %16
  %indvars.iv37 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next38, %16 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %17 = getelementptr inbounds [100 x [100 x i32]], ptr @dp, i64 0, i64 %indvars.iv, i64 %indvars.iv37
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %19 = getelementptr inbounds [100 x [100 x i32]], ptr @dp, i64 0, i64 %indvars.iv.next38, i64 %indvars.iv42
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = add nsw i32 %20, %18
  %22 = load i32, ptr %gep, align 4, !tbaa !5
  %23 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv37
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = mul nsw i32 %24, %22
  %26 = load i32, ptr %13, align 4, !tbaa !5
  %27 = mul nsw i32 %25, %26
  %28 = add nsw i32 %21, %27
  store i32 %28, ptr %4, align 4, !tbaa !5
  %29 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %30 = load i32, ptr %29, align 4, !tbaa !5
  store i32 %30, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  %exitcond.not = icmp eq i64 %indvars.iv.next38, %indvars.iv42
  br i1 %exitcond.not, label %._crit_edge, label %16, !llvm.loop !11

31:                                               ; preds = %._crit_edge
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond50.not = icmp eq i64 %indvars.iv.next41, %wide.trip.count
  br i1 %exitcond50.not, label %._crit_edge36, label %.preheader, !llvm.loop !12
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

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


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