; LLVM IR from tsotchke/quantum_geometric_tensor :: src/quantum_geometric/core (amx_operations)

; 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 @amx_matrix_multiply(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca float, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %14

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

18:                                               ; preds = %14
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %72

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

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

24:                                               ; preds = %20
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %68

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store float 0.000000e+00, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %52, %25
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

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

31:                                               ; preds = %26
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = mul nsw i32 %33, %34
  %36 = load i32, ptr %13, align 4, !tbaa !9
  %37 = add nsw i32 %35, %36
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds float, ptr %32, i64 %38
  %40 = load float, ptr %39, align 4, !tbaa !11
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i32, ptr %13, align 4, !tbaa !9
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = mul nsw i32 %42, %43
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = add nsw i32 %44, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds float, ptr %41, i64 %47
  %49 = load float, ptr %48, align 4, !tbaa !11
  %50 = load float, ptr %12, align 4, !tbaa !11
  %51 = call float @llvm.fmuladd.f32(float %40, float %49, float %50)
  store float %51, ptr %12, align 4, !tbaa !11
  br label %52

52:                                               ; preds = %31
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %13, align 4, !tbaa !9
  br label %26, !llvm.loop !13

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

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

68:                                               ; preds = %24
  br label %69

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

72:                                               ; preds = %18
  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 float @llvm.fmuladd.f32(float, float, float) #2

; 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !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 @amx_matrix_multiply(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %3, 0
  br i1 %5, label %.preheader26.us.preheader, label %._crit_edge

.preheader26.us.preheader:                        ; preds = %4
  %6 = zext nneg i32 %3 to i64
  %xtraiter = and i64 %6, 3
  %7 = icmp ult i32 %3, 4
  %unroll_iter = and i64 %6, 2147483644
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader26.us

.preheader26.us:                                  ; preds = %.preheader26.us.preheader, %._crit_edge30.split.us.us
  %indvars.iv38 = phi i64 [ 0, %.preheader26.us.preheader ], [ %indvars.iv.next39, %._crit_edge30.split.us.us ]
  %8 = mul nuw nsw i64 %indvars.iv38, %6
  %invariant.gep = getelementptr inbounds float, ptr %1, i64 %8
  %invariant.gep45 = getelementptr inbounds float, ptr %0, i64 %8
  br label %.preheader.us.us

.preheader.us.us:                                 ; preds = %._crit_edge.us.us, %.preheader26.us
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %._crit_edge.us.us ], [ 0, %.preheader26.us ]
  %invariant.gep43 = getelementptr inbounds float, ptr %2, i64 %indvars.iv33
  br i1 %7, label %._crit_edge.us.us.unr-lcssa, label %.preheader.us.us.new

.preheader.us.us.new:                             ; preds = %.preheader.us.us, %.preheader.us.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.preheader.us.us.new ], [ 0, %.preheader.us.us ]
  %.02227.us.us = phi float [ %24, %.preheader.us.us.new ], [ 0.000000e+00, %.preheader.us.us ]
  %niter = phi i64 [ %niter.next.3, %.preheader.us.us.new ], [ 0, %.preheader.us.us ]
  %gep = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv
  %9 = load float, ptr %gep, align 4, !tbaa !5
  %10 = mul nuw nsw i64 %indvars.iv, %6
  %gep44 = getelementptr inbounds float, ptr %invariant.gep43, i64 %10
  %11 = load float, ptr %gep44, align 4, !tbaa !5
  %12 = tail call float @llvm.fmuladd.f32(float %9, float %11, float %.02227.us.us)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %gep.1 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next
  %13 = load float, ptr %gep.1, align 4, !tbaa !5
  %14 = mul nuw nsw i64 %indvars.iv.next, %6
  %gep44.1 = getelementptr inbounds float, ptr %invariant.gep43, i64 %14
  %15 = load float, ptr %gep44.1, align 4, !tbaa !5
  %16 = tail call float @llvm.fmuladd.f32(float %13, float %15, float %12)
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %gep.2 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next.1
  %17 = load float, ptr %gep.2, align 4, !tbaa !5
  %18 = mul nuw nsw i64 %indvars.iv.next.1, %6
  %gep44.2 = getelementptr inbounds float, ptr %invariant.gep43, i64 %18
  %19 = load float, ptr %gep44.2, align 4, !tbaa !5
  %20 = tail call float @llvm.fmuladd.f32(float %17, float %19, float %16)
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %gep.3 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next.2
  %21 = load float, ptr %gep.3, align 4, !tbaa !5
  %22 = mul nuw nsw i64 %indvars.iv.next.2, %6
  %gep44.3 = getelementptr inbounds float, ptr %invariant.gep43, i64 %22
  %23 = load float, ptr %gep44.3, align 4, !tbaa !5
  %24 = tail call float @llvm.fmuladd.f32(float %21, float %23, float %20)
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.us.unr-lcssa, label %.preheader.us.us.new, !llvm.loop !9

._crit_edge.us.us.unr-lcssa:                      ; preds = %.preheader.us.us.new, %.preheader.us.us
  %.lcssa.ph = phi float [ poison, %.preheader.us.us ], [ %24, %.preheader.us.us.new ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us.us ], [ %indvars.iv.next.3, %.preheader.us.us.new ]
  %.02227.us.us.unr = phi float [ 0.000000e+00, %.preheader.us.us ], [ %24, %.preheader.us.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.us.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.us.us.unr-lcssa ]
  %.02227.us.us.epil = phi float [ %28, %.epil.preheader ], [ %.02227.us.us.unr, %._crit_edge.us.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.us.unr-lcssa ]
  %gep.epil = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.epil
  %25 = load float, ptr %gep.epil, align 4, !tbaa !5
  %26 = mul nuw nsw i64 %indvars.iv.epil, %6
  %gep44.epil = getelementptr inbounds float, ptr %invariant.gep43, i64 %26
  %27 = load float, ptr %gep44.epil, align 4, !tbaa !5
  %28 = tail call float @llvm.fmuladd.f32(float %25, float %27, float %.02227.us.us.epil)
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us.us, label %.epil.preheader, !llvm.loop !11

._crit_edge.us.us:                                ; preds = %.epil.preheader, %._crit_edge.us.us.unr-lcssa
  %.lcssa = phi float [ %.lcssa.ph, %._crit_edge.us.us.unr-lcssa ], [ %28, %.epil.preheader ]
  %gep46 = getelementptr inbounds float, ptr %invariant.gep45, i64 %indvars.iv33
  store float %.lcssa, ptr %gep46, align 4, !tbaa !5
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next34, %6
  br i1 %exitcond37.not, label %._crit_edge30.split.us.us, label %.preheader.us.us, !llvm.loop !13

._crit_edge30.split.us.us:                        ; preds = %._crit_edge.us.us
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond42.not = icmp eq i64 %indvars.iv.next39, %6
  br i1 %exitcond42.not, label %._crit_edge, label %.preheader26.us, !llvm.loop !14

._crit_edge:                                      ; preds = %._crit_edge30.split.us.us, %4
  ret void
}

; 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 = !{!6, !6, i64 0}
!6 = !{!"float", !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, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass