; 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.192 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.193 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.194 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.195 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.196 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.197 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.198 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.199 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.200 = external hidden unnamed_addr constant [42 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: nounwind uwtable
declare dso_local void @ggml_log_internal(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: nounwind uwtable
declare dso_local ptr @ggml_op_name(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @ggml_get_name(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @ggml_graph_get_grad(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @ggml_graph_print(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 2, ptr noundef @.str.192)
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ggml_cgraph, ptr %7, i32 0, i32 1
  %9 = load i32, ptr %8, align 4, !tbaa !9
  call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 2, ptr noundef @.str.193, i32 noundef %9)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !14
  br label %10

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

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

17:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ggml_cgraph, ptr %18, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = load i32, ptr %3, align 4, !tbaa !14
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds ptr, ptr %20, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  store ptr %24, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !14
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ggml_tensor, ptr %26, i32 0, i32 2
  %28 = getelementptr inbounds [4 x i64], ptr %27, i64 0, i64 0
  %29 = load i64, ptr %28, align 8, !tbaa !16
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ggml_tensor, ptr %30, i32 0, i32 2
  %32 = getelementptr inbounds [4 x i64], ptr %31, i64 0, i64 1
  %33 = load i64, ptr %32, align 8, !tbaa !16
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ggml_tensor, ptr %34, i32 0, i32 2
  %36 = getelementptr inbounds [4 x i64], ptr %35, i64 0, i64 2
  %37 = load i64, ptr %36, align 8, !tbaa !16
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ggml_tensor, ptr %38, i32 0, i32 4
  %40 = load i32, ptr %39, align 8, !tbaa !17
  %41 = call ptr @ggml_op_name(i32 noundef %40)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ggml_tensor, ptr %42, i32 0, i32 6
  %44 = load i32, ptr %43, align 4, !tbaa !19
  %45 = and i32 %44, 4
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %17
  br label %55

48:                                               ; preds = %17
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = call ptr @ggml_graph_get_grad(ptr noundef %49, ptr noundef %50)
  %52 = icmp ne ptr %51, null
  %53 = zext i1 %52 to i64
  %54 = select i1 %52, ptr @.str.196, ptr @.str.197
  br label %55

55:                                               ; preds = %48, %47
  %56 = phi ptr [ @.str.195, %47 ], [ %54, %48 ]
  call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 2, ptr noundef @.str.194, i32 noundef %25, i64 noundef %29, i64 noundef %33, i64 noundef %37, ptr noundef %41, ptr noundef %56)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %57

57:                                               ; preds = %55
  %58 = load i32, ptr %3, align 4, !tbaa !14
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %3, align 4, !tbaa !14
  br label %10, !llvm.loop !20

60:                                               ; preds = %16
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.ggml_cgraph, ptr %61, i32 0, i32 2
  %63 = load i32, ptr %62, align 8, !tbaa !22
  call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 2, ptr noundef @.str.198, i32 noundef %63)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %64

64:                                               ; preds = %94, %60
  %65 = load i32, ptr %5, align 4, !tbaa !14
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ggml_cgraph, ptr %66, i32 0, i32 2
  %68 = load i32, ptr %67, align 8, !tbaa !22
  %69 = icmp slt i32 %65, %68
  br i1 %69, label %71, label %70

70:                                               ; preds = %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %97

71:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.ggml_cgraph, ptr %72, i32 0, i32 6
  %74 = load ptr, ptr %73, align 8, !tbaa !23
  %75 = load i32, ptr %5, align 4, !tbaa !14
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds ptr, ptr %74, i64 %76
  %78 = load ptr, ptr %77, align 8, !tbaa !5
  store ptr %78, ptr %6, align 8, !tbaa !5
  %79 = load i32, ptr %5, align 4, !tbaa !14
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.ggml_tensor, ptr %80, i32 0, i32 2
  %82 = getelementptr inbounds [4 x i64], ptr %81, i64 0, i64 0
  %83 = load i64, ptr %82, align 8, !tbaa !16
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.ggml_tensor, ptr %84, i32 0, i32 2
  %86 = getelementptr inbounds [4 x i64], ptr %85, i64 0, i64 1
  %87 = load i64, ptr %86, align 8, !tbaa !16
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.ggml_tensor, ptr %88, i32 0, i32 4
  %90 = load i32, ptr %89, align 8, !tbaa !17
  %91 = call ptr @ggml_op_name(i32 noundef %90)
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = call ptr @ggml_get_name(ptr noundef %92)
  call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 2, ptr noundef @.str.199, i32 noundef %79, i64 noundef %83, i64 noundef %87, ptr noundef %91, ptr noundef %93)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %94

94:                                               ; preds = %71
  %95 = load i32, ptr %5, align 4, !tbaa !14
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %5, align 4, !tbaa !14
  br label %64, !llvm.loop !24

97:                                               ; preds = %70
  call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 2, ptr noundef @.str.200)
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !11, i64 4}
!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, !6, i64 16}
!16 = !{!13, !13, i64 0}
!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 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!10, !11, i64 8}
!23 = !{!10, !6, i64 40}
!24 = distinct !{!24, !21}


; 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.192 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.193 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.194 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.195 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.196 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.197 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.198 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.199 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.200 = external hidden unnamed_addr constant [42 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @ggml_op_name(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @ggml_get_name(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @ggml_graph_print(ptr noundef %0) local_unnamed_addr #0 {
  tail call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 2, ptr noundef nonnull @.str.192)
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i32, ptr %2, align 4, !tbaa !5
  tail call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 2, ptr noundef nonnull @.str.193, i32 noundef %3)
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  br label %12

._crit_edge:                                      ; preds = %31, %1
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !13
  tail call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 2, ptr noundef nonnull @.str.198, i32 noundef %8)
  %9 = load i32, ptr %7, align 8, !tbaa !13
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph29, label %._crit_edge30

.lr.ph29:                                         ; preds = %._crit_edge
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  br label %37

12:                                               ; preds = %.lr.ph, %31
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %31 ]
  %13 = load ptr, ptr %6, align 8, !tbaa !14
  %14 = getelementptr inbounds ptr, ptr %13, i64 %indvars.iv
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  %17 = load i64, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %15, i64 24
  %19 = load i64, ptr %18, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %15, i64 32
  %21 = load i64, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %15, i64 80
  %23 = load i32, ptr %22, align 8, !tbaa !17
  %24 = tail call ptr @ggml_op_name(i32 noundef %23)
  %25 = getelementptr inbounds i8, ptr %15, i64 148
  %26 = load i32, ptr %25, align 4, !tbaa !19
  %27 = and i32 %26, 4
  %.not = icmp eq i32 %27, 0
  br i1 %.not, label %28, label %31

28:                                               ; preds = %12
  %29 = tail call ptr @ggml_graph_get_grad(ptr noundef nonnull %0, ptr noundef nonnull %15)
  %.not25 = icmp eq ptr %29, null
  %30 = select i1 %.not25, ptr @.str.197, ptr @.str.196
  br label %31

31:                                               ; preds = %12, %28
  %32 = phi ptr [ %30, %28 ], [ @.str.195, %12 ]
  %33 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 2, ptr noundef nonnull @.str.194, i32 noundef %33, i64 noundef %17, i64 noundef %19, i64 noundef %21, ptr noundef %24, ptr noundef nonnull %32)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = icmp slt i64 %indvars.iv.next, %35
  br i1 %36, label %12, label %._crit_edge, !llvm.loop !20

._crit_edge30:                                    ; preds = %37, %._crit_edge
  tail call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 2, ptr noundef nonnull @.str.200)
  ret void

37:                                               ; preds = %.lr.ph29, %37
  %indvars.iv32 = phi i64 [ 0, %.lr.ph29 ], [ %indvars.iv.next33, %37 ]
  %38 = load ptr, ptr %11, align 8, !tbaa !22
  %39 = getelementptr inbounds ptr, ptr %38, i64 %indvars.iv32
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = getelementptr inbounds i8, ptr %40, i64 16
  %42 = load i64, ptr %41, align 8, !tbaa !16
  %43 = getelementptr inbounds i8, ptr %40, i64 24
  %44 = load i64, ptr %43, align 8, !tbaa !16
  %45 = getelementptr inbounds i8, ptr %40, i64 80
  %46 = load i32, ptr %45, align 8, !tbaa !17
  %47 = tail call ptr @ggml_op_name(i32 noundef %46)
  %48 = tail call ptr @ggml_get_name(ptr noundef %40)
  %49 = trunc nuw nsw i64 %indvars.iv32 to i32
  tail call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 2, ptr noundef nonnull @.str.199, i32 noundef %49, i64 noundef %42, i64 noundef %44, ptr noundef %47, ptr noundef %48)
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %50 = load i32, ptr %7, align 8, !tbaa !13
  %51 = sext i32 %50 to i64
  %52 = icmp slt i64 %indvars.iv.next33, %51
  br i1 %52, label %37, label %._crit_edge30, !llvm.loop !23
}

attributes #0 = { 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" }

!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 = !{!"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 8}
!14 = !{!6, !10, i64 16}
!15 = !{!10, !10, i64 0}
!16 = !{!12, !12, i64 0}
!17 = !{!18, !7, i64 80}
!18 = !{!"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}
!19 = !{!18, !7, i64 148}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!6, !10, i64 40}
!23 = distinct !{!23, !21}


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