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

@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.mul_mat_gq_2 = external hidden unnamed_addr constant [70 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @quantize_2_row_size(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @vec_dot_gq_2(i32 noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @mul_mat_gq_2(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #3 {
  %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
  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
  %16 = load i32, ptr %12, align 4, !tbaa !9
  %17 = srem i32 %16, 64
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %6
  br label %21

20:                                               ; preds = %6
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 663, ptr noundef @__PRETTY_FUNCTION__.mul_mat_gq_2) #4
  unreachable

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

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

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

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

28:                                               ; preds = %46, %27
  %29 = load i32, ptr %15, align 4, !tbaa !9
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %28
  %34 = load i32, ptr %12, align 4, !tbaa !9
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load i32, ptr %15, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds float, ptr %35, i64 %37
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  call void @vec_dot_gq_2(i32 noundef %34, ptr noundef %38, ptr noundef %39, ptr noundef %40)
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = call i32 @quantize_2_row_size(i32 noundef %42)
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %41, i64 %44
  store ptr %45, ptr %8, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %33
  %47 = load i32, ptr %15, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %15, align 4, !tbaa !9
  br label %28, !llvm.loop !11

49:                                               ; preds = %32
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i32, ptr %12, align 4, !tbaa !9
  %52 = call i32 @quantize_2_row_size(i32 noundef %51)
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %50, i64 %53
  store ptr %54, ptr %7, align 8, !tbaa !5
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load i32, ptr %11, align 4, !tbaa !9
  %57 = load i32, ptr %12, align 4, !tbaa !9
  %58 = call i32 @quantize_2_row_size(i32 noundef %57)
  %59 = mul nsw i32 %56, %58
  %60 = sext i32 %59 to i64
  %61 = sub i64 0, %60
  %62 = getelementptr inbounds i8, ptr %55, i64 %61
  store ptr %62, ptr %8, align 8, !tbaa !5
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = load i32, ptr %11, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds float, ptr %63, i64 %65
  store ptr %66, ptr %9, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %49
  %68 = load i32, ptr %13, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %13, align 4, !tbaa !9
  br label %22, !llvm.loop !13

70:                                               ; preds = %26
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 = { inlinehint 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 #3 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.mul_mat_gq_2 = external hidden unnamed_addr constant [70 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @quantize_2_row_size(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @vec_dot_gq_2(i32 noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @mul_mat_gq_2(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #2 {
  %7 = and i32 %5, 63
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %.preheader25, label %27

.preheader25:                                     ; preds = %6
  %9 = icmp sgt i32 %3, 0
  br i1 %9, label %.preheader.lr.ph, label %._crit_edge32

.preheader.lr.ph:                                 ; preds = %.preheader25
  %10 = icmp sgt i32 %4, 0
  %11 = sext i32 %4 to i64
  br i1 %10, label %.preheader.us.preheader, label %.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.02031.us = phi i32 [ %26, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %.02130.us = phi ptr [ %19, %._crit_edge.us ], [ %0, %.preheader.us.preheader ]
  %.02229.us = phi ptr [ %24, %._crit_edge.us ], [ %1, %.preheader.us.preheader ]
  %.02328.us = phi ptr [ %25, %._crit_edge.us ], [ %2, %.preheader.us.preheader ]
  br label %12

12:                                               ; preds = %.preheader.us, %12
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %12 ]
  %.126.us = phi ptr [ %.02229.us, %.preheader.us ], [ %16, %12 ]
  %13 = getelementptr inbounds float, ptr %.02328.us, i64 %indvars.iv
  tail call void @vec_dot_gq_2(i32 noundef %5, ptr noundef %13, ptr noundef %.02130.us, ptr noundef %.126.us)
  %14 = tail call i32 @quantize_2_row_size(i32 noundef %5)
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %.126.us, i64 %15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond35.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond35.not, label %._crit_edge.us, label %12, !llvm.loop !5

._crit_edge.us:                                   ; preds = %12
  %17 = tail call i32 @quantize_2_row_size(i32 noundef %5)
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %.02130.us, i64 %18
  %20 = tail call i32 @quantize_2_row_size(i32 noundef %5)
  %21 = mul nsw i32 %20, %4
  %22 = sext i32 %21 to i64
  %23 = sub nsw i64 0, %22
  %24 = getelementptr inbounds i8, ptr %16, i64 %23
  %25 = getelementptr inbounds float, ptr %.02328.us, i64 %11
  %26 = add nuw nsw i32 %.02031.us, 1
  %exitcond36.not = icmp eq i32 %26, %3
  br i1 %exitcond36.not, label %._crit_edge32, label %.preheader.us, !llvm.loop !7

27:                                               ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 663, ptr noundef nonnull @__PRETTY_FUNCTION__.mul_mat_gq_2) #3
  unreachable

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %.02031 = phi i32 [ %30, %.preheader ], [ 0, %.preheader.lr.ph ]
  %28 = tail call i32 @quantize_2_row_size(i32 noundef %5)
  %29 = tail call i32 @quantize_2_row_size(i32 noundef %5)
  %30 = add nuw nsw i32 %.02031, 1
  %exitcond.not = icmp eq i32 %30, %3
  br i1 %exitcond.not, label %._crit_edge32, label %.preheader, !llvm.loop !7

._crit_edge32:                                    ; preds = %.preheader, %._crit_edge.us, %.preheader25
  ret void
}

attributes #0 = { noreturn nounwind "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 = { inlinehint 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 = { 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 #3 = { noreturn 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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