; LLVM IR from Tiramisu-Compiler/tiramisu :: benchmarks/framework_benchmarking/linear_algebra/ppcg-gpu_sgemm (sgemm)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @sgemm(ptr noundef %0, ptr noundef %1, ptr noundef %2, float noundef %3, float noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store float %3, ptr %9, align 4, !tbaa !9
  store float %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %82, %5
  %16 = load i32, ptr %11, align 4, !tbaa !11
  %17 = icmp slt i32 %16, 3072
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %85

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

20:                                               ; preds = %78, %19
  %21 = load i32, ptr %13, align 4, !tbaa !11
  %22 = icmp slt i32 %21, 3072
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %81

24:                                               ; preds = %20
  %25 = load float, ptr %10, align 4, !tbaa !9
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load i32, ptr %11, align 4, !tbaa !11
  %28 = mul nsw i32 %27, 3072
  %29 = load i32, ptr %13, align 4, !tbaa !11
  %30 = add nsw i32 %28, %29
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds float, ptr %26, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !9
  %34 = fmul float %25, %33
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i32, ptr %11, align 4, !tbaa !11
  %37 = mul nsw i32 %36, 3072
  %38 = load i32, ptr %13, align 4, !tbaa !11
  %39 = add nsw i32 %37, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds float, ptr %35, i64 %40
  store float %34, ptr %41, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !11
  br label %42

42:                                               ; preds = %74, %24
  %43 = load i32, ptr %14, align 4, !tbaa !11
  %44 = icmp slt i32 %43, 3072
  br i1 %44, label %46, label %45

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

46:                                               ; preds = %42
  %47 = load float, ptr %9, align 4, !tbaa !9
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i32, ptr %11, align 4, !tbaa !11
  %50 = mul nsw i32 %49, 3072
  %51 = load i32, ptr %14, align 4, !tbaa !11
  %52 = add nsw i32 %50, %51
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds float, ptr %48, i64 %53
  %55 = load float, ptr %54, align 4, !tbaa !9
  %56 = fmul float %47, %55
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load i32, ptr %14, align 4, !tbaa !11
  %59 = mul nsw i32 %58, 3072
  %60 = load i32, ptr %13, align 4, !tbaa !11
  %61 = add nsw i32 %59, %60
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds float, ptr %57, i64 %62
  %64 = load float, ptr %63, align 4, !tbaa !9
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load i32, ptr %11, align 4, !tbaa !11
  %67 = mul nsw i32 %66, 3072
  %68 = load i32, ptr %13, align 4, !tbaa !11
  %69 = add nsw i32 %67, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds float, ptr %65, i64 %70
  %72 = load float, ptr %71, align 4, !tbaa !9
  %73 = call float @llvm.fmuladd.f32(float %56, float %64, float %72)
  store float %73, ptr %71, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %46
  %75 = load i32, ptr %14, align 4, !tbaa !11
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %14, align 4, !tbaa !11
  br label %42, !llvm.loop !13

77:                                               ; preds = %45
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %13, align 4, !tbaa !11
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %13, align 4, !tbaa !11
  br label %20, !llvm.loop !15

81:                                               ; preds = %23
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %11, align 4, !tbaa !11
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %11, align 4, !tbaa !11
  br label %15, !llvm.loop !16

85:                                               ; preds = %18
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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 @sgemm(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2, float noundef %3, float noundef %4) local_unnamed_addr #0 {
  br label %.preheader

.preheader:                                       ; preds = %5, %8
  %indvars.iv32 = phi i64 [ 0, %5 ], [ %indvars.iv.next33, %8 ]
  %6 = mul nuw nsw i64 %indvars.iv32, 3072
  %invariant.gep38 = getelementptr inbounds float, ptr %2, i64 %6
  %invariant.gep = getelementptr inbounds float, ptr %0, i64 %6
  br label %9

7:                                                ; preds = %8
  ret void

8:                                                ; preds = %12
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond35.not = icmp eq i64 %indvars.iv.next33, 3072
  br i1 %exitcond35.not, label %7, label %.preheader, !llvm.loop !5

9:                                                ; preds = %.preheader, %12
  %indvars.iv28 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next29, %12 ]
  %gep39 = getelementptr inbounds float, ptr %invariant.gep38, i64 %indvars.iv28
  %10 = load float, ptr %gep39, align 4, !tbaa !7
  %11 = fmul float %10, %4
  store float %11, ptr %gep39, align 4, !tbaa !7
  %invariant.gep36 = getelementptr float, ptr %1, i64 %indvars.iv28
  br label %13

12:                                               ; preds = %13
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %exitcond31.not = icmp eq i64 %indvars.iv.next29, 3072
  br i1 %exitcond31.not, label %8, label %9, !llvm.loop !11

13:                                               ; preds = %13, %9
  %indvars.iv = phi i64 [ 0, %9 ], [ %indvars.iv.next.1, %13 ]
  %14 = phi float [ %11, %9 ], [ %22, %13 ]
  %gep = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv
  %15 = load float, ptr %gep, align 4, !tbaa !7
  %16 = fmul float %15, %3
  %.idx = mul nuw nsw i64 %indvars.iv, 12288
  %gep37 = getelementptr i8, ptr %invariant.gep36, i64 %.idx
  %17 = load float, ptr %gep37, align 4, !tbaa !7
  %18 = tail call float @llvm.fmuladd.f32(float %16, float %17, float %14)
  store float %18, ptr %gep39, align 4, !tbaa !7
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %gep.1 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next
  %19 = load float, ptr %gep.1, align 4, !tbaa !7
  %20 = fmul float %19, %3
  %.idx.1 = mul nuw nsw i64 %indvars.iv.next, 12288
  %gep37.1 = getelementptr i8, ptr %invariant.gep36, i64 %.idx.1
  %21 = load float, ptr %gep37.1, align 4, !tbaa !7
  %22 = tail call float @llvm.fmuladd.f32(float %20, float %21, float %18)
  store float %22, ptr %gep39, align 4, !tbaa !7
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 3072
  br i1 %exitcond.not.1, label %12, label %13, !llvm.loop !12
}

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

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" }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = distinct !{!11, !6}
!12 = distinct !{!12, !6}


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