; 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_init_params = type { i64, ptr, i8 }
%union.anon = type { i16 }
%struct.ggml_context = type { i64, ptr, i8, i8, i32, ptr, 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
@ggml_init.is_first_call = external hidden global i8, align 1
@ggml_table_f32_f16 = external dso_local global [65536 x float], align 16
@.str.21 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [52 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_aligned_malloc(i64 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare dso_local void @ggml_time_init() #2

; Function Attrs: nounwind uwtable
define dso_local ptr @ggml_init(ptr noundef byval(%struct.ggml_init_params) align 8 %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca %union.anon, align 2
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca %struct.ggml_context, align 8
  call void @ggml_critical_section_start()
  %7 = load i8, ptr @ggml_init.is_first_call, align 1, !tbaa !5, !range !9, !noundef !10
  %8 = trunc i8 %7 to i1
  br i1 %8, label %9, label %26

9:                                                ; preds = %1
  call void @ggml_time_init()
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %22, %9
  %11 = load i32, ptr %2, align 4, !tbaa !11
  %12 = icmp slt i32 %11, 65536
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %25

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #6
  %15 = load i32, ptr %2, align 4, !tbaa !11
  %16 = trunc i32 %15 to i16
  store i16 %16, ptr %3, align 2, !tbaa !13
  %17 = load i16, ptr %3, align 2, !tbaa !13
  %18 = call float @ggml_compute_fp16_to_fp32(i16 noundef zeroext %17)
  %19 = load i32, ptr %2, align 4, !tbaa !11
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [65536 x float], ptr @ggml_table_f32_f16, i64 0, i64 %20
  store float %18, ptr %21, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #6
  br label %22

22:                                               ; preds = %14
  %23 = load i32, ptr %2, align 4, !tbaa !11
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !11
  br label %10, !llvm.loop !16

25:                                               ; preds = %13
  store i8 0, ptr @ggml_init.is_first_call, align 1, !tbaa !5
  br label %26

26:                                               ; preds = %25, %1
  call void @ggml_critical_section_end()
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %27 = call ptr @ggml_malloc(i64 noundef 40)
  store ptr %27, ptr %4, align 8, !tbaa !18
  %28 = getelementptr inbounds %struct.ggml_init_params, ptr %0, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !20
  %30 = icmp eq i64 %29, 0
  br i1 %30, label %31, label %33

31:                                               ; preds = %26
  %32 = getelementptr inbounds %struct.ggml_init_params, ptr %0, i32 0, i32 0
  store i64 16, ptr %32, align 8, !tbaa !20
  br label %33

33:                                               ; preds = %31, %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %34 = getelementptr inbounds %struct.ggml_init_params, ptr %0, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !23
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %40

37:                                               ; preds = %33
  %38 = getelementptr inbounds %struct.ggml_init_params, ptr %0, i32 0, i32 0
  %39 = load i64, ptr %38, align 8, !tbaa !20
  br label %46

40:                                               ; preds = %33
  %41 = getelementptr inbounds %struct.ggml_init_params, ptr %0, i32 0, i32 0
  %42 = load i64, ptr %41, align 8, !tbaa !20
  %43 = add i64 %42, 16
  %44 = sub i64 %43, 1
  %45 = and i64 %44, -16
  br label %46

46:                                               ; preds = %40, %37
  %47 = phi i64 [ %39, %37 ], [ %45, %40 ]
  store i64 %47, ptr %5, align 8, !tbaa !24
  %48 = load ptr, ptr %4, align 8, !tbaa !18
  %49 = getelementptr inbounds %struct.ggml_context, ptr %6, i32 0, i32 0
  %50 = load i64, ptr %5, align 8, !tbaa !24
  store i64 %50, ptr %49, align 8, !tbaa !25
  %51 = getelementptr inbounds %struct.ggml_context, ptr %6, i32 0, i32 1
  %52 = getelementptr inbounds %struct.ggml_init_params, ptr %0, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !23
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %58

55:                                               ; preds = %46
  %56 = getelementptr inbounds %struct.ggml_init_params, ptr %0, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !23
  br label %61

58:                                               ; preds = %46
  %59 = load i64, ptr %5, align 8, !tbaa !24
  %60 = call ptr @ggml_aligned_malloc(i64 noundef %59)
  br label %61

61:                                               ; preds = %58, %55
  %62 = phi ptr [ %57, %55 ], [ %60, %58 ]
  store ptr %62, ptr %51, align 8, !tbaa !27
  %63 = getelementptr inbounds %struct.ggml_context, ptr %6, i32 0, i32 2
  %64 = getelementptr inbounds %struct.ggml_init_params, ptr %0, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !23
  %66 = icmp ne ptr %65, null
  %67 = zext i1 %66 to i64
  %68 = select i1 %66, i32 0, i32 1
  %69 = icmp ne i32 %68, 0
  %70 = zext i1 %69 to i8
  store i8 %70, ptr %63, align 8, !tbaa !28
  %71 = getelementptr inbounds %struct.ggml_context, ptr %6, i32 0, i32 3
  %72 = getelementptr inbounds %struct.ggml_init_params, ptr %0, i32 0, i32 2
  %73 = load i8, ptr %72, align 8, !tbaa !29, !range !9, !noundef !10
  %74 = trunc i8 %73 to i1
  %75 = zext i1 %74 to i8
  store i8 %75, ptr %71, align 1, !tbaa !30
  %76 = getelementptr inbounds %struct.ggml_context, ptr %6, i32 0, i32 4
  store i32 0, ptr %76, align 4, !tbaa !31
  %77 = getelementptr inbounds %struct.ggml_context, ptr %6, i32 0, i32 5
  store ptr null, ptr %77, align 8, !tbaa !32
  %78 = getelementptr inbounds %struct.ggml_context, ptr %6, i32 0, i32 6
  store ptr null, ptr %78, align 8, !tbaa !33
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %48, ptr align 8 %6, i64 40, i1 false), !tbaa.struct !34
  %79 = load ptr, ptr %4, align 8, !tbaa !18
  %80 = getelementptr inbounds %struct.ggml_context, ptr %79, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8, !tbaa !27
  %82 = icmp ne ptr %81, null
  br i1 %82, label %84, label %83

83:                                               ; preds = %61
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.12, i32 noundef 1418, ptr noundef @.str.13, ptr noundef @.str.21) #7
  unreachable

84:                                               ; preds = %61
  %85 = load ptr, ptr %4, align 8, !tbaa !18
  %86 = getelementptr inbounds %struct.ggml_context, ptr %85, i32 0, i32 1
  %87 = load ptr, ptr %86, align 8, !tbaa !27
  %88 = ptrtoint ptr %87 to i64
  %89 = urem i64 %88, 16
  %90 = icmp eq i64 %89, 0
  br i1 %90, label %92, label %91

91:                                               ; preds = %84
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.12, i32 noundef 1420, ptr noundef @.str.13, ptr noundef @.str.22) #7
  unreachable

92:                                               ; preds = %84
  %93 = load ptr, ptr %4, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  ret ptr %93
}

declare void @ggml_critical_section_start() #4

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

declare void @ggml_critical_section_end() #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ggml_malloc(i64 noundef) #5

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { 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 #6 = { nounwind }
attributes #7 = { noreturn }

!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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!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 = !{!19, !19, i64 0}
!19 = !{!"any pointer", !7, i64 0}
!20 = !{!21, !22, i64 0}
!21 = !{!"ggml_init_params", !22, i64 0, !19, i64 8, !6, i64 16}
!22 = !{!"long", !7, i64 0}
!23 = !{!21, !19, i64 8}
!24 = !{!22, !22, i64 0}
!25 = !{!26, !22, i64 0}
!26 = !{!"ggml_context", !22, i64 0, !19, i64 8, !6, i64 16, !6, i64 17, !12, i64 20, !19, i64 24, !19, i64 32}
!27 = !{!26, !19, i64 8}
!28 = !{!26, !6, i64 16}
!29 = !{!21, !6, i64 16}
!30 = !{!26, !6, i64 17}
!31 = !{!26, !12, i64 20}
!32 = !{!26, !19, i64 24}
!33 = !{!26, !19, i64 32}
!34 = !{i64 0, i64 8, !24, i64 8, i64 8, !18, i64 16, i64 1, !5, i64 17, i64 1, !5, i64 20, i64 4, !11, i64 24, i64 8, !18, i64 32, i64 8, !18}


; 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_init_params = type { i64, ptr, 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
@ggml_init.is_first_call = external hidden local_unnamed_addr global i8, align 1
@ggml_table_f32_f16 = external dso_local local_unnamed_addr global [65536 x float], align 16
@.str.21 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [52 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: nounwind uwtable
declare dso_local ptr @ggml_aligned_malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @ggml_time_init() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @ggml_init(ptr nocapture noundef readonly byval(%struct.ggml_init_params) align 8 %0) local_unnamed_addr #1 {
  tail call void @ggml_critical_section_start() #5
  %2 = load i8, ptr @ggml_init.is_first_call, align 1, !tbaa !5, !range !9, !noundef !10
  %3 = trunc nuw i8 %2 to i1
  br i1 %3, label %4, label %10

4:                                                ; preds = %1
  tail call void @ggml_time_init()
  br label %6

5:                                                ; preds = %6
  store i8 0, ptr @ggml_init.is_first_call, align 1, !tbaa !5
  br label %10

6:                                                ; preds = %4, %6
  %indvars.iv = phi i64 [ 0, %4 ], [ %indvars.iv.next, %6 ]
  %7 = trunc i64 %indvars.iv to i16
  %8 = tail call float @ggml_compute_fp16_to_fp32(i16 noundef zeroext %7)
  %9 = getelementptr inbounds [65536 x float], ptr @ggml_table_f32_f16, i64 0, i64 %indvars.iv
  store float %8, ptr %9, align 4, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 65536
  br i1 %exitcond.not, label %5, label %6, !llvm.loop !13

10:                                               ; preds = %5, %1
  tail call void @ggml_critical_section_end() #5
  %11 = tail call ptr @ggml_malloc(i64 noundef 40)
  %12 = load i64, ptr %0, align 8
  %13 = icmp eq i64 %12, 0
  %spec.select = select i1 %13, i64 16, i64 %12
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %.not = icmp eq ptr %15, null
  %16 = add i64 %spec.select, 15
  %17 = and i64 %16, -16
  %18 = select i1 %.not, i64 %17, i64 %spec.select
  br i1 %.not, label %19, label %21

19:                                               ; preds = %10
  %20 = tail call ptr @ggml_aligned_malloc(i64 noundef %17)
  br label %21

21:                                               ; preds = %10, %19
  %22 = phi ptr [ %20, %19 ], [ %15, %10 ]
  %23 = zext i1 %.not to i8
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  %25 = load i8, ptr %24, align 8, !tbaa !19, !range !9, !noundef !10
  store i64 %18, ptr %11, align 8, !tbaa !20
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 8
  store ptr %22, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !21
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 16
  store i8 %23, ptr %.sroa.3.0..sroa_idx, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 17
  store i8 %25, ptr %.sroa.4.0..sroa_idx, align 1, !tbaa !5
  %.sroa.51.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 20
  %.not15 = icmp eq ptr %22, null
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(20) %.sroa.51.0..sroa_idx, i8 0, i64 20, i1 false)
  br i1 %.not15, label %26, label %27

26:                                               ; preds = %21
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.12, i32 noundef 1418, ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.21) #6
  unreachable

27:                                               ; preds = %21
  %28 = ptrtoint ptr %22 to i64
  %29 = and i64 %28, 15
  %30 = icmp eq i64 %29, 0
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.12, i32 noundef 1420, ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.22) #6
  unreachable

32:                                               ; preds = %27
  ret ptr %11
}

declare void @ggml_critical_section_start() local_unnamed_addr #2

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

declare void @ggml_critical_section_end() local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ggml_malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { noreturn }

!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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !18, i64 8}
!16 = !{!"ggml_init_params", !17, i64 0, !18, i64 8, !6, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!"any pointer", !7, i64 0}
!19 = !{!16, !6, i64 16}
!20 = !{!17, !17, i64 0}
!21 = !{!18, !18, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass