; 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_0 = type { i16, [32 x i8] }

@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@__PRETTY_FUNCTION__.dequantize_row_q8_0 = 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: inlinehint nounwind uwtable
declare hidden float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext) #2

; Function Attrs: nounwind uwtable
define dso_local void @dequantize_row_q8_0(ptr noalias noundef %0, ptr noalias noundef %1, i64 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  %11 = 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
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = srem i64 %12, 32
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  br label %17

16:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 352, ptr noundef @__PRETTY_FUNCTION__.dequantize_row_q8_0) #4
  unreachable

17:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = sdiv i64 %18, 32
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %21

21:                                               ; preds = %63, %17
  %22 = load i32, ptr %8, align 4, !tbaa !11
  %23 = load i32, ptr %7, align 4, !tbaa !11
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !11
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %struct.block_q8_0, ptr %27, i64 %29
  %31 = getelementptr inbounds %struct.block_q8_0, ptr %30, i32 0, i32 0
  %32 = load i16, ptr %31, align 2, !tbaa !13
  %33 = call float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext %32)
  store float %33, ptr %10, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %34

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

37:                                               ; preds = %34
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %62

38:                                               ; preds = %34
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = load i32, ptr %8, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %struct.block_q8_0, ptr %39, i64 %41
  %43 = getelementptr inbounds %struct.block_q8_0, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %11, align 4, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [32 x i8], ptr %43, i64 0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !18
  %48 = sext i8 %47 to i32
  %49 = sitofp i32 %48 to float
  %50 = load float, ptr %10, align 4, !tbaa !16
  %51 = fmul float %49, %50
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !11
  %54 = mul nsw i32 %53, 32
  %55 = load i32, ptr %11, align 4, !tbaa !11
  %56 = add nsw i32 %54, %55
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds float, ptr %52, i64 %57
  store float %51, ptr %58, align 4, !tbaa !16
  br label %59

59:                                               ; preds = %38
  %60 = load i32, ptr %11, align 4, !tbaa !11
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %11, align 4, !tbaa !11
  br label %34, !llvm.loop !19

62:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %8, align 4, !tbaa !11
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %8, align 4, !tbaa !11
  br label %21, !llvm.loop !21

66:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #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 = { 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 = !{!"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 2}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"float", !7, i64 0}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@__PRETTY_FUNCTION__.dequantize_row_q8_0 = 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: inlinehint nounwind uwtable
declare hidden float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @dequantize_row_q8_0(ptr noalias nocapture noundef readonly %0, ptr noalias nocapture noundef writeonly %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = and i64 %2, 31
  %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, ptr noundef nonnull @.str.1, i32 noundef 352, ptr noundef nonnull @__PRETTY_FUNCTION__.dequantize_row_q8_0) #3
  unreachable

7:                                                ; preds = %3
  %8 = lshr exact i64 %2, 5
  %9 = trunc i64 %8 to i32
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %7
  %wide.trip.count = and i64 %8, 2147483647
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %7
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %11 = getelementptr inbounds %struct.block_q8_0, ptr %0, i64 %indvars.iv
  %12 = load i16, ptr %11, align 2, !tbaa !5
  %13 = tail call float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext %12)
  %14 = getelementptr inbounds i8, ptr %11, i64 2
  %15 = shl i64 %indvars.iv, 5
  %16 = and i64 %15, 4294967264
  %17 = getelementptr inbounds float, ptr %1, i64 %16
  %18 = load <4 x i8>, ptr %14, align 1, !tbaa !10
  %19 = sitofp <4 x i8> %18 to <4 x float>
  %20 = insertelement <4 x float> poison, float %13, i64 0
  %21 = shufflevector <4 x float> %20, <4 x float> poison, <4 x i32> zeroinitializer
  %22 = fmul <4 x float> %21, %19
  store <4 x float> %22, ptr %17, align 4, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %11, i64 6
  %24 = or disjoint i64 %16, 4
  %25 = getelementptr inbounds float, ptr %1, i64 %24
  %26 = load <4 x i8>, ptr %23, align 1, !tbaa !10
  %27 = sitofp <4 x i8> %26 to <4 x float>
  %28 = fmul <4 x float> %21, %27
  store <4 x float> %28, ptr %25, align 4, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %11, i64 10
  %30 = or disjoint i64 %16, 8
  %31 = getelementptr inbounds float, ptr %1, i64 %30
  %32 = load <4 x i8>, ptr %29, align 1, !tbaa !10
  %33 = sitofp <4 x i8> %32 to <4 x float>
  %34 = fmul <4 x float> %21, %33
  store <4 x float> %34, ptr %31, align 4, !tbaa !11
  %35 = getelementptr inbounds i8, ptr %11, i64 14
  %36 = or disjoint i64 %16, 12
  %37 = getelementptr inbounds float, ptr %1, i64 %36
  %38 = load <4 x i8>, ptr %35, align 1, !tbaa !10
  %39 = sitofp <4 x i8> %38 to <4 x float>
  %40 = fmul <4 x float> %21, %39
  store <4 x float> %40, ptr %37, align 4, !tbaa !11
  %41 = getelementptr inbounds i8, ptr %11, i64 18
  %42 = or disjoint i64 %16, 16
  %43 = getelementptr inbounds float, ptr %1, i64 %42
  %44 = load <4 x i8>, ptr %41, align 1, !tbaa !10
  %45 = sitofp <4 x i8> %44 to <4 x float>
  %46 = fmul <4 x float> %21, %45
  store <4 x float> %46, ptr %43, align 4, !tbaa !11
  %47 = getelementptr inbounds i8, ptr %11, i64 22
  %48 = or disjoint i64 %16, 20
  %49 = getelementptr inbounds float, ptr %1, i64 %48
  %50 = load <4 x i8>, ptr %47, align 1, !tbaa !10
  %51 = sitofp <4 x i8> %50 to <4 x float>
  %52 = fmul <4 x float> %21, %51
  store <4 x float> %52, ptr %49, align 4, !tbaa !11
  %53 = getelementptr inbounds i8, ptr %11, i64 26
  %54 = or disjoint i64 %16, 24
  %55 = getelementptr inbounds float, ptr %1, i64 %54
  %56 = load <4 x i8>, ptr %53, align 1, !tbaa !10
  %57 = sitofp <4 x i8> %56 to <4 x float>
  %58 = fmul <4 x float> %21, %57
  store <4 x float> %58, ptr %55, align 4, !tbaa !11
  %59 = getelementptr inbounds i8, ptr %11, i64 30
  %60 = or disjoint i64 %16, 28
  %61 = getelementptr inbounds float, ptr %1, i64 %60
  %62 = load <4 x i8>, ptr %59, align 1, !tbaa !10
  %63 = sitofp <4 x i8> %62 to <4 x float>
  %64 = fmul <4 x float> %21, %63
  store <4 x float> %64, ptr %61, align 4, !tbaa !11
  %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 %.lr.ph, !llvm.loop !13
}

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 = !{!6, !7, i64 0}
!6 = !{!"", !7, i64 0, !8, i64 2}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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