; LLVM IR from ggml-org/ggml :: tests (test-mul-mat2)

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

18:                                               ; preds = %73, %6
  %19 = load i32, ptr %13, align 4, !tbaa !9
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

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

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

24:                                               ; preds = %69, %23
  %25 = load i32, ptr %15, align 4, !tbaa !9
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %72

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store float 0.000000e+00, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %56, %29
  %31 = load i32, ptr %17, align 4, !tbaa !9
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 8, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  br label %59

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

56:                                               ; preds = %35
  %57 = load i32, ptr %17, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %17, align 4, !tbaa !9
  br label %30, !llvm.loop !13

59:                                               ; preds = %34
  %60 = load float, ptr %16, align 4, !tbaa !11
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = load i32, ptr %13, align 4, !tbaa !9
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = mul nsw i32 %62, %63
  %65 = load i32, ptr %15, align 4, !tbaa !9
  %66 = add nsw i32 %64, %65
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds float, ptr %61, i64 %67
  store float %60, ptr %68, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %69

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

72:                                               ; preds = %28
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %13, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %13, align 4, !tbaa !9
  br label %18, !llvm.loop !16

76:                                               ; preds = %22
  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 @mul_mat_f32_naive(ptr noalias nocapture noundef readonly %0, ptr noalias nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = icmp sgt i32 %3, 0
  %8 = icmp sgt i32 %4, 0
  %or.cond = and i1 %7, %8
  br i1 %or.cond, label %.preheader27.lr.ph.split.us, label %._crit_edge

.preheader27.lr.ph.split.us:                      ; preds = %6
  %9 = icmp sgt i32 %5, 0
  br i1 %9, label %.preheader27.us.us.preheader, label %.preheader27.us.preheader

.preheader27.us.preheader:                        ; preds = %.preheader27.lr.ph.split.us
  %10 = zext nneg i32 %4 to i64
  %11 = zext nneg i32 %3 to i64
  %12 = mul nuw nsw i64 %10, %11
  %13 = shl nuw i64 %12, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %2, i8 0, i64 %13, i1 false), !tbaa !5
  br label %._crit_edge

.preheader27.us.us.preheader:                     ; preds = %.preheader27.lr.ph.split.us
  %14 = zext nneg i32 %5 to i64
  %15 = zext nneg i32 %4 to i64
  %wide.trip.count50 = zext nneg i32 %3 to i64
  %xtraiter = and i64 %14, 3
  %16 = icmp ult i32 %5, 4
  %unroll_iter = and i64 %14, 2147483644
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader27.us.us

.preheader27.us.us:                               ; preds = %.preheader27.us.us.preheader, %._crit_edge31.split.us.us.us
  %indvars.iv47 = phi i64 [ 0, %.preheader27.us.us.preheader ], [ %indvars.iv.next48, %._crit_edge31.split.us.us.us ]
  %17 = mul nuw nsw i64 %indvars.iv47, %14
  %18 = mul nuw nsw i64 %indvars.iv47, %15
  %invariant.gep = getelementptr inbounds float, ptr %0, i64 %17
  %invariant.gep54 = getelementptr inbounds float, ptr %2, i64 %18
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge.us.us.us, %.preheader27.us.us
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %._crit_edge.us.us.us ], [ 0, %.preheader27.us.us ]
  %19 = mul nuw nsw i64 %indvars.iv42, %14
  %invariant.gep52 = getelementptr inbounds float, ptr %1, i64 %19
  br i1 %16, label %._crit_edge.us.us.us.unr-lcssa, label %.preheader.us.us.us.new

.preheader.us.us.us.new:                          ; preds = %.preheader.us.us.us, %.preheader.us.us.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.preheader.us.us.us.new ], [ 0, %.preheader.us.us.us ]
  %.02228.us.us.us = phi float [ %31, %.preheader.us.us.us.new ], [ 0.000000e+00, %.preheader.us.us.us ]
  %niter = phi i64 [ %niter.next.3, %.preheader.us.us.us.new ], [ 0, %.preheader.us.us.us ]
  %gep = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv
  %20 = load float, ptr %gep, align 4, !tbaa !5
  %gep53 = getelementptr inbounds float, ptr %invariant.gep52, i64 %indvars.iv
  %21 = load float, ptr %gep53, align 4, !tbaa !5
  %22 = tail call float @llvm.fmuladd.f32(float %20, float %21, float %.02228.us.us.us)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %gep.1 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next
  %23 = load float, ptr %gep.1, align 4, !tbaa !5
  %gep53.1 = getelementptr inbounds float, ptr %invariant.gep52, i64 %indvars.iv.next
  %24 = load float, ptr %gep53.1, align 4, !tbaa !5
  %25 = tail call float @llvm.fmuladd.f32(float %23, float %24, float %22)
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %gep.2 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next.1
  %26 = load float, ptr %gep.2, align 4, !tbaa !5
  %gep53.2 = getelementptr inbounds float, ptr %invariant.gep52, i64 %indvars.iv.next.1
  %27 = load float, ptr %gep53.2, align 4, !tbaa !5
  %28 = tail call float @llvm.fmuladd.f32(float %26, float %27, float %25)
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %gep.3 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next.2
  %29 = load float, ptr %gep.3, align 4, !tbaa !5
  %gep53.3 = getelementptr inbounds float, ptr %invariant.gep52, i64 %indvars.iv.next.2
  %30 = load float, ptr %gep53.3, align 4, !tbaa !5
  %31 = tail call float @llvm.fmuladd.f32(float %29, float %30, float %28)
  %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.us.unr-lcssa, label %.preheader.us.us.us.new, !llvm.loop !9

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

.epil.preheader:                                  ; preds = %._crit_edge.us.us.us.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.us.us.us.unr-lcssa ]
  %.02228.us.us.us.epil = phi float [ %34, %.epil.preheader ], [ %.02228.us.us.us.unr, %._crit_edge.us.us.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.us.us.unr-lcssa ]
  %gep.epil = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.epil
  %32 = load float, ptr %gep.epil, align 4, !tbaa !5
  %gep53.epil = getelementptr inbounds float, ptr %invariant.gep52, i64 %indvars.iv.epil
  %33 = load float, ptr %gep53.epil, align 4, !tbaa !5
  %34 = tail call float @llvm.fmuladd.f32(float %32, float %33, float %.02228.us.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.us, label %.epil.preheader, !llvm.loop !11

._crit_edge.us.us.us:                             ; preds = %.epil.preheader, %._crit_edge.us.us.us.unr-lcssa
  %.lcssa = phi float [ %.lcssa.ph, %._crit_edge.us.us.us.unr-lcssa ], [ %34, %.epil.preheader ]
  %gep55 = getelementptr inbounds float, ptr %invariant.gep54, i64 %indvars.iv42
  store float %.lcssa, ptr %gep55, align 4, !tbaa !5
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %exitcond46.not = icmp eq i64 %indvars.iv.next43, %15
  br i1 %exitcond46.not, label %._crit_edge31.split.us.us.us, label %.preheader.us.us.us, !llvm.loop !13

._crit_edge31.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %exitcond51.not = icmp eq i64 %indvars.iv.next48, %wide.trip.count50
  br i1 %exitcond51.not, label %._crit_edge, label %.preheader27.us.us, !llvm.loop !14

._crit_edge:                                      ; preds = %._crit_edge31.split.us.us.us, %.preheader27.us.preheader, %6
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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: BDCEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass