; 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_cgraph = type { i32, i32, i32, ptr, ptr, ptr, ptr, %struct.ggml_hash_set, i32 }
%struct.ggml_hash_set = type { i64, ptr, 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.185 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.186 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.187 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.188 = external hidden unnamed_addr constant [15 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 zeroext i1 @ggml_is_scalar(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @ggml_set_zero(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @ggml_graph_reset(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ggml_cgraph, ptr %7, i32 0, i32 4
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %1
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.12, i32 noundef 6035, ptr noundef @.str.13, ptr noundef @.str.185) #4
  unreachable

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !14
  br label %13

13:                                               ; preds = %88, %12
  %14 = load i32, ptr %3, align 4, !tbaa !14
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ggml_cgraph, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !15
  %18 = icmp slt i32 %14, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %91

20:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ggml_cgraph, ptr %21, i32 0, i32 3
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = load i32, ptr %3, align 4, !tbaa !14
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds ptr, ptr %23, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  store ptr %27, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call ptr @ggml_graph_get_grad_acc(ptr noundef %28, ptr noundef %29)
  store ptr %30, ptr %5, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ggml_tensor, ptr %31, i32 0, i32 4
  %33 = load i32, ptr %32, align 8, !tbaa !17
  %34 = icmp eq i32 %33, 81
  br i1 %34, label %35, label %46

35:                                               ; preds = %20
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ggml_tensor, ptr %36, i32 0, i32 7
  %38 = getelementptr inbounds [10 x ptr], ptr %37, i64 0, i64 2
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = call ptr @ggml_set_zero(ptr noundef %39)
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ggml_tensor, ptr %41, i32 0, i32 7
  %43 = getelementptr inbounds [10 x ptr], ptr %42, i64 0, i64 3
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = call ptr @ggml_set_zero(ptr noundef %44)
  br label %46

46:                                               ; preds = %35, %20
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %87

49:                                               ; preds = %46
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ggml_tensor, ptr %50, i32 0, i32 6
  %52 = load i32, ptr %51, align 4, !tbaa !19
  %53 = and i32 %52, 8
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %83

55:                                               ; preds = %49
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ggml_tensor, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !20
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %61, label %60

60:                                               ; preds = %55
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.12, i32 noundef 6050, ptr noundef @.str.13, ptr noundef @.str.186) #4
  unreachable

61:                                               ; preds = %55
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = call zeroext i1 @ggml_is_scalar(ptr noundef %62)
  br i1 %63, label %65, label %64

64:                                               ; preds = %61
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.12, i32 noundef 6051, ptr noundef @.str.13, ptr noundef @.str.187) #4
  unreachable

65:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store float 1.000000e+00, ptr %6, align 4, !tbaa !21
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ggml_tensor, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !23
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %72

70:                                               ; preds = %65
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  call void @ggml_backend_tensor_set(ptr noundef %71, ptr noundef %6, i64 noundef 0, i64 noundef 4)
  br label %82

72:                                               ; preds = %65
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.ggml_tensor, ptr %73, i32 0, i32 10
  %75 = load ptr, ptr %74, align 8, !tbaa !24
  %76 = icmp ne ptr %75, null
  br i1 %76, label %78, label %77

77:                                               ; preds = %72
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.12, i32 noundef 6057, ptr noundef @.str.13, ptr noundef @.str.188) #4
  unreachable

78:                                               ; preds = %72
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.ggml_tensor, ptr %79, i32 0, i32 10
  %81 = load ptr, ptr %80, align 8, !tbaa !24
  store float 1.000000e+00, ptr %81, align 4, !tbaa !21
  br label %82

82:                                               ; preds = %78, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %86

83:                                               ; preds = %49
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = call ptr @ggml_set_zero(ptr noundef %84)
  br label %86

86:                                               ; preds = %83, %82
  br label %87

87:                                               ; preds = %86, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %3, align 4, !tbaa !14
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %3, align 4, !tbaa !14
  br label %13, !llvm.loop !25

91:                                               ; preds = %19
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @ggml_graph_get_grad_acc(ptr noundef, ptr noundef) #2

declare void @ggml_backend_tensor_set(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #3

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 = { "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 = { noreturn }
attributes #5 = { 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, !6, i64 24}
!10 = !{!"ggml_cgraph", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !12, i64 48, !11, i64 72}
!11 = !{!"int", !7, i64 0}
!12 = !{!"ggml_hash_set", !13, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 4}
!16 = !{!10, !6, i64 16}
!17 = !{!18, !11, i64 80}
!18 = !{!"ggml_tensor", !11, i64 0, !6, i64 8, !7, i64 16, !7, i64 48, !11, i64 80, !7, i64 84, !11, i64 148, !7, i64 152, !6, i64 232, !13, i64 240, !6, i64 248, !7, i64 256, !6, i64 320, !7, i64 328}
!19 = !{!18, !11, i64 148}
!20 = !{!18, !11, i64 0}
!21 = !{!22, !22, i64 0}
!22 = !{!"float", !7, i64 0}
!23 = !{!18, !6, i64 8}
!24 = !{!18, !6, i64 248}
!25 = distinct !{!25, !26}
!26 = !{!"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"

@.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.185 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.186 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.187 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.188 = external hidden unnamed_addr constant [15 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 zeroext i1 @ggml_is_scalar(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @ggml_set_zero(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @ggml_graph_reset(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca float, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %9, label %.preheader

.preheader:                                       ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !13
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  br label %10

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

._crit_edge:                                      ; preds = %49, %.preheader
  ret void

10:                                               ; preds = %.lr.ph, %49
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %49 ]
  %11 = load ptr, ptr %8, align 8, !tbaa !14
  %12 = getelementptr inbounds ptr, ptr %11, i64 %indvars.iv
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = call ptr @ggml_graph_get_grad_acc(ptr noundef nonnull %0, ptr noundef %13)
  %15 = getelementptr inbounds i8, ptr %13, i64 80
  %16 = load i32, ptr %15, align 8, !tbaa !16
  %17 = icmp eq i32 %16, 81
  br i1 %17, label %18, label %25

18:                                               ; preds = %10
  %19 = getelementptr inbounds i8, ptr %13, i64 168
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = call ptr @ggml_set_zero(ptr noundef %20)
  %22 = getelementptr inbounds i8, ptr %13, i64 176
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = call ptr @ggml_set_zero(ptr noundef %23)
  br label %25

25:                                               ; preds = %18, %10
  %.not21 = icmp eq ptr %14, null
  br i1 %.not21, label %49, label %26

26:                                               ; preds = %25
  %27 = getelementptr inbounds i8, ptr %13, i64 148
  %28 = load i32, ptr %27, align 4, !tbaa !18
  %29 = and i32 %28, 8
  %.not22 = icmp eq i32 %29, 0
  br i1 %.not22, label %47, label %30

30:                                               ; preds = %26
  %31 = load i32, ptr %14, align 8, !tbaa !19
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.12, i32 noundef 6050, ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.186) #4
  unreachable

34:                                               ; preds = %30
  %35 = call zeroext i1 @ggml_is_scalar(ptr noundef nonnull %14)
  br i1 %35, label %37, label %36

36:                                               ; preds = %34
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.12, i32 noundef 6051, ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.187) #4
  unreachable

37:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  store float 1.000000e+00, ptr %2, align 4, !tbaa !20
  %38 = getelementptr inbounds i8, ptr %14, i64 8
  %39 = load ptr, ptr %38, align 8, !tbaa !22
  %.not23 = icmp eq ptr %39, null
  br i1 %.not23, label %41, label %40

40:                                               ; preds = %37
  call void @ggml_backend_tensor_set(ptr noundef nonnull %14, ptr noundef nonnull %2, i64 noundef 0, i64 noundef 4) #5
  br label %46

41:                                               ; preds = %37
  %42 = getelementptr inbounds i8, ptr %14, i64 248
  %43 = load ptr, ptr %42, align 8, !tbaa !23
  %.not24 = icmp eq ptr %43, null
  br i1 %.not24, label %44, label %45

44:                                               ; preds = %41
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.12, i32 noundef 6057, ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.188) #4
  unreachable

45:                                               ; preds = %41
  store float 1.000000e+00, ptr %43, align 4, !tbaa !20
  br label %46

46:                                               ; preds = %45, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  br label %49

47:                                               ; preds = %26
  %48 = call ptr @ggml_set_zero(ptr noundef nonnull %14)
  br label %49

49:                                               ; preds = %46, %47, %25
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %50 = load i32, ptr %5, align 4, !tbaa !13
  %51 = sext i32 %50 to i64
  %52 = icmp slt i64 %indvars.iv.next, %51
  br i1 %52, label %10, label %._crit_edge, !llvm.loop !24
}

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

declare void @ggml_backend_tensor_set(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #3

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 = { "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 = { noreturn }
attributes #5 = { 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, !10, i64 24}
!6 = !{!"ggml_cgraph", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !11, i64 48, !7, i64 72}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"ggml_hash_set", !12, i64 0, !10, i64 8, !10, i64 16}
!12 = !{!"long", !8, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !10, i64 16}
!15 = !{!10, !10, i64 0}
!16 = !{!17, !7, i64 80}
!17 = !{!"ggml_tensor", !7, i64 0, !10, i64 8, !8, i64 16, !8, i64 48, !7, i64 80, !8, i64 84, !7, i64 148, !8, i64 152, !10, i64 232, !12, i64 240, !10, i64 248, !8, i64 256, !10, i64 320, !8, i64 328}
!18 = !{!17, !7, i64 148}
!19 = !{!17, !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"float", !8, i64 0}
!22 = !{!17, !10, i64 8}
!23 = !{!17, !10, i64 248}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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