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

; 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_backend_sched = type { i8, i8, i32, [16 x ptr], [16 x ptr], ptr, %struct.ggml_hash_set, ptr, ptr, ptr, ptr, ptr, ptr, %struct.ggml_cgraph, ptr, i32, i32, i32, i32, [16 x [4 x ptr]], [10 x ptr], i32, ptr, ptr, ptr, ptr, i64, i32 }
%struct.ggml_hash_set = type { i64, ptr, ptr }
%struct.ggml_cgraph = type { i32, i32, i32, ptr, ptr, ptr, ptr, %struct.ggml_hash_set, i32 }

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @ggml_backend_event_free(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @ggml_backend_sched_free(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  br label %84

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

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

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

17:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %35, %17
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ggml_backend_sched, ptr %20, i32 0, i32 17
  %22 = load i32, ptr %21, align 8, !tbaa !18
  %23 = icmp slt i32 %19, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %18
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %38

25:                                               ; preds = %18
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ggml_backend_sched, ptr %26, i32 0, i32 19
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [16 x [4 x ptr]], ptr %27, i64 0, i64 %29
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [4 x ptr], ptr %30, i64 0, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  call void @ggml_backend_event_free(ptr noundef %34)
  br label %35

35:                                               ; preds = %25
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %5, align 4, !tbaa !9
  br label %18, !llvm.loop !19

38:                                               ; preds = %24
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %3, align 4, !tbaa !9
  br label %10, !llvm.loop !21

42:                                               ; preds = %16
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ggml_backend_sched, ptr %43, i32 0, i32 5
  %45 = load ptr, ptr %44, align 8, !tbaa !22
  call void @ggml_gallocr_free(ptr noundef %45)
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ggml_backend_sched, ptr %46, i32 0, i32 22
  %48 = load ptr, ptr %47, align 8, !tbaa !23
  call void @ggml_free(ptr noundef %48)
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ggml_backend_sched, ptr %49, i32 0, i32 6
  call void @ggml_hash_set_free(ptr noundef %50)
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ggml_backend_sched, ptr %51, i32 0, i32 14
  %53 = load ptr, ptr %52, align 8, !tbaa !24
  call void @free(ptr noundef %53) #4
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ggml_backend_sched, ptr %54, i32 0, i32 7
  %56 = load ptr, ptr %55, align 8, !tbaa !25
  call void @free(ptr noundef %56) #4
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ggml_backend_sched, ptr %57, i32 0, i32 8
  %59 = load ptr, ptr %58, align 8, !tbaa !26
  call void @free(ptr noundef %59) #4
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ggml_backend_sched, ptr %60, i32 0, i32 9
  %62 = load ptr, ptr %61, align 8, !tbaa !27
  call void @free(ptr noundef %62) #4
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ggml_backend_sched, ptr %63, i32 0, i32 10
  %65 = load ptr, ptr %64, align 8, !tbaa !28
  call void @free(ptr noundef %65) #4
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ggml_backend_sched, ptr %66, i32 0, i32 11
  %68 = load ptr, ptr %67, align 8, !tbaa !29
  call void @free(ptr noundef %68) #4
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ggml_backend_sched, ptr %69, i32 0, i32 12
  %71 = load ptr, ptr %70, align 8, !tbaa !30
  call void @free(ptr noundef %71) #4
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.ggml_backend_sched, ptr %72, i32 0, i32 25
  %74 = load ptr, ptr %73, align 8, !tbaa !31
  call void @free(ptr noundef %74) #4
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ggml_backend_sched, ptr %75, i32 0, i32 13
  %77 = getelementptr inbounds %struct.ggml_cgraph, ptr %76, i32 0, i32 3
  %78 = load ptr, ptr %77, align 8, !tbaa !32
  call void @free(ptr noundef %78) #4
  %79 = load ptr, ptr %2, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.ggml_backend_sched, ptr %79, i32 0, i32 13
  %81 = getelementptr inbounds %struct.ggml_cgraph, ptr %80, i32 0, i32 6
  %82 = load ptr, ptr %81, align 8, !tbaa !33
  call void @free(ptr noundef %82) #4
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %83) #4
  br label %84

84:                                               ; preds = %42, %8
  ret void
}

declare void @ggml_gallocr_free(ptr noundef) #3

declare void @ggml_free(ptr noundef) #3

declare void @ggml_hash_set_free(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = { "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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTS18ggml_backend_sched", !13, i64 0, !13, i64 1, !10, i64 4, !7, i64 8, !7, i64 136, !6, i64 264, !14, i64 272, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !16, i64 344, !6, i64 424, !10, i64 432, !10, i64 436, !10, i64 440, !10, i64 444, !7, i64 448, !7, i64 960, !10, i64 1040, !6, i64 1048, !6, i64 1056, !6, i64 1064, !6, i64 1072, !15, i64 1080, !10, i64 1088}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTS13ggml_hash_set", !15, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ZTS11ggml_cgraph", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !14, i64 48, !17, i64 72}
!17 = !{!"_ZTS22ggml_cgraph_eval_order", !7, i64 0}
!18 = !{!12, !10, i64 440}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}
!22 = !{!12, !6, i64 264}
!23 = !{!12, !6, i64 1048}
!24 = !{!12, !6, i64 424}
!25 = !{!12, !6, i64 296}
!26 = !{!12, !6, i64 304}
!27 = !{!12, !6, i64 312}
!28 = !{!12, !6, i64 320}
!29 = !{!12, !6, i64 328}
!30 = !{!12, !6, i64 336}
!31 = !{!12, !6, i64 1072}
!32 = !{!12, !6, i64 360}
!33 = !{!12, !6, i64 384}


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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @ggml_backend_event_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @ggml_backend_sched_free(ptr noundef %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %47, label %.preheader25

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

.preheader.lr.ph:                                 ; preds = %.preheader25
  %6 = getelementptr inbounds i8, ptr %0, i64 440
  %7 = getelementptr inbounds i8, ptr %0, i64 448
  %8 = load i32, ptr %6, align 8, !tbaa !16
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.preheader, label %._crit_edge28

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %10 = phi i32 [ %38, %._crit_edge ], [ %4, %.preheader.lr.ph ]
  %11 = phi i32 [ %39, %._crit_edge ], [ %8, %.preheader.lr.ph ]
  %indvars.iv31 = phi i64 [ %indvars.iv.next32, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

._crit_edge28:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %.preheader25
  %13 = getelementptr inbounds i8, ptr %0, i64 264
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  tail call void @ggml_gallocr_free(ptr noundef %14)
  %15 = getelementptr inbounds i8, ptr %0, i64 1048
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  tail call void @ggml_free(ptr noundef %16)
  %17 = getelementptr inbounds i8, ptr %0, i64 272
  tail call void @ggml_hash_set_free(ptr noundef nonnull %17)
  %18 = getelementptr inbounds i8, ptr %0, i64 424
  %19 = load ptr, ptr %18, align 8, !tbaa !19
  tail call void @free(ptr noundef %19) #3
  %20 = getelementptr inbounds i8, ptr %0, i64 296
  %21 = load ptr, ptr %20, align 8, !tbaa !20
  tail call void @free(ptr noundef %21) #3
  %22 = getelementptr inbounds i8, ptr %0, i64 304
  %23 = load ptr, ptr %22, align 8, !tbaa !21
  tail call void @free(ptr noundef %23) #3
  %24 = getelementptr inbounds i8, ptr %0, i64 312
  %25 = load ptr, ptr %24, align 8, !tbaa !22
  tail call void @free(ptr noundef %25) #3
  %26 = getelementptr inbounds i8, ptr %0, i64 320
  %27 = load ptr, ptr %26, align 8, !tbaa !23
  tail call void @free(ptr noundef %27) #3
  %28 = getelementptr inbounds i8, ptr %0, i64 328
  %29 = load ptr, ptr %28, align 8, !tbaa !24
  tail call void @free(ptr noundef %29) #3
  %30 = getelementptr inbounds i8, ptr %0, i64 336
  %31 = load ptr, ptr %30, align 8, !tbaa !25
  tail call void @free(ptr noundef %31) #3
  %32 = getelementptr inbounds i8, ptr %0, i64 1072
  %33 = load ptr, ptr %32, align 8, !tbaa !26
  tail call void @free(ptr noundef %33) #3
  %34 = getelementptr inbounds i8, ptr %0, i64 360
  %35 = load ptr, ptr %34, align 8, !tbaa !27
  tail call void @free(ptr noundef %35) #3
  %36 = getelementptr inbounds i8, ptr %0, i64 384
  %37 = load ptr, ptr %36, align 8, !tbaa !28
  tail call void @free(ptr noundef %37) #3
  tail call void @free(ptr noundef nonnull %0) #3
  br label %47

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %38 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %10, %.preheader ]
  %39 = phi i32 [ %44, %._crit_edge.loopexit ], [ %11, %.preheader ]
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %40 = sext i32 %38 to i64
  %41 = icmp slt i64 %indvars.iv.next32, %40
  br i1 %41, label %.preheader, label %._crit_edge28, !llvm.loop !29

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %42 = getelementptr inbounds [16 x [4 x ptr]], ptr %7, i64 0, i64 %indvars.iv31, i64 %indvars.iv
  %43 = load ptr, ptr %42, align 8, !tbaa !32
  tail call void @ggml_backend_event_free(ptr noundef %43)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %44 = load i32, ptr %6, align 8, !tbaa !16
  %45 = sext i32 %44 to i64
  %46 = icmp slt i64 %indvars.iv.next, %45
  br i1 %46, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !33

47:                                               ; preds = %1, %._crit_edge28
  ret void
}

declare void @ggml_gallocr_free(ptr noundef) local_unnamed_addr #2

declare void @ggml_free(ptr noundef) local_unnamed_addr #2

declare void @ggml_hash_set_free(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 }

!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 4}
!6 = !{!"_ZTS18ggml_backend_sched", !7, i64 0, !7, i64 1, !10, i64 4, !8, i64 8, !8, i64 136, !11, i64 264, !12, i64 272, !11, i64 296, !11, i64 304, !11, i64 312, !11, i64 320, !11, i64 328, !11, i64 336, !14, i64 344, !11, i64 424, !10, i64 432, !10, i64 436, !10, i64 440, !10, i64 444, !8, i64 448, !8, i64 960, !10, i64 1040, !11, i64 1048, !11, i64 1056, !11, i64 1064, !11, i64 1072, !13, i64 1080, !10, i64 1088}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"_ZTS13ggml_hash_set", !13, i64 0, !11, i64 8, !11, i64 16}
!13 = !{!"long", !8, i64 0}
!14 = !{!"_ZTS11ggml_cgraph", !10, i64 0, !10, i64 4, !10, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !12, i64 48, !15, i64 72}
!15 = !{!"_ZTS22ggml_cgraph_eval_order", !8, i64 0}
!16 = !{!6, !10, i64 440}
!17 = !{!6, !11, i64 264}
!18 = !{!6, !11, i64 1048}
!19 = !{!6, !11, i64 424}
!20 = !{!6, !11, i64 296}
!21 = !{!6, !11, i64 304}
!22 = !{!6, !11, i64 312}
!23 = !{!6, !11, i64 320}
!24 = !{!6, !11, i64 328}
!25 = !{!6, !11, i64 336}
!26 = !{!6, !11, i64 1072}
!27 = !{!6, !11, i64 360}
!28 = !{!6, !11, i64 384}
!29 = distinct !{!29, !30, !31}
!30 = !{!"llvm.loop.mustprogress"}
!31 = !{!"llvm.loop.unswitch.partial.disable"}
!32 = !{!11, !11, i64 0}
!33 = distinct !{!33, !30}


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