; LLVM IR from ggml-org/ggml :: src (ggml)

; 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.ggml_custom_op_params = type { ptr, i32, ptr }
%struct.ggml_tensor = type { i32, ptr, [4 x i64], [4 x i64], i32, [16 x i32], i32, [10 x ptr], ptr, i64, ptr, [64 x i8], ptr, [8 x i8] }

@.str.12 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.152 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
declare dso_local void @ggml_abort(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
declare dso_local ptr @ggml_new_tensor_4d(ptr noundef, i32 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @ggml_set_op_params(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @ggml_custom_4d(ptr noundef %0, i32 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, ptr noundef %6, i32 noundef %7, ptr noundef %8, i32 noundef %9, ptr noundef %10) #2 {
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  %20 = alloca ptr, align 8
  %21 = alloca i32, align 4
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca %struct.ggml_custom_op_params, align 8
  %25 = alloca i32, align 4
  store ptr %0, ptr %12, align 8, !tbaa !5
  store i32 %1, ptr %13, align 4, !tbaa !9
  store i64 %2, ptr %14, align 8, !tbaa !11
  store i64 %3, ptr %15, align 8, !tbaa !11
  store i64 %4, ptr %16, align 8, !tbaa !11
  store i64 %5, ptr %17, align 8, !tbaa !11
  store ptr %6, ptr %18, align 8, !tbaa !5
  store i32 %7, ptr %19, align 4, !tbaa !9
  store ptr %8, ptr %20, align 8, !tbaa !5
  store i32 %9, ptr %21, align 4, !tbaa !9
  store ptr %10, ptr %22, align 8, !tbaa !5
  %26 = load i32, ptr %19, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 10
  br i1 %27, label %29, label %28

28:                                               ; preds = %11
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.12, i32 noundef 5005, ptr noundef @.str.13, ptr noundef @.str.152) #3
  unreachable

29:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #4
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = load i32, ptr %13, align 4, !tbaa !9
  %32 = load i64, ptr %14, align 8, !tbaa !11
  %33 = load i64, ptr %15, align 8, !tbaa !11
  %34 = load i64, ptr %16, align 8, !tbaa !11
  %35 = load i64, ptr %17, align 8, !tbaa !11
  %36 = call ptr @ggml_new_tensor_4d(ptr noundef %30, i32 noundef %31, i64 noundef %32, i64 noundef %33, i64 noundef %34, i64 noundef %35)
  store ptr %36, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %24) #4
  %37 = getelementptr inbounds %struct.ggml_custom_op_params, ptr %24, i32 0, i32 0
  %38 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %38, ptr %37, align 8, !tbaa !13
  %39 = getelementptr inbounds %struct.ggml_custom_op_params, ptr %24, i32 0, i32 1
  %40 = load i32, ptr %21, align 4, !tbaa !9
  store i32 %40, ptr %39, align 8, !tbaa !15
  %41 = getelementptr inbounds %struct.ggml_custom_op_params, ptr %24, i32 0, i32 2
  %42 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %42, ptr %41, align 8, !tbaa !16
  %43 = load ptr, ptr %23, align 8, !tbaa !5
  call void @ggml_set_op_params(ptr noundef %43, ptr noundef %24, i64 noundef 24)
  %44 = load ptr, ptr %23, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ggml_tensor, ptr %44, i32 0, i32 4
  store i32 78, ptr %45, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #4
  store i32 0, ptr %25, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %62, %29
  %47 = load i32, ptr %25, align 4, !tbaa !9
  %48 = load i32, ptr %19, align 4, !tbaa !9
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #4
  br label %65

51:                                               ; preds = %46
  %52 = load ptr, ptr %18, align 8, !tbaa !5
  %53 = load i32, ptr %25, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds ptr, ptr %52, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = load ptr, ptr %23, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ggml_tensor, ptr %57, i32 0, i32 7
  %59 = load i32, ptr %25, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [10 x ptr], ptr %58, i64 0, i64 %60
  store ptr %56, ptr %61, align 8, !tbaa !5
  br label %62

62:                                               ; preds = %51
  %63 = load i32, ptr %25, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %25, align 4, !tbaa !9
  br label %46, !llvm.loop !19

65:                                               ; preds = %50
  %66 = load ptr, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 24, ptr %24) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #4
  ret ptr %66
}

attributes #0 = { noreturn 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 #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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"ggml_custom_op_params", !6, i64 0, !10, i64 8, !6, i64 16}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !6, i64 16}
!17 = !{!18, !10, i64 80}
!18 = !{!"ggml_tensor", !10, i64 0, !6, i64 8, !7, i64 16, !7, i64 48, !10, i64 80, !7, i64 84, !10, i64 148, !7, i64 152, !6, i64 232, !12, i64 240, !6, i64 248, !7, i64 256, !6, i64 320, !7, i64 328}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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.ggml_custom_op_params = type { ptr, i32, ptr }

@.str.12 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.152 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
declare dso_local void @ggml_abort(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @ggml_new_tensor_4d(ptr noundef, i32 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @ggml_set_op_params(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @ggml_custom_4d(ptr noundef %0, i32 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, ptr nocapture noundef readonly %6, i32 noundef %7, ptr noundef %8, i32 noundef %9, ptr noundef %10) local_unnamed_addr #2 {
  %12 = alloca %struct.ggml_custom_op_params, align 8
  %13 = icmp slt i32 %7, 10
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.12, i32 noundef 5005, ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.152) #3
  unreachable

15:                                               ; preds = %11
  %16 = tail call ptr @ggml_new_tensor_4d(ptr noundef %0, i32 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %12) #4
  store ptr %8, ptr %12, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %12, i64 8
  store i32 %9, ptr %17, align 8, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %12, i64 16
  store ptr %10, ptr %18, align 8, !tbaa !12
  call void @ggml_set_op_params(ptr noundef %16, ptr noundef nonnull %12, i64 noundef 24)
  %19 = getelementptr inbounds i8, ptr %16, i64 80
  store i32 78, ptr %19, align 8, !tbaa !13
  %20 = icmp sgt i32 %7, 0
  br i1 %20, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %15
  %21 = getelementptr inbounds i8, ptr %16, i64 152
  %wide.trip.count = zext nneg i32 %7 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %22 = icmp ult i32 %7, 4
  br i1 %22, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %26

._crit_edge.loopexit.unr-lcssa:                   ; preds = %26, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %26 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %23 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv.epil
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = getelementptr inbounds [10 x ptr], ptr %21, i64 0, i64 %indvars.iv.epil
  store ptr %24, ptr %25, align 8, !tbaa !16
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !17

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %15
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %12) #4
  ret ptr %16

26:                                               ; preds = %26, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %26 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %26 ]
  %27 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv
  %28 = load ptr, ptr %27, align 8, !tbaa !16
  %29 = getelementptr inbounds [10 x ptr], ptr %21, i64 0, i64 %indvars.iv
  store ptr %28, ptr %29, align 8, !tbaa !16
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %30 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv.next
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = getelementptr inbounds [10 x ptr], ptr %21, i64 0, i64 %indvars.iv.next
  store ptr %31, ptr %32, align 8, !tbaa !16
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %33 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv.next.1
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = getelementptr inbounds [10 x ptr], ptr %21, i64 0, i64 %indvars.iv.next.1
  store ptr %34, ptr %35, align 8, !tbaa !16
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %36 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv.next.2
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = getelementptr inbounds [10 x ptr], ptr %21, i64 0, i64 %indvars.iv.next.2
  store ptr %37, ptr %38, align 8, !tbaa !16
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %26, !llvm.loop !19
}

attributes #0 = { noreturn 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 #1 = { mustprogress 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 = { 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, !7, i64 0}
!6 = !{!"ggml_custom_op_params", !7, i64 0, !10, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !7, i64 16}
!13 = !{!14, !10, i64 80}
!14 = !{!"ggml_tensor", !10, i64 0, !7, i64 8, !8, i64 16, !8, i64 48, !10, i64 80, !8, i64 84, !10, i64 148, !8, i64 152, !7, i64 232, !15, i64 240, !7, i64 248, !8, i64 256, !7, i64 320, !8, i64 328}
!15 = !{!"long", !8, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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