; 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_q4_0 = type { i16, [16 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_q4_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: nounwind uwtable
define dso_local void @dequantize_row_q4_0(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 i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = 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
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = srem i64 %14, 32
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  br label %19

18:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 258, ptr noundef @__PRETTY_FUNCTION__.dequantize_row_q4_0) #4
  unreachable

19:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = sdiv i64 %20, 32
  %22 = trunc i64 %21 to i32
  store i32 %22, 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 %23

23:                                               ; preds = %93, %19
  %24 = load i32, ptr %8, align 4, !tbaa !11
  %25 = load i32, ptr %7, align 4, !tbaa !11
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !11
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds %struct.block_q4_0, ptr %29, i64 %31
  %33 = getelementptr inbounds %struct.block_q4_0, ptr %32, i32 0, i32 0
  %34 = load i16, ptr %33, align 2, !tbaa !13
  %35 = call float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext %34)
  store float %35, 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 %36

36:                                               ; preds = %89, %28
  %37 = load i32, ptr %11, align 4, !tbaa !11
  %38 = icmp slt i32 %37, 16
  br i1 %38, label %40, label %39

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

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !11
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %struct.block_q4_0, ptr %41, i64 %43
  %45 = getelementptr inbounds %struct.block_q4_0, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %11, align 4, !tbaa !11
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [16 x i8], ptr %45, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !18
  %50 = zext i8 %49 to i32
  %51 = and i32 %50, 15
  %52 = sub nsw i32 %51, 8
  store i32 %52, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !11
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds %struct.block_q4_0, ptr %53, i64 %55
  %57 = getelementptr inbounds %struct.block_q4_0, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %11, align 4, !tbaa !11
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [16 x i8], ptr %57, i64 0, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !18
  %62 = zext i8 %61 to i32
  %63 = ashr i32 %62, 4
  %64 = sub nsw i32 %63, 8
  store i32 %64, ptr %13, align 4, !tbaa !11
  %65 = load i32, ptr %12, align 4, !tbaa !11
  %66 = sitofp i32 %65 to float
  %67 = load float, ptr %10, align 4, !tbaa !16
  %68 = fmul float %66, %67
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !11
  %71 = mul nsw i32 %70, 32
  %72 = load i32, ptr %11, align 4, !tbaa !11
  %73 = add nsw i32 %71, %72
  %74 = add nsw i32 %73, 0
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds float, ptr %69, i64 %75
  store float %68, ptr %76, align 4, !tbaa !16
  %77 = load i32, ptr %13, align 4, !tbaa !11
  %78 = sitofp i32 %77 to float
  %79 = load float, ptr %10, align 4, !tbaa !16
  %80 = fmul float %78, %79
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i32, ptr %8, align 4, !tbaa !11
  %83 = mul nsw i32 %82, 32
  %84 = load i32, ptr %11, align 4, !tbaa !11
  %85 = add nsw i32 %83, %84
  %86 = add nsw i32 %85, 16
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds float, ptr %81, i64 %87
  store float %80, ptr %88, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %89

89:                                               ; preds = %40
  %90 = load i32, ptr %11, align 4, !tbaa !11
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %11, align 4, !tbaa !11
  br label %36, !llvm.loop !19

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

93:                                               ; preds = %92
  %94 = load i32, ptr %8, align 4, !tbaa !11
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %8, align 4, !tbaa !11
  br label %23, !llvm.loop !21

96:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret void
}

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

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 = { 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 #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_q4_0 = type { i16, [16 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_q4_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: nounwind uwtable
define dso_local void @dequantize_row_q4_0(ptr noalias nocapture noundef readonly %0, ptr noalias nocapture noundef writeonly %1, i64 noundef %2) local_unnamed_addr #1 {
  %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 258, ptr noundef nonnull @__PRETTY_FUNCTION__.dequantize_row_q4_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_q4_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 = or disjoint i64 %16, 16
  %19 = getelementptr inbounds float, ptr %1, i64 %18
  %20 = load <4 x i8>, ptr %14, align 1, !tbaa !10
  %21 = and <4 x i8> %20, <i8 15, i8 15, i8 15, i8 15>
  %22 = add nsw <4 x i8> %21, <i8 -8, i8 -8, i8 -8, i8 -8>
  %23 = sitofp <4 x i8> %22 to <4 x float>
  %24 = insertelement <4 x float> poison, float %13, i64 0
  %25 = shufflevector <4 x float> %24, <4 x float> poison, <4 x i32> zeroinitializer
  %26 = fmul <4 x float> %25, %23
  store <4 x float> %26, ptr %17, align 4, !tbaa !11
  %27 = lshr <4 x i8> %20, <i8 4, i8 4, i8 4, i8 4>
  %28 = add nsw <4 x i8> %27, <i8 -8, i8 -8, i8 -8, i8 -8>
  %29 = sitofp <4 x i8> %28 to <4 x float>
  %30 = fmul <4 x float> %25, %29
  store <4 x float> %30, ptr %19, align 4, !tbaa !11
  %31 = getelementptr inbounds i8, ptr %11, i64 6
  %32 = or disjoint i64 %16, 4
  %33 = getelementptr inbounds float, ptr %1, i64 %32
  %34 = or disjoint i64 %16, 20
  %35 = getelementptr inbounds float, ptr %1, i64 %34
  %36 = load <4 x i8>, ptr %31, align 1, !tbaa !10
  %37 = and <4 x i8> %36, <i8 15, i8 15, i8 15, i8 15>
  %38 = add nsw <4 x i8> %37, <i8 -8, i8 -8, i8 -8, i8 -8>
  %39 = sitofp <4 x i8> %38 to <4 x float>
  %40 = fmul <4 x float> %25, %39
  store <4 x float> %40, ptr %33, align 4, !tbaa !11
  %41 = lshr <4 x i8> %36, <i8 4, i8 4, i8 4, i8 4>
  %42 = add nsw <4 x i8> %41, <i8 -8, i8 -8, i8 -8, i8 -8>
  %43 = sitofp <4 x i8> %42 to <4 x float>
  %44 = fmul <4 x float> %25, %43
  store <4 x float> %44, ptr %35, align 4, !tbaa !11
  %45 = getelementptr inbounds i8, ptr %11, i64 10
  %46 = or disjoint i64 %16, 8
  %47 = getelementptr inbounds float, ptr %1, i64 %46
  %48 = or disjoint i64 %16, 24
  %49 = getelementptr inbounds float, ptr %1, i64 %48
  %50 = load <4 x i8>, ptr %45, align 1, !tbaa !10
  %51 = and <4 x i8> %50, <i8 15, i8 15, i8 15, i8 15>
  %52 = add nsw <4 x i8> %51, <i8 -8, i8 -8, i8 -8, i8 -8>
  %53 = sitofp <4 x i8> %52 to <4 x float>
  %54 = fmul <4 x float> %25, %53
  store <4 x float> %54, ptr %47, align 4, !tbaa !11
  %55 = lshr <4 x i8> %50, <i8 4, i8 4, i8 4, i8 4>
  %56 = add nsw <4 x i8> %55, <i8 -8, i8 -8, i8 -8, i8 -8>
  %57 = sitofp <4 x i8> %56 to <4 x float>
  %58 = fmul <4 x float> %25, %57
  store <4 x float> %58, ptr %49, align 4, !tbaa !11
  %59 = getelementptr inbounds i8, ptr %11, i64 14
  %60 = or disjoint i64 %16, 12
  %61 = getelementptr inbounds float, ptr %1, i64 %60
  %62 = or disjoint i64 %16, 28
  %63 = getelementptr inbounds float, ptr %1, i64 %62
  %64 = load <4 x i8>, ptr %59, align 1, !tbaa !10
  %65 = and <4 x i8> %64, <i8 15, i8 15, i8 15, i8 15>
  %66 = add nsw <4 x i8> %65, <i8 -8, i8 -8, i8 -8, i8 -8>
  %67 = sitofp <4 x i8> %66 to <4 x float>
  %68 = fmul <4 x float> %25, %67
  store <4 x float> %68, ptr %61, align 4, !tbaa !11
  %69 = lshr <4 x i8> %64, <i8 4, i8 4, i8 4, i8 4>
  %70 = add nsw <4 x i8> %69, <i8 -8, i8 -8, i8 -8, i8 -8>
  %71 = sitofp <4 x i8> %70 to <4 x float>
  %72 = fmul <4 x float> %25, %71
  store <4 x float> %72, ptr %63, 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
}

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

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 = { 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 = { 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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass