; LLVM IR from ggml-org/ggml :: src/ggml-cpu (ggml-cpu-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"

%struct.block_q8_0 = type { i16, [32 x i8] }

@.str.1 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@__PRETTY_FUNCTION__.ggml_vec_dot_q8_0_q8_0 = external hidden unnamed_addr constant [123 x i8], align 1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @ggml_vec_dot_q8_0_q8_0(i32 noundef %0, ptr noalias noundef %1, i64 noundef %2, ptr noalias noundef %3, i64 noundef %4, ptr noalias noundef %5, i64 noundef %6, i32 noundef %7) #4 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i32, align 4
  %22 = alloca float, align 4
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  store i32 %0, ptr %9, align 4, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !9
  store i64 %2, ptr %11, align 8, !tbaa !11
  store ptr %3, ptr %12, align 8, !tbaa !9
  store i64 %4, ptr %13, align 8, !tbaa !11
  store ptr %5, ptr %14, align 8, !tbaa !9
  store i64 %6, ptr %15, align 8, !tbaa !11
  store i32 %7, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  store i32 32, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  %25 = load i32, ptr %9, align 4, !tbaa !5
  %26 = sdiv i32 %25, 32
  store i32 %26, ptr %18, align 4, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !5
  %28 = srem i32 %27, 32
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %8
  br label %32

31:                                               ; preds = %8
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 3601, ptr noundef @__PRETTY_FUNCTION__.ggml_vec_dot_q8_0_q8_0) #6
  unreachable

32:                                               ; preds = %30
  %33 = load i32, ptr %16, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 1
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  br label %37

36:                                               ; preds = %32
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 3605, ptr noundef @__PRETTY_FUNCTION__.ggml_vec_dot_q8_0_q8_0) #6
  unreachable

37:                                               ; preds = %35
  %38 = load i32, ptr %16, align 4, !tbaa !5
  %39 = load i64, ptr %13, align 8, !tbaa !11
  %40 = load i64, ptr %15, align 8, !tbaa !11
  %41 = load i64, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  %42 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %42, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #5
  %43 = load ptr, ptr %14, align 8, !tbaa !9
  store ptr %43, ptr %20, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #5
  store i32 0, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #5
  store float 0.000000e+00, ptr %22, align 4, !tbaa !13
  br label %44

44:                                               ; preds = %100, %37
  %45 = load i32, ptr %21, align 4, !tbaa !5
  %46 = load i32, ptr %18, align 4, !tbaa !5
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %48, label %103

48:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #5
  store i32 0, ptr %23, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #5
  store i32 0, ptr %24, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %77, %48
  %50 = load i32, ptr %24, align 4, !tbaa !5
  %51 = icmp slt i32 %50, 32
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #5
  br label %80

53:                                               ; preds = %49
  %54 = load ptr, ptr %19, align 8, !tbaa !9
  %55 = load i32, ptr %21, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds %struct.block_q8_0, ptr %54, i64 %56
  %58 = getelementptr inbounds %struct.block_q8_0, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %24, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [32 x i8], ptr %58, i64 0, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !15
  %63 = sext i8 %62 to i32
  %64 = load ptr, ptr %20, align 8, !tbaa !9
  %65 = load i32, ptr %21, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds %struct.block_q8_0, ptr %64, i64 %66
  %68 = getelementptr inbounds %struct.block_q8_0, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %24, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [32 x i8], ptr %68, i64 0, i64 %70
  %72 = load i8, ptr %71, align 1, !tbaa !15
  %73 = sext i8 %72 to i32
  %74 = mul nsw i32 %63, %73
  %75 = load i32, ptr %23, align 4, !tbaa !5
  %76 = add nsw i32 %75, %74
  store i32 %76, ptr %23, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %53
  %78 = load i32, ptr %24, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %24, align 4, !tbaa !5
  br label %49, !llvm.loop !16

80:                                               ; preds = %52
  %81 = load i32, ptr %23, align 4, !tbaa !5
  %82 = sitofp i32 %81 to float
  %83 = load ptr, ptr %19, align 8, !tbaa !9
  %84 = load i32, ptr %21, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds %struct.block_q8_0, ptr %83, i64 %85
  %87 = getelementptr inbounds %struct.block_q8_0, ptr %86, i32 0, i32 0
  %88 = load i16, ptr %87, align 2, !tbaa !18
  %89 = call float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext %88)
  %90 = load ptr, ptr %20, align 8, !tbaa !9
  %91 = load i32, ptr %21, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds %struct.block_q8_0, ptr %90, i64 %92
  %94 = getelementptr inbounds %struct.block_q8_0, ptr %93, i32 0, i32 0
  %95 = load i16, ptr %94, align 2, !tbaa !18
  %96 = call float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext %95)
  %97 = fmul float %89, %96
  %98 = load float, ptr %22, align 4, !tbaa !13
  %99 = call float @llvm.fmuladd.f32(float %82, float %97, float %98)
  store float %99, ptr %22, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #5
  br label %100

100:                                              ; preds = %80
  %101 = load i32, ptr %21, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %21, align 4, !tbaa !5
  br label %44, !llvm.loop !21

103:                                              ; preds = %44
  %104 = load float, ptr %22, align 4, !tbaa !13
  %105 = load ptr, ptr %10, align 8, !tbaa !9
  store float %104, ptr %105, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !20, i64 0}
!19 = !{!"", !20, i64 0, !7, i64 2}
!20 = !{!"short", !7, i64 0}
!21 = distinct !{!21, !17}


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

%struct.block_q8_0 = type { i16, [32 x i8] }

@.str.1 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@__PRETTY_FUNCTION__.ggml_vec_dot_q8_0_q8_0 = external hidden unnamed_addr constant [123 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 float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @ggml_vec_dot_q8_0_q8_0(i32 noundef %0, ptr noalias nocapture noundef writeonly %1, i64 noundef %2, ptr noalias nocapture noundef readonly %3, i64 noundef %4, ptr noalias nocapture noundef readonly %5, i64 noundef %6, i32 noundef %7) local_unnamed_addr #3 {
  %9 = sdiv i32 %0, 32
  %10 = and i32 %0, 31
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 3601, ptr noundef nonnull @__PRETTY_FUNCTION__.ggml_vec_dot_q8_0_q8_0) #5
  unreachable

13:                                               ; preds = %8
  %14 = icmp eq i32 %7, 1
  br i1 %14, label %.preheader31, label %16

.preheader31:                                     ; preds = %13
  %15 = icmp sgt i32 %0, 31
  br i1 %15, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %.preheader31
  %wide.trip.count = zext nneg i32 %9 to i64
  br label %.preheader

16:                                               ; preds = %13
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 3605, ptr noundef nonnull @__PRETTY_FUNCTION__.ggml_vec_dot_q8_0_q8_0) #5
  unreachable

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %indvars.iv = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next, %.preheader ]
  %.02935 = phi float [ 0.000000e+00, %.preheader.preheader ], [ %33, %.preheader ]
  %17 = getelementptr inbounds %struct.block_q8_0, ptr %3, i64 %indvars.iv, i32 1, i64 0
  %18 = getelementptr inbounds %struct.block_q8_0, ptr %5, i64 %indvars.iv, i32 1, i64 0
  %19 = load <32 x i8>, ptr %17, align 1, !tbaa !5
  %20 = sext <32 x i8> %19 to <32 x i32>
  %21 = load <32 x i8>, ptr %18, align 1, !tbaa !5
  %22 = sext <32 x i8> %21 to <32 x i32>
  %23 = mul nsw <32 x i32> %22, %20
  %24 = tail call i32 @llvm.vector.reduce.add.v32i32(<32 x i32> %23)
  %25 = sitofp i32 %24 to float
  %26 = getelementptr inbounds %struct.block_q8_0, ptr %3, i64 %indvars.iv
  %27 = load i16, ptr %26, align 2, !tbaa !8
  %28 = tail call float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext %27)
  %29 = getelementptr inbounds %struct.block_q8_0, ptr %5, i64 %indvars.iv
  %30 = load i16, ptr %29, align 2, !tbaa !8
  %31 = tail call float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext %30)
  %32 = fmul float %28, %31
  %33 = tail call float @llvm.fmuladd.f32(float %25, float %32, float %.02935)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !11

._crit_edge:                                      ; preds = %.preheader, %.preheader31
  %.029.lcssa = phi float [ 0.000000e+00, %.preheader31 ], [ %33, %.preheader ]
  store float %.029.lcssa, ptr %1, align 4, !tbaa !13
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v32i32(<32 x i32>) #4

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"", !10, i64 0, !6, i64 2}
!10 = !{!"short", !6, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !6, i64 0}


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