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

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

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__PRETTY_FUNCTION__.llamafile_sgemm = external hidden unnamed_addr constant [162 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [26 x i8], align 1

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

30:                                               ; preds = %13
  br label %33

31:                                               ; preds = %13
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 3283, ptr noundef @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

32:                                               ; No predecessors!
  br label %33

33:                                               ; preds = %32, %30
  %34 = load i64, ptr %17, align 8, !tbaa !9
  %35 = icmp sge i64 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  br label %39

37:                                               ; preds = %33
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 3284, ptr noundef @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

38:                                               ; No predecessors!
  br label %39

39:                                               ; preds = %38, %36
  %40 = load i64, ptr %18, align 8, !tbaa !9
  %41 = icmp sge i64 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  br label %45

43:                                               ; preds = %39
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 3285, ptr noundef @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

44:                                               ; No predecessors!
  br label %45

45:                                               ; preds = %44, %42
  %46 = load i64, ptr %20, align 8, !tbaa !9
  %47 = load i64, ptr %18, align 8, !tbaa !9
  %48 = icmp sge i64 %46, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %45
  br label %52

50:                                               ; preds = %45
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 3286, ptr noundef @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

51:                                               ; No predecessors!
  br label %52

52:                                               ; preds = %51, %49
  %53 = load i64, ptr %22, align 8, !tbaa !9
  %54 = load i64, ptr %18, align 8, !tbaa !9
  %55 = icmp sge i64 %53, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %52
  br label %59

57:                                               ; preds = %52
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 3287, ptr noundef @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

58:                                               ; No predecessors!
  br label %59

59:                                               ; preds = %58, %56
  %60 = load i64, ptr %24, align 8, !tbaa !9
  %61 = load i64, ptr %16, align 8, !tbaa !9
  %62 = icmp sge i64 %60, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %59
  br label %66

64:                                               ; preds = %59
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 3288, ptr noundef @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

65:                                               ; No predecessors!
  br label %66

66:                                               ; preds = %65, %63
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.ggml_compute_params, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 4, !tbaa !13
  %70 = icmp sgt i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %66
  br label %74

72:                                               ; preds = %66
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.1, i32 noundef 3289, ptr noundef @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

73:                                               ; No predecessors!
  br label %74

74:                                               ; preds = %73, %71
  %75 = load ptr, ptr %15, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ggml_compute_params, ptr %75, i32 0, i32 0
  %77 = load i32, ptr %76, align 8, !tbaa !15
  %78 = load ptr, ptr %15, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.ggml_compute_params, ptr %78, i32 0, i32 1
  %80 = load i32, ptr %79, align 4, !tbaa !13
  %81 = icmp slt i32 %77, %80
  br i1 %81, label %82, label %83

82:                                               ; preds = %74
  br label %85

83:                                               ; preds = %74
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 3290, ptr noundef @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

84:                                               ; No predecessors!
  br label %85

85:                                               ; preds = %84, %82
  %86 = load i64, ptr %17, align 8, !tbaa !9
  %87 = icmp slt i64 %86, 2
  br i1 %87, label %88, label %89

88:                                               ; preds = %85
  store i1 false, ptr %14, align 1
  br label %123

89:                                               ; preds = %85
  %90 = load i32, ptr %27, align 4, !tbaa !11
  %91 = icmp ne i32 %90, 0
  br i1 %91, label %92, label %93

92:                                               ; preds = %89
  store i1 false, ptr %14, align 1
  br label %123

93:                                               ; preds = %89
  %94 = load i32, ptr %25, align 4, !tbaa !11
  switch i32 %94, label %122 [
    i32 0, label %95
    i32 30, label %100
    i32 1, label %101
    i32 8, label %102
    i32 2, label %107
    i32 6, label %112
    i32 20, label %117
  ]

95:                                               ; preds = %93
  %96 = load i32, ptr %26, align 4, !tbaa !11
  %97 = icmp ne i32 %96, 0
  br i1 %97, label %98, label %99

98:                                               ; preds = %95
  store i1 false, ptr %14, align 1
  br label %123

99:                                               ; preds = %95
  store i1 false, ptr %14, align 1
  br label %123

100:                                              ; preds = %93
  store i1 false, ptr %14, align 1
  br label %123

101:                                              ; preds = %93
  store i1 false, ptr %14, align 1
  br label %123

102:                                              ; preds = %93
  %103 = load i32, ptr %26, align 4, !tbaa !11
  %104 = icmp ne i32 %103, 8
  br i1 %104, label %105, label %106

105:                                              ; preds = %102
  store i1 false, ptr %14, align 1
  br label %123

106:                                              ; preds = %102
  store i1 false, ptr %14, align 1
  br label %123

107:                                              ; preds = %93
  %108 = load i32, ptr %26, align 4, !tbaa !11
  %109 = icmp ne i32 %108, 8
  br i1 %109, label %110, label %111

110:                                              ; preds = %107
  store i1 false, ptr %14, align 1
  br label %123

111:                                              ; preds = %107
  store i1 false, ptr %14, align 1
  br label %123

112:                                              ; preds = %93
  %113 = load i32, ptr %26, align 4, !tbaa !11
  %114 = icmp ne i32 %113, 8
  br i1 %114, label %115, label %116

115:                                              ; preds = %112
  store i1 false, ptr %14, align 1
  br label %123

116:                                              ; preds = %112
  store i1 false, ptr %14, align 1
  br label %123

117:                                              ; preds = %93
  %118 = load i32, ptr %26, align 4, !tbaa !11
  %119 = icmp ne i32 %118, 8
  br i1 %119, label %120, label %121

120:                                              ; preds = %117
  store i1 false, ptr %14, align 1
  br label %123

121:                                              ; preds = %117
  store i1 false, ptr %14, align 1
  br label %123

122:                                              ; preds = %93
  store i1 false, ptr %14, align 1
  br label %123

123:                                              ; preds = %122, %121, %120, %116, %115, %111, %110, %106, %105, %101, %100, %99, %98, %92, %88
  %124 = load i1, ptr %14, align 1
  ret i1 %124
}

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

attributes #0 = { mustprogress 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 = { 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 #2 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 4}
!14 = !{!"_ZTS19ggml_compute_params", !12, i64 0, !12, i64 4, !10, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!14, !12, i64 0}


; 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"

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__PRETTY_FUNCTION__.llamafile_sgemm = external hidden unnamed_addr constant [162 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @llamafile_sgemm(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef readnone %4, i64 noundef %5, ptr nocapture noundef readnone %6, i64 noundef %7, ptr nocapture noundef readnone %8, i64 noundef %9, i32 noundef %10, i32 noundef %11, i32 noundef %12) local_unnamed_addr #0 {
  %14 = icmp sgt i64 %1, -1
  br i1 %14, label %16, label %15

15:                                               ; preds = %13
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 3283, ptr noundef nonnull @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

16:                                               ; preds = %13
  %17 = icmp sgt i64 %2, -1
  br i1 %17, label %19, label %18

18:                                               ; preds = %16
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 3284, ptr noundef nonnull @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

19:                                               ; preds = %16
  %20 = icmp sgt i64 %3, -1
  br i1 %20, label %22, label %21

21:                                               ; preds = %19
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 3285, ptr noundef nonnull @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

22:                                               ; preds = %19
  %.not = icmp slt i64 %5, %3
  br i1 %.not, label %23, label %24

23:                                               ; preds = %22
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 3286, ptr noundef nonnull @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

24:                                               ; preds = %22
  %.not23 = icmp slt i64 %7, %3
  br i1 %.not23, label %25, label %26

25:                                               ; preds = %24
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 3287, ptr noundef nonnull @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

26:                                               ; preds = %24
  %.not24 = icmp slt i64 %9, %1
  br i1 %.not24, label %27, label %28

27:                                               ; preds = %26
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 3288, ptr noundef nonnull @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

28:                                               ; preds = %26
  %29 = getelementptr inbounds i8, ptr %0, i64 4
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = icmp sgt i32 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.1, i32 noundef 3289, ptr noundef nonnull @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

33:                                               ; preds = %28
  %34 = load i32, ptr %0, align 8, !tbaa !12
  %35 = icmp slt i32 %34, %30
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 3290, ptr noundef nonnull @__PRETTY_FUNCTION__.llamafile_sgemm) #2
  unreachable

37:                                               ; preds = %33
  ret i1 false
}

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

attributes #0 = { mustprogress 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 = { 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 #2 = { 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, !7, i64 4}
!6 = !{!"_ZTS19ggml_compute_params", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !11, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass