; LLVM IR from bondhugula/pluto :: examples/matmul-init (matmul-init)

; 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 [1024 x [1037 x double]], align 16
@B = external dso_local global [1024 x [1047 x double]], align 16
@C = external dso_local global [1024 x [1067 x double]], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @init_array() #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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @init_array()
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %62, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 1024
  br i1 %10, label %11, label %65

11:                                               ; preds = %8
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %58, %11
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 1024
  br i1 %14, label %15, label %61

15:                                               ; preds = %12
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1024 x [1067 x double]], ptr @C, i64 0, i64 %17
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1067 x double], ptr %18, i64 0, i64 %20
  store double 0.000000e+00, ptr %21, align 8, !tbaa !9
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %54, %15
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 1024
  br i1 %24, label %25, label %57

25:                                               ; preds = %22
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1024 x [1067 x double]], ptr @C, i64 0, i64 %27
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1067 x double], ptr %28, i64 0, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1024 x [1037 x double]], ptr @A, i64 0, i64 %34
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1037 x double], ptr %35, i64 0, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1024 x [1047 x double]], ptr @B, i64 0, i64 %41
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1047 x double], ptr %42, i64 0, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !9
  %47 = call double @llvm.fmuladd.f64(double %39, double %46, double %32)
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1024 x [1067 x double]], ptr @C, i64 0, i64 %49
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [1067 x double], ptr %50, i64 0, i64 %52
  store double %47, ptr %53, align 8, !tbaa !9
  br label %54

54:                                               ; preds = %25
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %4, align 4, !tbaa !5
  br label %22, !llvm.loop !11

57:                                               ; preds = %22
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %3, align 4, !tbaa !5
  br label %12, !llvm.loop !13

61:                                               ; preds = %12
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !14

65:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !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"

@A = external dso_local local_unnamed_addr global [1024 x [1037 x double]], align 16
@B = external dso_local local_unnamed_addr global [1024 x [1047 x double]], align 16
@C = external dso_local local_unnamed_addr global [1024 x [1067 x double]], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @init_array() local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  tail call void @init_array()
  br label %.preheader

.preheader:                                       ; preds = %0, %16
  %indvars.iv26 = phi i64 [ 0, %0 ], [ %indvars.iv.next27, %16 ]
  br label %1

1:                                                ; preds = %.preheader, %15
  %indvars.iv22 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next23, %15 ]
  %2 = getelementptr inbounds [1024 x [1067 x double]], ptr @C, i64 0, i64 %indvars.iv26, i64 %indvars.iv22
  br label %3

3:                                                ; preds = %3, %1
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next.1, %3 ]
  %4 = phi double [ 0.000000e+00, %1 ], [ %14, %3 ]
  %5 = getelementptr inbounds [1024 x [1037 x double]], ptr @A, i64 0, i64 %indvars.iv26, i64 %indvars.iv
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds [1024 x [1047 x double]], ptr @B, i64 0, i64 %indvars.iv, i64 %indvars.iv22
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = tail call double @llvm.fmuladd.f64(double %6, double %8, double %4)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %10 = getelementptr inbounds [1024 x [1037 x double]], ptr @A, i64 0, i64 %indvars.iv26, i64 %indvars.iv.next
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds [1024 x [1047 x double]], ptr @B, i64 0, i64 %indvars.iv.next, i64 %indvars.iv22
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = tail call double @llvm.fmuladd.f64(double %11, double %13, double %9)
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 1024
  br i1 %exitcond.not.1, label %15, label %3, !llvm.loop !9

15:                                               ; preds = %3
  store double %14, ptr %2, align 8, !tbaa !5
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %exitcond25.not = icmp eq i64 %indvars.iv.next23, 1024
  br i1 %exitcond25.not, label %16, label %1, !llvm.loop !11

16:                                               ; preds = %15
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next27, 1024
  br i1 %exitcond29.not, label %17, label %.preheader, !llvm.loop !12

17:                                               ; preds = %16
  ret i32 0
}

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 speculatable willreturn memory(none) }

!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 = !{!"double", !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}
!12 = distinct !{!12, !10}


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