; 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_1 = type { %union.anon, [16 x i8] }
%union.anon = type { i32 }
%struct.anon = type { i16, i16 }

@.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_1 = 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_q4_1(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 float, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = 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
  %15 = load i64, ptr %6, align 8, !tbaa !9
  %16 = srem i64 %15, 32
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %3
  br label %20

19:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 278, ptr noundef @__PRETTY_FUNCTION__.dequantize_row_q4_1) #5
  unreachable

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

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

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

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds %struct.block_q4_1, ptr %30, i64 %32
  %34 = getelementptr inbounds %struct.block_q4_1, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds %struct.anon, ptr %34, i32 0, i32 0
  %36 = load i16, ptr %35, align 4, !tbaa !13
  %37 = call float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext %36)
  store float %37, ptr %10, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i32, ptr %8, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds %struct.block_q4_1, ptr %38, i64 %40
  %42 = getelementptr inbounds %struct.block_q4_1, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %struct.anon, ptr %42, i32 0, i32 1
  %44 = load i16, ptr %43, align 2, !tbaa !13
  %45 = call float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext %44)
  store float %45, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %46

46:                                               ; preds = %99, %29
  %47 = load i32, ptr %12, align 4, !tbaa !11
  %48 = icmp slt i32 %47, 16
  br i1 %48, label %50, label %49

49:                                               ; preds = %46
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %102

50:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !11
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds %struct.block_q4_1, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct.block_q4_1, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %12, align 4, !tbaa !11
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [16 x i8], ptr %55, i64 0, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !13
  %60 = zext i8 %59 to i32
  %61 = and i32 %60, 15
  store i32 %61, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load i32, ptr %8, align 4, !tbaa !11
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds %struct.block_q4_1, ptr %62, i64 %64
  %66 = getelementptr inbounds %struct.block_q4_1, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %12, align 4, !tbaa !11
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [16 x i8], ptr %66, i64 0, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !13
  %71 = zext i8 %70 to i32
  %72 = ashr i32 %71, 4
  store i32 %72, ptr %14, align 4, !tbaa !11
  %73 = load i32, ptr %13, align 4, !tbaa !11
  %74 = sitofp i32 %73 to float
  %75 = load float, ptr %10, align 4, !tbaa !14
  %76 = load float, ptr %11, align 4, !tbaa !14
  %77 = call float @llvm.fmuladd.f32(float %74, float %75, float %76)
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load i32, ptr %8, align 4, !tbaa !11
  %80 = mul nsw i32 %79, 32
  %81 = load i32, ptr %12, align 4, !tbaa !11
  %82 = add nsw i32 %80, %81
  %83 = add nsw i32 %82, 0
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds float, ptr %78, i64 %84
  store float %77, ptr %85, align 4, !tbaa !14
  %86 = load i32, ptr %14, align 4, !tbaa !11
  %87 = sitofp i32 %86 to float
  %88 = load float, ptr %10, align 4, !tbaa !14
  %89 = load float, ptr %11, align 4, !tbaa !14
  %90 = call float @llvm.fmuladd.f32(float %87, float %88, float %89)
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = load i32, ptr %8, align 4, !tbaa !11
  %93 = mul nsw i32 %92, 32
  %94 = load i32, ptr %12, align 4, !tbaa !11
  %95 = add nsw i32 %93, %94
  %96 = add nsw i32 %95, 16
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds float, ptr %91, i64 %97
  store float %90, ptr %98, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  br label %99

99:                                               ; preds = %50
  %100 = load i32, ptr %12, align 4, !tbaa !11
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %12, align 4, !tbaa !11
  br label %46, !llvm.loop !16

102:                                              ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %8, align 4, !tbaa !11
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %8, align 4, !tbaa !11
  br label %24, !llvm.loop !18

106:                                              ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !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_q4_1 = type { %union.anon, [16 x i8] }
%union.anon = type { i32 }

@.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_1 = 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_q4_1(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 278, ptr noundef nonnull @__PRETTY_FUNCTION__.dequantize_row_q4_1) #4
  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_1, ptr %0, i64 %indvars.iv
  %12 = load i16, ptr %11, align 4, !tbaa !5
  %13 = tail call float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext %12)
  %14 = getelementptr inbounds i8, ptr %11, i64 2
  %15 = load i16, ptr %14, align 2, !tbaa !5
  %16 = tail call float @ggml_lookup_fp16_to_fp32(i16 noundef zeroext %15)
  %17 = getelementptr inbounds i8, ptr %11, i64 4
  %18 = shl i64 %indvars.iv, 5
  %19 = and i64 %18, 4294967264
  %20 = getelementptr inbounds float, ptr %1, i64 %19
  %21 = or disjoint i64 %19, 16
  %22 = getelementptr inbounds float, ptr %1, i64 %21
  %23 = load <4 x i8>, ptr %17, align 1, !tbaa !5
  %24 = and <4 x i8> %23, <i8 15, i8 15, i8 15, i8 15>
  %25 = uitofp nneg <4 x i8> %24 to <4 x float>
  %26 = insertelement <4 x float> poison, float %13, i64 0
  %27 = shufflevector <4 x float> %26, <4 x float> poison, <4 x i32> zeroinitializer
  %28 = insertelement <4 x float> poison, float %16, i64 0
  %29 = shufflevector <4 x float> %28, <4 x float> poison, <4 x i32> zeroinitializer
  %30 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %25, <4 x float> %27, <4 x float> %29)
  store <4 x float> %30, ptr %20, align 4, !tbaa !8
  %31 = lshr <4 x i8> %23, <i8 4, i8 4, i8 4, i8 4>
  %32 = uitofp nneg <4 x i8> %31 to <4 x float>
  %33 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %32, <4 x float> %27, <4 x float> %29)
  store <4 x float> %33, ptr %22, align 4, !tbaa !8
  %34 = getelementptr inbounds i8, ptr %11, i64 8
  %35 = or disjoint i64 %19, 4
  %36 = getelementptr inbounds float, ptr %1, i64 %35
  %37 = or disjoint i64 %19, 20
  %38 = getelementptr inbounds float, ptr %1, i64 %37
  %39 = load <4 x i8>, ptr %34, align 1, !tbaa !5
  %40 = and <4 x i8> %39, <i8 15, i8 15, i8 15, i8 15>
  %41 = uitofp nneg <4 x i8> %40 to <4 x float>
  %42 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %41, <4 x float> %27, <4 x float> %29)
  store <4 x float> %42, ptr %36, align 4, !tbaa !8
  %43 = lshr <4 x i8> %39, <i8 4, i8 4, i8 4, i8 4>
  %44 = uitofp nneg <4 x i8> %43 to <4 x float>
  %45 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %44, <4 x float> %27, <4 x float> %29)
  store <4 x float> %45, ptr %38, align 4, !tbaa !8
  %46 = getelementptr inbounds i8, ptr %11, i64 12
  %47 = or disjoint i64 %19, 8
  %48 = getelementptr inbounds float, ptr %1, i64 %47
  %49 = or disjoint i64 %19, 24
  %50 = getelementptr inbounds float, ptr %1, i64 %49
  %51 = load <4 x i8>, ptr %46, align 1, !tbaa !5
  %52 = and <4 x i8> %51, <i8 15, i8 15, i8 15, i8 15>
  %53 = uitofp nneg <4 x i8> %52 to <4 x float>
  %54 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %53, <4 x float> %27, <4 x float> %29)
  store <4 x float> %54, ptr %48, align 4, !tbaa !8
  %55 = lshr <4 x i8> %51, <i8 4, i8 4, i8 4, i8 4>
  %56 = uitofp nneg <4 x i8> %55 to <4 x float>
  %57 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %56, <4 x float> %27, <4 x float> %29)
  store <4 x float> %57, ptr %50, align 4, !tbaa !8
  %58 = getelementptr inbounds i8, ptr %11, i64 16
  %59 = or disjoint i64 %19, 12
  %60 = getelementptr inbounds float, ptr %1, i64 %59
  %61 = or disjoint i64 %19, 28
  %62 = getelementptr inbounds float, ptr %1, i64 %61
  %63 = load <4 x i8>, ptr %58, align 1, !tbaa !5
  %64 = and <4 x i8> %63, <i8 15, i8 15, i8 15, i8 15>
  %65 = uitofp nneg <4 x i8> %64 to <4 x float>
  %66 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %65, <4 x float> %27, <4 x float> %29)
  store <4 x float> %66, ptr %60, align 4, !tbaa !8
  %67 = lshr <4 x i8> %63, <i8 4, i8 4, i8 4, i8 4>
  %68 = uitofp nneg <4 x i8> %67 to <4 x float>
  %69 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %68, <4 x float> %27, <4 x float> %29)
  store <4 x float> %69, ptr %62, align 4, !tbaa !8
  %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 !10
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.fmuladd.v4f32(<4 x float>, <4 x float>, <4 x float>) #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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, !9, i64 0}
!9 = !{!"float", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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