; LLVM IR from aferikoglou/GenHLSOptimizer :: dataset/spcl_example_05/Example5_Reordered.ll (Z20MatrixMultiplicationPKdS0_Pd)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z20MatrixMultiplicationPKdS0_Pd(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [1024 x double], align 16
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %95, %15
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 1024
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  store i32 3, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %98

20:                                               ; preds = %16
  br label %21

21:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8192, ptr %9) #3
  br label %22

22:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %70, %22
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 1024
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i32 8, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %73

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = mul nsw i32 %29, 1024
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = add nsw i32 %30, %31
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds double, ptr %28, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !11
  store double %35, ptr %11, align 8, !tbaa !11
  br label %36

36:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %66, %36
  %38 = load i32, ptr %12, align 4, !tbaa !9
  %39 = icmp slt i32 %38, 1024
  br i1 %39, label %41, label %40

40:                                               ; preds = %37
  store i32 12, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %69

41:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %41
  br label %50

45:                                               ; preds = %41
  %46 = load i32, ptr %12, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1024 x double], ptr %9, i64 0, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %45, %44
  %51 = phi double [ 0.000000e+00, %44 ], [ %49, %45 ]
  store double %51, ptr %13, align 8, !tbaa !11
  %52 = load double, ptr %13, align 8, !tbaa !11
  %53 = load double, ptr %11, align 8, !tbaa !11
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = mul nsw i32 %55, 1024
  %57 = load i32, ptr %12, align 4, !tbaa !9
  %58 = add nsw i32 %56, %57
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds double, ptr %54, i64 %59
  %61 = load double, ptr %60, align 8, !tbaa !11
  %62 = call double @llvm.fmuladd.f64(double %53, double %61, double %52)
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1024 x double], ptr %9, i64 0, i64 %64
  store double %62, ptr %65, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %66

66:                                               ; preds = %50
  %67 = load i32, ptr %12, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %12, align 4, !tbaa !9
  br label %37, !llvm.loop !13

69:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %10, align 4, !tbaa !9
  br label %23, !llvm.loop !15

73:                                               ; preds = %26
  br label %74

74:                                               ; preds = %73
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %91, %74
  %76 = load i32, ptr %14, align 4, !tbaa !9
  %77 = icmp slt i32 %76, 1024
  br i1 %77, label %79, label %78

78:                                               ; preds = %75
  store i32 16, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %94

79:                                               ; preds = %75
  %80 = load i32, ptr %14, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [1024 x double], ptr %9, i64 0, i64 %81
  %83 = load double, ptr %82, align 8, !tbaa !11
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = load i32, ptr %7, align 4, !tbaa !9
  %86 = mul nsw i32 %85, 1024
  %87 = load i32, ptr %14, align 4, !tbaa !9
  %88 = add nsw i32 %86, %87
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds double, ptr %84, i64 %89
  store double %83, ptr %90, align 8, !tbaa !11
  br label %91

91:                                               ; preds = %79
  %92 = load i32, ptr %14, align 4, !tbaa !9
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %14, align 4, !tbaa !9
  br label %75, !llvm.loop !16

94:                                               ; preds = %78
  call void @llvm.lifetime.end.p0(i64 8192, ptr %9) #3
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr %7, align 4, !tbaa !9
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %7, align 4, !tbaa !9
  br label %16, !llvm.loop !17

98:                                               ; preds = %19
  ret void
}

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_Z20MatrixMultiplicationPKdS0_Pd(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = alloca [1024 x double], align 16
  br label %6

5:                                                ; preds = %.preheader
  ret void

6:                                                ; preds = %3, %.preheader
  %indvar = phi i64 [ 0, %3 ], [ %indvar.next, %.preheader ]
  %7 = shl nuw nsw i64 %indvar, 13
  %scevgep = getelementptr i8, ptr %2, i64 %7
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %4) #4
  %.idx = shl nsw i64 %indvar, 13
  %invariant.gep48 = getelementptr inbounds i8, ptr %0, i64 %.idx
  br label %8

.preheader:                                       ; preds = %.split27.us
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(8192) %scevgep, ptr noundef nonnull align 16 dereferenceable(8192) %4, i64 8192, i1 false), !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %4) #4
  %indvar.next = add nuw nsw i64 %indvar, 1
  %exitcond45.not = icmp eq i64 %indvar.next, 1024
  br i1 %exitcond45.not, label %5, label %6, !llvm.loop !9

8:                                                ; preds = %6, %.split27.us
  %indvars.iv37 = phi i64 [ 0, %6 ], [ %indvars.iv.next38, %.split27.us ]
  %gep49 = getelementptr inbounds double, ptr %invariant.gep48, i64 %indvars.iv37
  %9 = load double, ptr %gep49, align 8, !tbaa !5
  %10 = icmp eq i64 %indvars.iv37, 0
  br i1 %10, label %vector.ph, label %.split.preheader

vector.ph:                                        ; preds = %8
  %broadcast.splatinsert = insertelement <2 x double> poison, double %9, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.1, %vector.body ]
  %11 = getelementptr inbounds double, ptr %1, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %wide.load = load <2 x double>, ptr %11, align 8, !tbaa !5
  %wide.load51 = load <2 x double>, ptr %12, align 8, !tbaa !5
  %13 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat, <2 x double> %wide.load, <2 x double> zeroinitializer)
  %14 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat, <2 x double> %wide.load51, <2 x double> zeroinitializer)
  %15 = getelementptr inbounds [1024 x double], ptr %4, i64 0, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store <2 x double> %13, ptr %15, align 16, !tbaa !5
  store <2 x double> %14, ptr %16, align 16, !tbaa !5
  %index.next = or disjoint i64 %index, 4
  %17 = getelementptr inbounds double, ptr %1, i64 %index.next
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %wide.load.1 = load <2 x double>, ptr %17, align 8, !tbaa !5
  %wide.load51.1 = load <2 x double>, ptr %18, align 8, !tbaa !5
  %19 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat, <2 x double> %wide.load.1, <2 x double> zeroinitializer)
  %20 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat, <2 x double> %wide.load51.1, <2 x double> zeroinitializer)
  %21 = getelementptr inbounds [1024 x double], ptr %4, i64 0, i64 %index.next
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  store <2 x double> %19, ptr %21, align 16, !tbaa !5
  store <2 x double> %20, ptr %22, align 16, !tbaa !5
  %index.next.1 = add nuw nsw i64 %index, 8
  %23 = icmp eq i64 %index.next.1, 1024
  br i1 %23, label %.split27.us, label %vector.body, !llvm.loop !11

.split.preheader:                                 ; preds = %8
  %.idx46 = shl nsw i64 %indvars.iv37, 13
  %invariant.gep = getelementptr inbounds i8, ptr %1, i64 %.idx46
  %broadcast.splatinsert62 = insertelement <2 x double> poison, double %9, i64 0
  %broadcast.splat63 = shufflevector <2 x double> %broadcast.splatinsert62, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body56

vector.body56:                                    ; preds = %vector.body56, %.split.preheader
  %index57 = phi i64 [ 0, %.split.preheader ], [ %index.next64.1, %vector.body56 ]
  %24 = getelementptr inbounds [1024 x double], ptr %4, i64 0, i64 %index57
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %wide.load58 = load <2 x double>, ptr %24, align 16, !tbaa !5
  %wide.load59 = load <2 x double>, ptr %25, align 16, !tbaa !5
  %26 = getelementptr inbounds double, ptr %invariant.gep, i64 %index57
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %wide.load60 = load <2 x double>, ptr %26, align 8, !tbaa !5
  %wide.load61 = load <2 x double>, ptr %27, align 8, !tbaa !5
  %28 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat63, <2 x double> %wide.load60, <2 x double> %wide.load58)
  %29 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat63, <2 x double> %wide.load61, <2 x double> %wide.load59)
  store <2 x double> %28, ptr %24, align 16, !tbaa !5
  store <2 x double> %29, ptr %25, align 16, !tbaa !5
  %index.next64 = or disjoint i64 %index57, 4
  %30 = getelementptr inbounds [1024 x double], ptr %4, i64 0, i64 %index.next64
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  %wide.load58.1 = load <2 x double>, ptr %30, align 16, !tbaa !5
  %wide.load59.1 = load <2 x double>, ptr %31, align 16, !tbaa !5
  %32 = getelementptr inbounds double, ptr %invariant.gep, i64 %index.next64
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  %wide.load60.1 = load <2 x double>, ptr %32, align 8, !tbaa !5
  %wide.load61.1 = load <2 x double>, ptr %33, align 8, !tbaa !5
  %34 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat63, <2 x double> %wide.load60.1, <2 x double> %wide.load58.1)
  %35 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat63, <2 x double> %wide.load61.1, <2 x double> %wide.load59.1)
  store <2 x double> %34, ptr %30, align 16, !tbaa !5
  store <2 x double> %35, ptr %31, align 16, !tbaa !5
  %index.next64.1 = add nuw nsw i64 %index57, 8
  %36 = icmp eq i64 %index.next64.1, 1024
  br i1 %36, label %.split27.us, label %vector.body56, !llvm.loop !14

.split27.us:                                      ; preds = %vector.body56, %vector.body
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %exitcond40.not = icmp eq i64 %indvars.iv.next38, 1024
  br i1 %exitcond40.not, label %.preheader, label %8, !llvm.loop !15
}

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #3

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !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, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !10, !12, !13}
!15 = distinct !{!15, !10}


; Effective O3 passes: GVNPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass