; 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_iq4_xs = type { i16, i16, [4 x i8], [128 x i8] }

@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@kvalues_iq4nl = external hidden constant [16 x i8], align 16
@.str.6 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: noreturn
declare void @ggml_abort(ptr noundef, i32 noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare hidden void @quantize_row_iq4_nl_impl(i32 noundef, i32 noundef, ptr noalias noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @quantize_iq4_xs(ptr noalias noundef %0, ptr noalias noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca [256 x i8], align 16
  %14 = alloca [32 x float], align 16
  %15 = alloca [8 x float], align 16
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  %20 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = srem i64 %21, 256
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %25, label %24

24:                                               ; preds = %5
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.1, i32 noundef 4723, ptr noundef @.str.6, ptr noundef @.str.8) #3
  unreachable

25:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %26 = load i64, ptr %9, align 8, !tbaa !9
  %27 = sdiv i64 %26, 256
  store i64 %27, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %28, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 256, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 128, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %96, %25
  %30 = load i64, ptr %16, align 8, !tbaa !9
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = icmp slt i64 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 2, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %99

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %35, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  store i32 0, ptr %19, align 4, !tbaa !11
  br label %36

36:                                               ; preds = %85, %34
  %37 = load i32, ptr %19, align 4, !tbaa !11
  %38 = sext i32 %37 to i64
  %39 = load i64, ptr %11, align 8, !tbaa !9
  %40 = icmp slt i64 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %36
  store i32 5, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  br label %88

42:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %51

45:                                               ; preds = %42
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = load i32, ptr %19, align 4, !tbaa !11
  %48 = mul nsw i32 256, %47
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds float, ptr %46, i64 %49
  br label %52

51:                                               ; preds = %42
  br label %52

52:                                               ; preds = %51, %45
  %53 = phi ptr [ %50, %45 ], [ null, %51 ]
  store ptr %53, ptr %20, align 8, !tbaa !5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i32, ptr %19, align 4, !tbaa !11
  %56 = mul nsw i32 256, %55
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds float, ptr %54, i64 %57
  %59 = load ptr, ptr %18, align 8, !tbaa !5
  %60 = load i32, ptr %19, align 4, !tbaa !11
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.block_iq4_xs, ptr %59, i64 %61
  %63 = getelementptr inbounds %struct.block_iq4_xs, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %18, align 8, !tbaa !5
  %65 = load i32, ptr %19, align 4, !tbaa !11
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds %struct.block_iq4_xs, ptr %64, i64 %66
  %68 = getelementptr inbounds %struct.block_iq4_xs, ptr %67, i32 0, i32 3
  %69 = getelementptr inbounds [128 x i8], ptr %68, i64 0, i64 0
  %70 = load ptr, ptr %18, align 8, !tbaa !5
  %71 = load i32, ptr %19, align 4, !tbaa !11
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds %struct.block_iq4_xs, ptr %70, i64 %72
  %74 = getelementptr inbounds %struct.block_iq4_xs, ptr %73, i32 0, i32 1
  %75 = load ptr, ptr %18, align 8, !tbaa !5
  %76 = load i32, ptr %19, align 4, !tbaa !11
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds %struct.block_iq4_xs, ptr %75, i64 %77
  %79 = getelementptr inbounds %struct.block_iq4_xs, ptr %78, i32 0, i32 2
  %80 = getelementptr inbounds [4 x i8], ptr %79, i64 0, i64 0
  %81 = getelementptr inbounds [8 x float], ptr %15, i64 0, i64 0
  %82 = getelementptr inbounds [32 x float], ptr %14, i64 0, i64 0
  %83 = getelementptr inbounds [256 x i8], ptr %13, i64 0, i64 0
  %84 = load ptr, ptr %20, align 8, !tbaa !5
  call void @quantize_row_iq4_nl_impl(i32 noundef 256, i32 noundef 32, ptr noundef %58, ptr noundef %63, ptr noundef %69, ptr noundef %74, ptr noundef %80, ptr noundef %81, ptr noundef %82, ptr noundef %83, ptr noundef @kvalues_iq4nl, ptr noundef %84, i32 noundef 7)
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  br label %85

85:                                               ; preds = %52
  %86 = load i32, ptr %19, align 4, !tbaa !11
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %19, align 4, !tbaa !11
  br label %36, !llvm.loop !13

88:                                               ; preds = %41
  %89 = load i64, ptr %9, align 8, !tbaa !9
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds float, ptr %90, i64 %89
  store ptr %91, ptr %6, align 8, !tbaa !5
  %92 = load i64, ptr %11, align 8, !tbaa !9
  %93 = mul i64 %92, 136
  %94 = load ptr, ptr %12, align 8, !tbaa !5
  %95 = getelementptr inbounds i8, ptr %94, i64 %93
  store ptr %95, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %96

96:                                               ; preds = %88
  %97 = load i64, ptr %16, align 8, !tbaa !9
  %98 = add nsw i64 %97, 1
  store i64 %98, ptr %16, align 8, !tbaa !9
  br label %29, !llvm.loop !15

99:                                               ; preds = %33
  %100 = load i64, ptr %8, align 8, !tbaa !9
  %101 = load i64, ptr %11, align 8, !tbaa !9
  %102 = mul nsw i64 %100, %101
  %103 = mul i64 %102, 136
  store i32 1, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 32, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 256, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  ret i64 %103
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn "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 }
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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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_iq4_xs = type { i16, i16, [4 x i8], [128 x i8] }

@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@kvalues_iq4nl = external hidden constant [16 x i8], align 16
@.str.6 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: noreturn
declare void @ggml_abort(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @quantize_row_iq4_nl_impl(i32 noundef, i32 noundef, ptr noalias noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i64 @quantize_iq4_xs(ptr noalias noundef %0, ptr noalias noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = alloca [256 x i8], align 16
  %7 = alloca [32 x float], align 16
  %8 = alloca [8 x float], align 16
  %9 = and i64 %3, 255
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %12, label %11

11:                                               ; preds = %5
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.1, i32 noundef 4723, ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.8) #3
  unreachable

12:                                               ; preds = %5
  %13 = ashr exact i64 %3, 8
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %8) #4
  %14 = icmp sgt i64 %2, 0
  br i1 %14, label %.preheader.lr.ph, label %._crit_edge41

.preheader.lr.ph:                                 ; preds = %12
  %15 = icmp sgt i64 %13, 0
  %16 = mul nsw i64 %13, 136
  br i1 %15, label %.preheader.lr.ph.split.us, label %._crit_edge41

.preheader.lr.ph.split.us:                        ; preds = %.preheader.lr.ph
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %.preheader.us.us, label %.preheader.us

.preheader.us.us:                                 ; preds = %.preheader.lr.ph.split.us, %._crit_edge.split.us.us.us
  %.039.us.us = phi ptr [ %23, %._crit_edge.split.us.us.us ], [ %0, %.preheader.lr.ph.split.us ]
  %.03037.us.us = phi ptr [ %24, %._crit_edge.split.us.us.us ], [ %1, %.preheader.lr.ph.split.us ]
  %.03136.us.us = phi i64 [ %25, %._crit_edge.split.us.us.us ], [ 0, %.preheader.lr.ph.split.us ]
  br label %17

17:                                               ; preds = %17, %.preheader.us.us
  %indvars.iv49 = phi i64 [ %indvars.iv.next50, %17 ], [ 0, %.preheader.us.us ]
  %.idx = shl nsw i64 %indvars.iv49, 10
  %18 = getelementptr inbounds i8, ptr %.039.us.us, i64 %.idx
  %19 = getelementptr inbounds %struct.block_iq4_xs, ptr %.03037.us.us, i64 %indvars.iv49
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = getelementptr inbounds i8, ptr %19, i64 2
  %22 = getelementptr inbounds i8, ptr %19, i64 4
  call void @quantize_row_iq4_nl_impl(i32 noundef 256, i32 noundef 32, ptr noundef %18, ptr noundef %19, ptr noundef nonnull %20, ptr noundef nonnull %21, ptr noundef nonnull %22, ptr noundef nonnull %8, ptr noundef nonnull %7, ptr noundef nonnull %6, ptr noundef nonnull @kvalues_iq4nl, ptr noundef null, i32 noundef 7)
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %exitcond52.not = icmp eq i64 %indvars.iv.next50, %13
  br i1 %exitcond52.not, label %._crit_edge.split.us.us.us, label %17, !llvm.loop !5

._crit_edge.split.us.us.us:                       ; preds = %17
  %23 = getelementptr inbounds float, ptr %.039.us.us, i64 %3
  %24 = getelementptr inbounds i8, ptr %.03037.us.us, i64 %16
  %25 = add nuw nsw i64 %.03136.us.us, 1
  %exitcond53.not = icmp eq i64 %25, %2
  br i1 %exitcond53.not, label %._crit_edge41, label %.preheader.us.us, !llvm.loop !7

.preheader.us:                                    ; preds = %.preheader.lr.ph.split.us, %._crit_edge.split.us43
  %.039.us = phi ptr [ %34, %._crit_edge.split.us43 ], [ %0, %.preheader.lr.ph.split.us ]
  %.03037.us = phi ptr [ %35, %._crit_edge.split.us43 ], [ %1, %.preheader.lr.ph.split.us ]
  %.03136.us = phi i64 [ %36, %._crit_edge.split.us43 ], [ 0, %.preheader.lr.ph.split.us ]
  br label %26

26:                                               ; preds = %.preheader.us, %26
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %26 ]
  %27 = shl nsw i64 %indvars.iv, 8
  %28 = getelementptr inbounds float, ptr %4, i64 %27
  %29 = getelementptr inbounds float, ptr %.039.us, i64 %27
  %30 = getelementptr inbounds %struct.block_iq4_xs, ptr %.03037.us, i64 %indvars.iv
  %31 = getelementptr inbounds i8, ptr %30, i64 8
  %32 = getelementptr inbounds i8, ptr %30, i64 2
  %33 = getelementptr inbounds i8, ptr %30, i64 4
  call void @quantize_row_iq4_nl_impl(i32 noundef 256, i32 noundef 32, ptr noundef %29, ptr noundef %30, ptr noundef nonnull %31, ptr noundef nonnull %32, ptr noundef nonnull %33, ptr noundef nonnull %8, ptr noundef nonnull %7, ptr noundef nonnull %6, ptr noundef nonnull @kvalues_iq4nl, ptr noundef nonnull %28, i32 noundef 7)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %13
  br i1 %exitcond.not, label %._crit_edge.split.us43, label %26, !llvm.loop !5

._crit_edge.split.us43:                           ; preds = %26
  %34 = getelementptr inbounds float, ptr %.039.us, i64 %3
  %35 = getelementptr inbounds i8, ptr %.03037.us, i64 %16
  %36 = add nuw nsw i64 %.03136.us, 1
  %exitcond48.not = icmp eq i64 %36, %2
  br i1 %exitcond48.not, label %._crit_edge41, label %.preheader.us, !llvm.loop !7

._crit_edge41:                                    ; preds = %._crit_edge.split.us43, %._crit_edge.split.us.us.us, %.preheader.lr.ph, %12
  %37 = mul i64 %2, 136
  %38 = mul i64 %37, %13
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %6) #4
  ret i64 %38
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn "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 }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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