; LLVM IR from aferikoglou/GenHLSOptimizer :: dataset/machsuite-gemm-ncubed (gemm)

; 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: nounwind uwtable
define dso_local void @gemm(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 i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  br label %14

14:                                               ; preds = %3
  br label %15

15:                                               ; preds = %14
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %16

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

19:                                               ; preds = %16
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %65, %21
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 64
  br i1 %24, label %25, label %68

25:                                               ; preds = %22
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = mul nsw i32 %26, 64
  store i32 %27, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  store double 0.000000e+00, ptr %13, align 8, !tbaa !11
  br label %28

28:                                               ; preds = %25
  br label %29

29:                                               ; preds = %28
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %54, %29
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 64
  br i1 %32, label %33, label %57

33:                                               ; preds = %30
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = mul nsw i32 %34, 64
  store i32 %35, ptr %10, align 4, !tbaa !9
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = add nsw i32 %37, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %36, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !11
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = add nsw i32 %44, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %43, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fmul double %42, %49
  store double %50, ptr %12, align 8, !tbaa !11
  %51 = load double, ptr %12, align 8, !tbaa !11
  %52 = load double, ptr %13, align 8, !tbaa !11
  %53 = fadd double %52, %51
  store double %53, ptr %13, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %33
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %9, align 4, !tbaa !9
  br label %30, !llvm.loop !13

57:                                               ; preds = %30
  %58 = load double, ptr %13, align 8, !tbaa !11
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i32, ptr %11, align 4, !tbaa !9
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = add nsw i32 %60, %61
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds double, ptr %59, i64 %63
  store double %58, ptr %64, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  br label %65

65:                                               ; preds = %57
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %8, align 4, !tbaa !9
  br label %22, !llvm.loop !15

68:                                               ; preds = %22
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %7, align 4, !tbaa !9
  br label %16, !llvm.loop !16

72:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = { 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/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}


; 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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @gemm(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  br label %.preheader

.preheader:                                       ; preds = %3, %22
  %indvars.iv31 = phi i64 [ 0, %3 ], [ %indvars.iv.next32, %22 ]
  %4 = shl nuw nsw i64 %indvars.iv31, 6
  br label %5

5:                                                ; preds = %.preheader, %19
  %indvars.iv27 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next28, %19 ]
  %invariant.gep = getelementptr inbounds double, ptr %1, i64 %indvars.iv27
  br label %6

6:                                                ; preds = %6, %5
  %indvars.iv = phi i64 [ 0, %5 ], [ %indvars.iv.next.1, %6 ]
  %.023 = phi double [ 0.000000e+00, %5 ], [ %18, %6 ]
  %7 = or disjoint i64 %indvars.iv, %4
  %8 = getelementptr inbounds double, ptr %0, i64 %7
  %9 = load double, ptr %8, align 8, !tbaa !5
  %.idx = shl nsw i64 %indvars.iv, 9
  %gep = getelementptr inbounds i8, ptr %invariant.gep, i64 %.idx
  %10 = load double, ptr %gep, align 8, !tbaa !5
  %11 = fmul double %9, %10
  %12 = fadd double %.023, %11
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %13 = or disjoint i64 %indvars.iv.next, %4
  %14 = getelementptr inbounds double, ptr %0, i64 %13
  %15 = load double, ptr %14, align 8, !tbaa !5
  %.idx.1 = shl nsw i64 %indvars.iv.next, 9
  %gep.1 = getelementptr inbounds i8, ptr %invariant.gep, i64 %.idx.1
  %16 = load double, ptr %gep.1, align 8, !tbaa !5
  %17 = fmul double %15, %16
  %18 = fadd double %12, %17
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 64
  br i1 %exitcond.not.1, label %19, label %6, !llvm.loop !9

19:                                               ; preds = %6
  %20 = or disjoint i64 %indvars.iv27, %4
  %21 = getelementptr inbounds double, ptr %2, i64 %20
  store double %18, ptr %21, align 8, !tbaa !5
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %exitcond30.not = icmp eq i64 %indvars.iv.next28, 64
  br i1 %exitcond30.not, label %22, label %5, !llvm.loop !11

22:                                               ; preds = %19
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next32, 64
  br i1 %exitcond34.not, label %23, label %.preheader, !llvm.loop !12

23:                                               ; preds = %22
  ret void
}

attributes #0 = { 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" }

!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: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass