; 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: mustprogress uwtable
declare dso_local void @ggml_backend_sched_reset(ptr noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local zeroext i1 @ggml_backend_sched_alloc_graph(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local i32 @ggml_backend_sched_graph_compute_async(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ggml_backend_sched, ptr %6, i32 0, i32 0
  %8 = load i8, ptr %7, align 8, !tbaa !9, !range !17, !noundef !18
  %9 = trunc i8 %8 to i1
  br i1 %9, label %17, label %10

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ggml_backend_sched, ptr %11, i32 0, i32 1
  %13 = load i8, ptr %12, align 1, !tbaa !19, !range !17, !noundef !18
  %14 = trunc i8 %13 to i1
  br i1 %14, label %17, label %15

15:                                               ; preds = %10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ggml_backend_sched_reset(ptr noundef %16)
  br label %17

17:                                               ; preds = %15, %10, %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ggml_backend_sched, ptr %18, i32 0, i32 1
  %20 = load i8, ptr %19, align 1, !tbaa !19, !range !17, !noundef !18
  %21 = trunc i8 %20 to i1
  br i1 %21, label %28, label %22

22:                                               ; preds = %17
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call zeroext i1 @ggml_backend_sched_alloc_graph(ptr noundef %23, ptr noundef %24)
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 -2, ptr %3, align 4
  br label %31

27:                                               ; preds = %22
  br label %28

28:                                               ; preds = %27, %17
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call noundef i32 @_ZL33ggml_backend_sched_compute_splitsP18ggml_backend_sched(ptr noundef %29)
  store i32 %30, ptr %3, align 4
  br label %31

31:                                               ; preds = %28, %26
  %32 = load i32, ptr %3, align 4
  ret i32 %32
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL33ggml_backend_sched_compute_splitsP18ggml_backend_sched(ptr noundef) #0

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

!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 = !{!"_ZTS18ggml_backend_sched", !11, i64 0, !11, i64 1, !12, i64 4, !7, i64 8, !7, i64 136, !6, i64 264, !13, i64 272, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !15, i64 344, !6, i64 424, !12, i64 432, !12, i64 436, !12, i64 440, !12, i64 444, !7, i64 448, !7, i64 960, !12, i64 1040, !6, i64 1048, !6, i64 1056, !6, i64 1064, !6, i64 1072, !14, i64 1080, !12, i64 1088}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTS13ggml_hash_set", !14, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTS11ggml_cgraph", !12, i64 0, !12, i64 4, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !13, i64 48, !16, i64 72}
!16 = !{!"_ZTS22ggml_cgraph_eval_order", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!10, !11, i64 1}


; 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 uwtable
declare dso_local void @ggml_backend_sched_reset(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local zeroext i1 @ggml_backend_sched_alloc_graph(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @ggml_backend_sched_graph_compute_async(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i8, ptr %0, align 8, !tbaa !5, !range !16, !noundef !17
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %10, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 1
  %7 = load i8, ptr %6, align 1, !tbaa !18, !range !16, !noundef !17
  %8 = trunc nuw i8 %7 to i1
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  tail call void @ggml_backend_sched_reset(ptr noundef nonnull %0)
  br label %10

10:                                               ; preds = %9, %5, %2
  %11 = getelementptr inbounds i8, ptr %0, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !18, !range !16, !noundef !17
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %16, label %14

14:                                               ; preds = %10
  %15 = tail call zeroext i1 @ggml_backend_sched_alloc_graph(ptr noundef nonnull %0, ptr noundef %1)
  br i1 %15, label %16, label %18

16:                                               ; preds = %14, %10
  %17 = tail call noundef i32 @_ZL33ggml_backend_sched_compute_splitsP18ggml_backend_sched(ptr noundef nonnull %0)
  br label %18

18:                                               ; preds = %14, %16
  %.0 = phi i32 [ %17, %16 ], [ -2, %14 ]
  ret i32 %.0
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL33ggml_backend_sched_compute_splitsP18ggml_backend_sched(ptr noundef) local_unnamed_addr #0

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

!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 0}
!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 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!6, !7, i64 1}


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