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

; 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_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 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 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: noreturn
declare void @ggml_abort(ptr noundef, i32 noundef, ptr noundef, ...) #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @ggml_compute_forward_add1(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ggml_tensor, ptr %7, i32 0, i32 7
  %9 = getelementptr inbounds [10 x ptr], ptr %8, i64 0, i64 0
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %10, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ggml_tensor, ptr %11, i32 0, i32 7
  %13 = getelementptr inbounds [10 x ptr], ptr %12, i64 0, i64 1
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ggml_tensor, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !9
  switch i32 %17, label %62 [
    i32 0, label %18
    i32 1, label %21
    i32 30, label %40
    i32 2, label %59
    i32 3, label %59
    i32 6, label %59
    i32 7, label %59
    i32 8, label %59
    i32 9, label %59
    i32 10, label %59
    i32 11, label %59
    i32 12, label %59
    i32 13, label %59
    i32 14, label %59
    i32 34, label %59
    i32 35, label %59
    i32 16, label %59
    i32 17, label %59
    i32 18, label %59
    i32 19, label %59
    i32 29, label %59
    i32 20, label %59
    i32 23, label %59
    i32 21, label %59
    i32 22, label %59
  ]

18:                                               ; preds = %2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZL29ggml_compute_forward_add1_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef %19, ptr noundef %20)
  br label %63

21:                                               ; preds = %2
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ggml_tensor, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %29

26:                                               ; preds = %21
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZL33ggml_compute_forward_add1_f16_f16PK19ggml_compute_paramsP11ggml_tensor(ptr noundef %27, ptr noundef %28)
  br label %39

29:                                               ; preds = %21
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ggml_tensor, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !9
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %37

34:                                               ; preds = %29
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZL33ggml_compute_forward_add1_f16_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef %35, ptr noundef %36)
  br label %38

37:                                               ; preds = %29
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str, i32 noundef 1670, ptr noundef @.str.1) #4
  unreachable

38:                                               ; preds = %34
  br label %39

39:                                               ; preds = %38, %26
  br label %63

40:                                               ; preds = %2
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ggml_tensor, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !9
  %44 = icmp eq i32 %43, 30
  br i1 %44, label %45, label %48

45:                                               ; preds = %40
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZL35ggml_compute_forward_add1_bf16_bf16PK19ggml_compute_paramsP11ggml_tensor(ptr noundef %46, ptr noundef %47)
  br label %58

48:                                               ; preds = %40
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ggml_tensor, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !9
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %48
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZL34ggml_compute_forward_add1_bf16_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef %54, ptr noundef %55)
  br label %57

56:                                               ; preds = %48
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str, i32 noundef 1682, ptr noundef @.str.1) #4
  unreachable

57:                                               ; preds = %53
  br label %58

58:                                               ; preds = %57, %45
  br label %63

59:                                               ; preds = %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZL31ggml_compute_forward_add1_q_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef %60, ptr noundef %61)
  br label %63

62:                                               ; preds = %2
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str, i32 noundef 1712, ptr noundef @.str.1) #4
  unreachable

63:                                               ; preds = %59, %58, %39, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL29ggml_compute_forward_add1_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL33ggml_compute_forward_add1_f16_f16PK19ggml_compute_paramsP11ggml_tensor(ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL33ggml_compute_forward_add1_f16_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL35ggml_compute_forward_add1_bf16_bf16PK19ggml_compute_paramsP11ggml_tensor(ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL34ggml_compute_forward_add1_bf16_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL31ggml_compute_forward_add1_q_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef, ptr 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 = { mustprogress 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 = { nounwind }
attributes #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS11ggml_tensor", !11, i64 0, !6, i64 8, !7, i64 16, !7, i64 48, !12, i64 80, !7, i64 84, !13, i64 148, !7, i64 152, !6, i64 232, !14, i64 240, !6, i64 248, !7, i64 256, !6, i64 320, !7, i64 328}
!11 = !{!"_ZTS9ggml_type", !7, i64 0}
!12 = !{!"_ZTS7ggml_op", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, 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 [68 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1

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

; Function Attrs: mustprogress uwtable
define dso_local void @ggml_compute_forward_add1(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 152
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 160
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load i32, ptr %4, align 8, !tbaa !9
  switch i32 %7, label %20 [
    i32 0, label %8
    i32 1, label %9
    i32 30, label %14
    i32 2, label %19
    i32 3, label %19
    i32 6, label %19
    i32 7, label %19
    i32 8, label %19
    i32 9, label %19
    i32 10, label %19
    i32 11, label %19
    i32 12, label %19
    i32 13, label %19
    i32 14, label %19
    i32 34, label %19
    i32 35, label %19
    i32 16, label %19
    i32 17, label %19
    i32 18, label %19
    i32 19, label %19
    i32 29, label %19
    i32 20, label %19
    i32 23, label %19
    i32 21, label %19
    i32 22, label %19
  ]

8:                                                ; preds = %2
  tail call void @_ZL29ggml_compute_forward_add1_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef %0, ptr noundef nonnull %1)
  br label %21

9:                                                ; preds = %2
  %10 = load i32, ptr %6, align 8, !tbaa !9
  switch i32 %10, label %13 [
    i32 1, label %11
    i32 0, label %12
  ]

11:                                               ; preds = %9
  tail call void @_ZL33ggml_compute_forward_add1_f16_f16PK19ggml_compute_paramsP11ggml_tensor(ptr noundef %0, ptr noundef nonnull %1)
  br label %21

12:                                               ; preds = %9
  tail call void @_ZL33ggml_compute_forward_add1_f16_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef %0, ptr noundef nonnull %1)
  br label %21

13:                                               ; preds = %9
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str, i32 noundef 1670, ptr noundef nonnull @.str.1) #2
  unreachable

14:                                               ; preds = %2
  %15 = load i32, ptr %6, align 8, !tbaa !9
  switch i32 %15, label %18 [
    i32 30, label %16
    i32 0, label %17
  ]

16:                                               ; preds = %14
  tail call void @_ZL35ggml_compute_forward_add1_bf16_bf16PK19ggml_compute_paramsP11ggml_tensor(ptr noundef %0, ptr noundef nonnull %1)
  br label %21

17:                                               ; preds = %14
  tail call void @_ZL34ggml_compute_forward_add1_bf16_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef %0, ptr noundef nonnull %1)
  br label %21

18:                                               ; preds = %14
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str, i32 noundef 1682, ptr noundef nonnull @.str.1) #2
  unreachable

19:                                               ; preds = %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2
  tail call void @_ZL31ggml_compute_forward_add1_q_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef %0, ptr noundef nonnull %1)
  br label %21

20:                                               ; preds = %2
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str, i32 noundef 1712, ptr noundef nonnull @.str.1) #2
  unreachable

21:                                               ; preds = %16, %17, %11, %12, %19, %8
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL29ggml_compute_forward_add1_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL33ggml_compute_forward_add1_f16_f16PK19ggml_compute_paramsP11ggml_tensor(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL33ggml_compute_forward_add1_f16_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL35ggml_compute_forward_add1_bf16_bf16PK19ggml_compute_paramsP11ggml_tensor(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL34ggml_compute_forward_add1_bf16_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL31ggml_compute_forward_add1_q_f32PK19ggml_compute_paramsP11ggml_tensor(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { mustprogress 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS11ggml_tensor", !11, i64 0, !6, i64 8, !7, i64 16, !7, i64 48, !12, i64 80, !7, i64 84, !13, i64 148, !7, i64 152, !6, i64 232, !14, i64 240, !6, i64 248, !7, i64 256, !6, i64 320, !7, i64 328}
!11 = !{!"_ZTS9ggml_type", !7, i64 0}
!12 = !{!"_ZTS7ggml_op", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}


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