; LLVM IR from gzc/CLRS :: C15-Dynamic-Programming (Matrix-chain-multiplication)

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

@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @MATRIX_CHAIN_ORDER(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @PRINT_OPTIMAL_PARRNS(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [7 x i32], align 16
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 6, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 28, ptr %3) #4
  %11 = getelementptr inbounds [7 x i32], ptr %3, i64 0, i64 0
  store i32 30, ptr %11, align 16, !tbaa !5
  %12 = getelementptr inbounds [7 x i32], ptr %3, i64 0, i64 1
  store i32 35, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds [7 x i32], ptr %3, i64 0, i64 2
  store i32 15, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds [7 x i32], ptr %3, i64 0, i64 3
  store i32 5, ptr %14, align 4, !tbaa !5
  %15 = getelementptr inbounds [7 x i32], ptr %3, i64 0, i64 4
  store i32 10, ptr %15, align 16, !tbaa !5
  %16 = getelementptr inbounds [7 x i32], ptr %3, i64 0, i64 5
  store i32 20, ptr %16, align 4, !tbaa !5
  %17 = getelementptr inbounds [7 x i32], ptr %3, i64 0, i64 6
  store i32 25, ptr %17, align 8, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = zext i32 %19 to i64
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  %23 = zext i32 %22 to i64
  %24 = call ptr @llvm.stacksave.p0()
  store ptr %24, ptr %4, align 8
  %25 = mul nuw i64 %20, %23
  %26 = alloca i32, i64 %25, align 16
  store i64 %20, ptr %5, align 8
  store i64 %23, ptr %6, align 8
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  %29 = zext i32 %28 to i64
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  %32 = zext i32 %31 to i64
  %33 = mul nuw i64 %29, %32
  %34 = alloca i32, i64 %33, align 16
  store i64 %29, ptr %7, align 8
  store i64 %32, ptr %8, align 8
  %35 = getelementptr inbounds [7 x i32], ptr %3, i64 0, i64 0
  %36 = load i32, ptr %2, align 4, !tbaa !5
  call void @MATRIX_CHAIN_ORDER(ptr noundef %35, i32 noundef %36, ptr noundef %26, ptr noundef %34)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %62, %0
  %38 = load i32, ptr %9, align 4, !tbaa !5
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = icmp sle i32 %38, %39
  br i1 %40, label %41, label %65

41:                                               ; preds = %37
  %42 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %42, ptr %10, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %57, %41
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = icmp sle i32 %44, %45
  br i1 %46, label %47, label %60

47:                                               ; preds = %43
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = mul nsw i64 %49, %23
  %51 = getelementptr inbounds i32, ptr %26, i64 %50
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %51, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %55)
  br label %57

57:                                               ; preds = %47
  %58 = load i32, ptr %10, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %10, align 4, !tbaa !5
  br label %43, !llvm.loop !9

60:                                               ; preds = %43
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %62

62:                                               ; preds = %60
  %63 = load i32, ptr %9, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %9, align 4, !tbaa !5
  br label %37, !llvm.loop !11

65:                                               ; preds = %37
  call void @PRINT_OPTIMAL_PARRNS(ptr noundef %34, i32 noundef 1, i32 noundef 6, i32 noundef 7)
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %66 = load ptr, ptr %4, align 8
  call void @llvm.stackrestore.p0(ptr %66)
  call void @llvm.lifetime.end.p0(i64 28, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %67 = load i32, ptr %1, align 4
  ret i32 %67
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 nosync nounwind willreturn }
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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @MATRIX_CHAIN_ORDER(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @PRINT_OPTIMAL_PARRNS(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.preheader:
  %0 = alloca [7 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %0) #4
  store <4 x i32> <i32 30, i32 35, i32 15, i32 5>, ptr %0, align 16, !tbaa !5
  %1 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 10, ptr %1, align 16, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 20, ptr %2, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 25, ptr %3, align 8, !tbaa !5
  %4 = tail call ptr @llvm.stacksave.p0()
  %5 = alloca [49 x i32], align 16
  %6 = alloca [49 x i32], align 16
  call void @MATRIX_CHAIN_ORDER(ptr noundef nonnull %0, i32 noundef 6, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %7 = getelementptr inbounds i8, ptr %5, i64 32
  %8 = load i32, ptr %7, align 16, !tbaa !5
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %8)
  %10 = getelementptr inbounds i8, ptr %5, i64 36
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %11)
  %13 = getelementptr inbounds i8, ptr %5, i64 40
  %14 = load i32, ptr %13, align 8, !tbaa !5
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %14)
  %16 = getelementptr inbounds i8, ptr %5, i64 44
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %17)
  %19 = getelementptr inbounds i8, ptr %5, i64 48
  %20 = load i32, ptr %19, align 16, !tbaa !5
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %20)
  %22 = getelementptr inbounds i8, ptr %5, i64 52
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %23)
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %26 = getelementptr inbounds i8, ptr %5, i64 64
  %27 = load i32, ptr %26, align 16, !tbaa !5
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %27)
  %29 = getelementptr inbounds i8, ptr %5, i64 68
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %30)
  %32 = getelementptr inbounds i8, ptr %5, i64 72
  %33 = load i32, ptr %32, align 8, !tbaa !5
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %33)
  %35 = getelementptr inbounds i8, ptr %5, i64 76
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %36)
  %38 = getelementptr inbounds i8, ptr %5, i64 80
  %39 = load i32, ptr %38, align 16, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %39)
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %42 = getelementptr inbounds i8, ptr %5, i64 96
  %43 = load i32, ptr %42, align 16, !tbaa !5
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %43)
  %45 = getelementptr inbounds i8, ptr %5, i64 100
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %46)
  %48 = getelementptr inbounds i8, ptr %5, i64 104
  %49 = load i32, ptr %48, align 8, !tbaa !5
  %50 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %49)
  %51 = getelementptr inbounds i8, ptr %5, i64 108
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %52)
  %54 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %55 = getelementptr inbounds i8, ptr %5, i64 128
  %56 = load i32, ptr %55, align 16, !tbaa !5
  %57 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %56)
  %58 = getelementptr inbounds i8, ptr %5, i64 132
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %59)
  %61 = getelementptr inbounds i8, ptr %5, i64 136
  %62 = load i32, ptr %61, align 8, !tbaa !5
  %63 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %62)
  %64 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %65 = getelementptr inbounds i8, ptr %5, i64 160
  %66 = load i32, ptr %65, align 16, !tbaa !5
  %67 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %66)
  %68 = getelementptr inbounds i8, ptr %5, i64 164
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %69)
  %71 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %72 = getelementptr inbounds i8, ptr %5, i64 192
  %73 = load i32, ptr %72, align 16, !tbaa !5
  %74 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %73)
  %75 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  call void @PRINT_OPTIMAL_PARRNS(ptr noundef nonnull %6, i32 noundef 1, i32 noundef 6, i32 noundef 7)
  call void @llvm.stackrestore.p0(ptr %4)
  call void @llvm.lifetime.end.p0(i64 28, ptr nonnull %0) #4
  ret i32 0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

attributes #0 = { 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 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind willreturn }
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/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass