; 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_nl = type { i16, [16 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.10 = external hidden unnamed_addr constant [22 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
define dso_local i64 @quantize_iq4_nl(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 [32 x i8], align 16
  %14 = alloca [32 x float], align 16
  %15 = alloca i16, align 2
  %16 = alloca ptr, align 8
  %17 = alloca float, align 4
  %18 = alloca i64, align 8
  %19 = alloca i32, align 4
  %20 = alloca ptr, align 8
  %21 = alloca i32, align 4
  %22 = 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
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = srem i64 %23, 32
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %5
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.1, i32 noundef 4685, ptr noundef @.str.6, ptr noundef @.str.10) #3
  unreachable

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

31:                                               ; preds = %87, %27
  %32 = load i64, ptr %18, align 8, !tbaa !9
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = icmp slt i64 %32, %33
  br i1 %34, label %36, label %35

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

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %37, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  store i32 0, ptr %21, align 4, !tbaa !11
  br label %38

38:                                               ; preds = %76, %36
  %39 = load i32, ptr %21, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = load i64, ptr %11, align 8, !tbaa !9
  %42 = icmp slt i64 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %38
  store i32 5, ptr %19, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  br label %79

44:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #4
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %53

47:                                               ; preds = %44
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = load i32, ptr %21, align 4, !tbaa !11
  %50 = mul nsw i32 32, %49
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds float, ptr %48, i64 %51
  br label %54

53:                                               ; preds = %44
  br label %54

54:                                               ; preds = %53, %47
  %55 = phi ptr [ %52, %47 ], [ null, %53 ]
  store ptr %55, ptr %22, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %21, align 4, !tbaa !11
  %58 = mul nsw i32 32, %57
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds float, ptr %56, i64 %59
  %61 = load ptr, ptr %20, align 8, !tbaa !5
  %62 = load i32, ptr %21, align 4, !tbaa !11
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds %struct.block_iq4_nl, ptr %61, i64 %63
  %65 = getelementptr inbounds %struct.block_iq4_nl, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %20, align 8, !tbaa !5
  %67 = load i32, ptr %21, align 4, !tbaa !11
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds %struct.block_iq4_nl, ptr %66, i64 %68
  %70 = getelementptr inbounds %struct.block_iq4_nl, ptr %69, i32 0, i32 1
  %71 = getelementptr inbounds [16 x i8], ptr %70, i64 0, i64 0
  %72 = load ptr, ptr %16, align 8, !tbaa !5
  %73 = getelementptr inbounds [32 x float], ptr %14, i64 0, i64 0
  %74 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  %75 = load ptr, ptr %22, align 8, !tbaa !5
  call void @quantize_row_iq4_nl_impl(i32 noundef 32, i32 noundef 32, ptr noundef %60, ptr noundef %65, ptr noundef %71, ptr noundef %15, ptr noundef %72, ptr noundef %17, ptr noundef %73, ptr noundef %74, ptr noundef @kvalues_iq4nl, ptr noundef %75, i32 noundef 7)
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #4
  br label %76

76:                                               ; preds = %54
  %77 = load i32, ptr %21, align 4, !tbaa !11
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %21, align 4, !tbaa !11
  br label %38, !llvm.loop !13

79:                                               ; preds = %43
  %80 = load i64, ptr %9, align 8, !tbaa !9
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds float, ptr %81, i64 %80
  store ptr %82, ptr %6, align 8, !tbaa !5
  %83 = load i64, ptr %11, align 8, !tbaa !9
  %84 = mul i64 %83, 18
  %85 = load ptr, ptr %12, align 8, !tbaa !5
  %86 = getelementptr inbounds i8, ptr %85, i64 %84
  store ptr %86, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  br label %87

87:                                               ; preds = %79
  %88 = load i64, ptr %18, align 8, !tbaa !9
  %89 = add nsw i64 %88, 1
  store i64 %89, ptr %18, align 8, !tbaa !9
  br label %31, !llvm.loop !15

90:                                               ; preds = %35
  %91 = load i64, ptr %8, align 8, !tbaa !9
  %92 = load i64, ptr %11, align 8, !tbaa !9
  %93 = mul nsw i64 %91, %92
  %94 = mul i64 %93, 18
  store i32 1, ptr %19, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 32, 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 %94
}

; 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

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_nl = type { i16, [16 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.10 = external hidden unnamed_addr constant [22 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
define dso_local i64 @quantize_iq4_nl(ptr noalias noundef %0, ptr noalias noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = alloca [32 x i8], align 16
  %7 = alloca [32 x float], align 16
  %8 = alloca i16, align 2
  %9 = alloca float, align 4
  %10 = and i64 %3, 31
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %13, label %12

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

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

.preheader.lr.ph:                                 ; preds = %13
  %16 = icmp sgt i64 %14, 0
  %17 = mul nsw i64 %14, 18
  br i1 %16, label %.preheader.lr.ph.split.us, label %._crit_edge38

.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
  %.036.us.us = phi ptr [ %22, %._crit_edge.split.us.us.us ], [ %0, %.preheader.lr.ph.split.us ]
  %.02734.us.us = phi ptr [ %23, %._crit_edge.split.us.us.us ], [ %1, %.preheader.lr.ph.split.us ]
  %.02833.us.us = phi i64 [ %24, %._crit_edge.split.us.us.us ], [ 0, %.preheader.lr.ph.split.us ]
  br label %18

18:                                               ; preds = %18, %.preheader.us.us
  %indvars.iv46 = phi i64 [ %indvars.iv.next47, %18 ], [ 0, %.preheader.us.us ]
  %.idx = shl nsw i64 %indvars.iv46, 7
  %19 = getelementptr inbounds i8, ptr %.036.us.us, i64 %.idx
  %20 = getelementptr inbounds %struct.block_iq4_nl, ptr %.02734.us.us, i64 %indvars.iv46
  %21 = getelementptr inbounds i8, ptr %20, i64 2
  call void @quantize_row_iq4_nl_impl(i32 noundef 32, i32 noundef 32, ptr noundef %19, ptr noundef %20, ptr noundef nonnull %21, ptr noundef nonnull %8, ptr noundef null, ptr noundef nonnull %9, ptr noundef nonnull %7, ptr noundef nonnull %6, ptr noundef nonnull @kvalues_iq4nl, ptr noundef null, i32 noundef 7)
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %exitcond49.not = icmp eq i64 %indvars.iv.next47, %14
  br i1 %exitcond49.not, label %._crit_edge.split.us.us.us, label %18, !llvm.loop !5

._crit_edge.split.us.us.us:                       ; preds = %18
  %22 = getelementptr inbounds float, ptr %.036.us.us, i64 %3
  %23 = getelementptr inbounds i8, ptr %.02734.us.us, i64 %17
  %24 = add nuw nsw i64 %.02833.us.us, 1
  %exitcond50.not = icmp eq i64 %24, %2
  br i1 %exitcond50.not, label %._crit_edge38, label %.preheader.us.us, !llvm.loop !7

.preheader.us:                                    ; preds = %.preheader.lr.ph.split.us, %._crit_edge.split.us40
  %.036.us = phi ptr [ %31, %._crit_edge.split.us40 ], [ %0, %.preheader.lr.ph.split.us ]
  %.02734.us = phi ptr [ %32, %._crit_edge.split.us40 ], [ %1, %.preheader.lr.ph.split.us ]
  %.02833.us = phi i64 [ %33, %._crit_edge.split.us40 ], [ 0, %.preheader.lr.ph.split.us ]
  br label %25

25:                                               ; preds = %.preheader.us, %25
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %25 ]
  %26 = shl nsw i64 %indvars.iv, 5
  %27 = getelementptr inbounds float, ptr %4, i64 %26
  %28 = getelementptr inbounds float, ptr %.036.us, i64 %26
  %29 = getelementptr inbounds %struct.block_iq4_nl, ptr %.02734.us, i64 %indvars.iv
  %30 = getelementptr inbounds i8, ptr %29, i64 2
  call void @quantize_row_iq4_nl_impl(i32 noundef 32, i32 noundef 32, ptr noundef %28, ptr noundef %29, ptr noundef nonnull %30, ptr noundef nonnull %8, ptr noundef null, ptr noundef nonnull %9, ptr noundef nonnull %7, ptr noundef nonnull %6, ptr noundef nonnull @kvalues_iq4nl, ptr noundef nonnull %27, i32 noundef 7)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %14
  br i1 %exitcond.not, label %._crit_edge.split.us40, label %25, !llvm.loop !5

._crit_edge.split.us40:                           ; preds = %25
  %31 = getelementptr inbounds float, ptr %.036.us, i64 %3
  %32 = getelementptr inbounds i8, ptr %.02734.us, i64 %17
  %33 = add nuw nsw i64 %.02833.us, 1
  %exitcond45.not = icmp eq i64 %33, %2
  br i1 %exitcond45.not, label %._crit_edge38, label %.preheader.us, !llvm.loop !7

._crit_edge38:                                    ; preds = %._crit_edge.split.us40, %._crit_edge.split.us.us.us, %.preheader.lr.ph, %13
  %34 = mul i64 %2, 18
  %35 = mul i64 %34, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #4
  ret i64 %35
}

; 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

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