; 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_3 = 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_3_blocks_per_row(i32 noundef) #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @mul_mat_gq_3(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
  %16 = alloca i32, 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
  %18 = load i32, ptr %12, align 4, !tbaa !9
  %19 = srem i32 %18, 64
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %6
  br label %23

22:                                               ; preds = %6
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1009, ptr noundef @__PRETTY_FUNCTION__.mul_mat_gq_3) #4
  unreachable

23:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %24 = load i32, ptr %12, align 4, !tbaa !9
  %25 = call i32 @quantize_3_blocks_per_row(i32 noundef %24)
  store i32 %25, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %26 = call i32 @quantize_3_quants_per_block()
  store i32 %26, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %27

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

31:                                               ; preds = %27
  store i32 2, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %75

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

33:                                               ; preds = %51, %32
  %34 = load i32, ptr %17, align 4, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 5, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  br label %54

38:                                               ; preds = %33
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = load i32, ptr %17, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds float, ptr %40, i64 %42
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  call void @vec_dot_gq_3(i32 noundef %39, ptr noundef %43, ptr noundef %44, ptr noundef %45)
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = call i32 @quantize_3_row_size(i32 noundef %47)
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i8, ptr %46, i64 %49
  store ptr %50, ptr %8, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %38
  %52 = load i32, ptr %17, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %17, align 4, !tbaa !9
  br label %33, !llvm.loop !11

54:                                               ; preds = %37
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load i32, ptr %12, align 4, !tbaa !9
  %57 = call i32 @quantize_3_row_size(i32 noundef %56)
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %55, i64 %58
  store ptr %59, ptr %7, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = load i32, ptr %12, align 4, !tbaa !9
  %63 = call i32 @quantize_3_row_size(i32 noundef %62)
  %64 = mul nsw i32 %61, %63
  %65 = sext i32 %64 to i64
  %66 = sub i64 0, %65
  %67 = getelementptr inbounds i8, ptr %60, i64 %66
  store ptr %67, ptr %8, align 8, !tbaa !5
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds float, ptr %68, i64 %70
  store ptr %71, ptr %9, align 8, !tbaa !5
  br label %72

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

75:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  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_3 = 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_3_blocks_per_row(i32 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @vec_dot_gq_3(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_3(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 %10, label %9

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

10:                                               ; preds = %6
  %11 = tail call i32 @quantize_3_blocks_per_row(i32 noundef %5)
  %12 = tail call i32 @quantize_3_quants_per_block()
  %13 = icmp sgt i32 %3, 0
  br i1 %13, label %.preheader.lr.ph, label %._crit_edge32

.preheader.lr.ph:                                 ; preds = %10
  %14 = icmp sgt i32 %4, 0
  %15 = sext i32 %4 to i64
  br i1 %14, 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
  %.02131.us = phi i32 [ %30, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %.02230.us = phi ptr [ %23, %._crit_edge.us ], [ %0, %.preheader.us.preheader ]
  %.02329.us = phi ptr [ %28, %._crit_edge.us ], [ %1, %.preheader.us.preheader ]
  %.02428.us = phi ptr [ %29, %._crit_edge.us ], [ %2, %.preheader.us.preheader ]
  br label %16

16:                                               ; preds = %.preheader.us, %16
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %16 ]
  %.126.us = phi ptr [ %.02329.us, %.preheader.us ], [ %20, %16 ]
  %17 = getelementptr inbounds float, ptr %.02428.us, i64 %indvars.iv
  tail call void @vec_dot_gq_3(i32 noundef %5, ptr noundef %17, ptr noundef %.02230.us, ptr noundef %.126.us)
  %18 = tail call i32 @quantize_3_row_size(i32 noundef %5)
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %.126.us, i64 %19
  %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 %16, !llvm.loop !5

._crit_edge.us:                                   ; preds = %16
  %21 = tail call i32 @quantize_3_row_size(i32 noundef %5)
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %.02230.us, i64 %22
  %24 = tail call i32 @quantize_3_row_size(i32 noundef %5)
  %25 = mul nsw i32 %24, %4
  %26 = sext i32 %25 to i64
  %27 = sub nsw i64 0, %26
  %28 = getelementptr inbounds i8, ptr %20, i64 %27
  %29 = getelementptr inbounds float, ptr %.02428.us, i64 %15
  %30 = add nuw nsw i32 %.02131.us, 1
  %exitcond36.not = icmp eq i32 %30, %3
  br i1 %exitcond36.not, label %._crit_edge32, label %.preheader.us, !llvm.loop !7

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %.02131 = phi i32 [ %33, %.preheader ], [ 0, %.preheader.lr.ph ]
  %31 = tail call i32 @quantize_3_row_size(i32 noundef %5)
  %32 = tail call i32 @quantize_3_row_size(i32 noundef %5)
  %33 = add nuw nsw i32 %.02131, 1
  %exitcond.not = icmp eq i32 %33, %3
  br i1 %exitcond.not, label %._crit_edge32, label %.preheader, !llvm.loop !7

._crit_edge32:                                    ; preds = %.preheader, %._crit_edge.us, %10
  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