; LLVM IR from ggml-org/ggml :: src (ggml-quants)

; 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
declare dso_local void @quantize_row_q4_0_ref(ptr noalias noundef, ptr noalias noundef, i64 noundef) #0

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare i64 @ggml_row_size(i32 noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @quantize_q4_0(ptr noalias noundef %0, ptr noalias noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  %15 = load ptr, ptr %11, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %27, label %17

17:                                               ; preds = %5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = load i64, ptr %10, align 8, !tbaa !9
  %22 = mul nsw i64 %20, %21
  call void @quantize_row_q4_0_ref(ptr noundef %18, ptr noundef %19, i64 noundef %22)
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = load i64, ptr %10, align 8, !tbaa !9
  %25 = call i64 @ggml_row_size(i32 noundef 2, i64 noundef %24)
  %26 = mul i64 %23, %25
  store i64 %26, ptr %6, align 8
  br label %54

27:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = call i64 @ggml_row_size(i32 noundef 2, i64 noundef %28)
  store i64 %29, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %30, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store i64 0, ptr %14, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %47, %27
  %32 = load i64, ptr %14, align 8, !tbaa !9
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = icmp slt i64 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %50

36:                                               ; preds = %31
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = load i64, ptr %10, align 8, !tbaa !9
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  call void @quantize_row_q4_0_impl(ptr noundef %37, ptr noundef %38, i64 noundef %39, ptr noundef %40)
  %41 = load i64, ptr %10, align 8, !tbaa !9
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds float, ptr %42, i64 %41
  store ptr %43, ptr %7, align 8, !tbaa !5
  %44 = load i64, ptr %12, align 8, !tbaa !9
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 %44
  store ptr %46, ptr %13, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %36
  %48 = load i64, ptr %14, align 8, !tbaa !9
  %49 = add nsw i64 %48, 1
  store i64 %49, ptr %14, align 8, !tbaa !9
  br label %31, !llvm.loop !11

50:                                               ; preds = %35
  %51 = load i64, ptr %9, align 8, !tbaa !9
  %52 = load i64, ptr %12, align 8, !tbaa !9
  %53 = mul i64 %51, %52
  store i64 %53, ptr %6, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %54

54:                                               ; preds = %50, %17
  %55 = load i64, ptr %6, align 8
  ret i64 %55
}

; Function Attrs: nounwind uwtable
declare hidden void @quantize_row_q4_0_impl(ptr noalias noundef, ptr noalias noundef, i64 noundef, ptr noundef) #0

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 = { "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 }

!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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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: nounwind uwtable
declare dso_local void @quantize_row_q4_0_ref(ptr noalias noundef, ptr noalias noundef, i64 noundef) local_unnamed_addr #0

declare i64 @ggml_row_size(i32 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @quantize_q4_0(ptr noalias noundef %0, ptr noalias noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %6, label %9

6:                                                ; preds = %5
  %7 = mul nsw i64 %3, %2
  tail call void @quantize_row_q4_0_ref(ptr noundef %0, ptr noundef %1, i64 noundef %7)
  %8 = tail call i64 @ggml_row_size(i32 noundef 2, i64 noundef %3) #2
  br label %.loopexit

9:                                                ; preds = %5
  %10 = tail call i64 @ggml_row_size(i32 noundef 2, i64 noundef %3) #2
  %11 = icmp sgt i64 %2, 0
  br i1 %11, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %9, %.lr.ph
  %.029 = phi i64 [ %14, %.lr.ph ], [ 0, %9 ]
  %.02228 = phi ptr [ %13, %.lr.ph ], [ %1, %9 ]
  %.02427 = phi ptr [ %12, %.lr.ph ], [ %0, %9 ]
  tail call void @quantize_row_q4_0_impl(ptr noundef %.02427, ptr noundef %.02228, i64 noundef %3, ptr noundef nonnull %4)
  %12 = getelementptr inbounds float, ptr %.02427, i64 %3
  %13 = getelementptr inbounds i8, ptr %.02228, i64 %10
  %14 = add nuw nsw i64 %.029, 1
  %exitcond.not = icmp eq i64 %14, %2
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !5

.loopexit:                                        ; preds = %.lr.ph, %9, %6
  %.pn = phi i64 [ %8, %6 ], [ %10, %9 ], [ %10, %.lr.ph ]
  %.023 = mul i64 %.pn, %2
  ret i64 %.023
}

; Function Attrs: nounwind uwtable
declare hidden void @quantize_row_q4_0_impl(ptr noalias noundef, ptr noalias noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

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 = { "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 }

!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"}


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