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

%struct.block_q8_K = type { float, [256 x i8], [16 x i16] }

@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@__PRETTY_FUNCTION__.dequantize_row_q8_K = external hidden unnamed_addr constant [79 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: nounwind uwtable
define dso_local void @dequantize_row_q8_K(ptr noalias noundef %0, ptr noalias noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = srem i64 %11, 256
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  br label %16

15:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 2519, ptr noundef @__PRETTY_FUNCTION__.dequantize_row_q8_K) #3
  unreachable

16:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = sdiv i64 %17, 256
  store i64 %18, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %19

19:                                               ; preds = %55, %16
  %20 = load i32, ptr %8, align 4, !tbaa !11
  %21 = sext i32 %20 to i64
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = icmp slt i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %19
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %58

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %51, %25
  %27 = load i32, ptr %10, align 4, !tbaa !11
  %28 = icmp slt i32 %27, 256
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %54

30:                                               ; preds = %26
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !11
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.block_q8_K, ptr %31, i64 %33
  %35 = getelementptr inbounds %struct.block_q8_K, ptr %34, i32 0, i32 0
  %36 = load float, ptr %35, align 4, !tbaa !13
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !11
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds %struct.block_q8_K, ptr %37, i64 %39
  %41 = getelementptr inbounds %struct.block_q8_K, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %10, align 4, !tbaa !11
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [256 x i8], ptr %41, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !16
  %46 = sext i8 %45 to i32
  %47 = sitofp i32 %46 to float
  %48 = fmul float %36, %47
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds float, ptr %49, i32 1
  store ptr %50, ptr %5, align 8, !tbaa !5
  store float %48, ptr %49, align 4, !tbaa !17
  br label %51

51:                                               ; preds = %30
  %52 = load i32, ptr %10, align 4, !tbaa !11
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %10, align 4, !tbaa !11
  br label %26, !llvm.loop !18

54:                                               ; preds = %29
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %8, align 4, !tbaa !11
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %8, align 4, !tbaa !11
  br label %19, !llvm.loop !20

58:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  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 = { 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 }
attributes #4 = { 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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"", !15, i64 0, !7, i64 4, !7, i64 260}
!15 = !{!"float", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!15, !15, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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_K = type { float, [256 x i8], [16 x i16] }

@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@__PRETTY_FUNCTION__.dequantize_row_q8_K = external hidden unnamed_addr constant [79 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: nounwind uwtable
define dso_local void @dequantize_row_q8_K(ptr noalias nocapture noundef readonly %0, ptr noalias nocapture noundef writeonly %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = and i64 %2, 255
  %5 = icmp eq i64 %4, 0
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 2519, ptr noundef nonnull @__PRETTY_FUNCTION__.dequantize_row_q8_K) #2
  unreachable

7:                                                ; preds = %3
  %8 = ashr exact i64 %2, 8
  %9 = icmp sgt i64 %8, 0
  br i1 %9, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %7
  %scevgep24 = getelementptr i8, ptr %0, i64 4
  %10 = mul i64 %8, 292
  %11 = getelementptr i8, ptr %0, i64 %10
  %scevgep25 = getelementptr i8, ptr %11, i64 -32
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %middle.block
  %indvars.iv20 = phi i64 [ %indvars.iv.next21, %middle.block ], [ 0, %.preheader.preheader ]
  %.01317 = phi ptr [ %.lcssa, %middle.block ], [ %1, %.preheader.preheader ]
  %12 = getelementptr inbounds %struct.block_q8_K, ptr %0, i64 %indvars.iv20
  %13 = load float, ptr %12, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %12, i64 4
  %scevgep = getelementptr i8, ptr %.01317, i64 1024
  %bound0 = icmp ult ptr %.01317, %scevgep25
  %bound1 = icmp ult ptr %scevgep24, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph, label %vector.ph

vector.ph:                                        ; preds = %.preheader
  %ind.end = getelementptr i8, ptr %.01317, i64 1024
  %broadcast.splatinsert = insertelement <4 x float> poison, float %13, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.1, %vector.body ]
  %offset.idx = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %.01317, i64 %offset.idx
  %15 = getelementptr inbounds [256 x i8], ptr %14, i64 0, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 4
  %wide.load = load <4 x i8>, ptr %15, align 1, !tbaa !10, !alias.scope !11
  %wide.load28 = load <4 x i8>, ptr %16, align 1, !tbaa !10, !alias.scope !11
  %17 = sitofp <4 x i8> %wide.load to <4 x float>
  %18 = sitofp <4 x i8> %wide.load28 to <4 x float>
  %19 = fmul <4 x float> %broadcast.splat, %17
  %20 = fmul <4 x float> %broadcast.splat, %18
  %21 = getelementptr i8, ptr %next.gep, i64 16
  store <4 x float> %19, ptr %next.gep, align 4, !tbaa !14, !alias.scope !15, !noalias !11
  store <4 x float> %20, ptr %21, align 4, !tbaa !14, !alias.scope !15, !noalias !11
  %index.next = or disjoint i64 %index, 8
  %offset.idx.1 = shl i64 %index.next, 2
  %next.gep.1 = getelementptr i8, ptr %.01317, i64 %offset.idx.1
  %22 = getelementptr inbounds [256 x i8], ptr %14, i64 0, i64 %index.next
  %23 = getelementptr inbounds i8, ptr %22, i64 4
  %wide.load.1 = load <4 x i8>, ptr %22, align 1, !tbaa !10, !alias.scope !11
  %wide.load28.1 = load <4 x i8>, ptr %23, align 1, !tbaa !10, !alias.scope !11
  %24 = sitofp <4 x i8> %wide.load.1 to <4 x float>
  %25 = sitofp <4 x i8> %wide.load28.1 to <4 x float>
  %26 = fmul <4 x float> %broadcast.splat, %24
  %27 = fmul <4 x float> %broadcast.splat, %25
  %28 = getelementptr i8, ptr %next.gep.1, i64 16
  store <4 x float> %26, ptr %next.gep.1, align 4, !tbaa !14, !alias.scope !15, !noalias !11
  store <4 x float> %27, ptr %28, align 4, !tbaa !14, !alias.scope !15, !noalias !11
  %index.next.1 = add nuw nsw i64 %index, 16
  %29 = icmp eq i64 %index.next.1, 256
  br i1 %29, label %middle.block, label %vector.body, !llvm.loop !17

._crit_edge:                                      ; preds = %middle.block, %7
  ret void

middle.block:                                     ; preds = %vector.body, %scalar.ph
  %.lcssa = phi ptr [ %49, %scalar.ph ], [ %ind.end, %vector.body ]
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %exitcond23.not = icmp eq i64 %indvars.iv.next21, %8
  br i1 %exitcond23.not, label %._crit_edge, label %.preheader, !llvm.loop !21

scalar.ph:                                        ; preds = %.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ 0, %.preheader ]
  %.115 = phi ptr [ %49, %scalar.ph ], [ %.01317, %.preheader ]
  %30 = getelementptr inbounds [256 x i8], ptr %14, i64 0, i64 %indvars.iv
  %31 = load i8, ptr %30, align 1, !tbaa !10
  %32 = sitofp i8 %31 to float
  %33 = fmul float %13, %32
  %34 = getelementptr inbounds i8, ptr %.115, i64 4
  store float %33, ptr %.115, align 4, !tbaa !14
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %35 = getelementptr inbounds [256 x i8], ptr %14, i64 0, i64 %indvars.iv.next
  %36 = load i8, ptr %35, align 1, !tbaa !10
  %37 = sitofp i8 %36 to float
  %38 = fmul float %13, %37
  %39 = getelementptr inbounds i8, ptr %.115, i64 8
  store float %38, ptr %34, align 4, !tbaa !14
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %40 = getelementptr inbounds [256 x i8], ptr %14, i64 0, i64 %indvars.iv.next.1
  %41 = load i8, ptr %40, align 1, !tbaa !10
  %42 = sitofp i8 %41 to float
  %43 = fmul float %13, %42
  %44 = getelementptr inbounds i8, ptr %.115, i64 12
  store float %43, ptr %39, align 4, !tbaa !14
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %45 = getelementptr inbounds [256 x i8], ptr %14, i64 0, i64 %indvars.iv.next.2
  %46 = load i8, ptr %45, align 1, !tbaa !10
  %47 = sitofp i8 %46 to float
  %48 = fmul float %13, %47
  %49 = getelementptr inbounds i8, ptr %.115, i64 16
  store float %48, ptr %44, align 4, !tbaa !14
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 256
  br i1 %exitcond.not.3, label %middle.block, label %scalar.ph, !llvm.loop !22
}

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 = { 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 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !8, i64 4, !8, i64 260}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12}
!12 = distinct !{!12, !13}
!13 = distinct !{!13, !"LVerDomain"}
!14 = !{!7, !7, i64 0}
!15 = !{!16}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !18, !19, !20}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"llvm.loop.isvectorized", i32 1}
!20 = !{!"llvm.loop.unroll.runtime.disable"}
!21 = distinct !{!21, !18}
!22 = distinct !{!22, !18, !19}


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