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

@.str.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [77 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
define dso_local zeroext i1 @ggml_backend_sched_reserve(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i1, align 1
  %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 6
  %8 = getelementptr inbounds %struct.ggml_hash_set, ptr %7, i32 0, i32 0
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = trunc i64 %9 to i32
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ggml_cgraph, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !17
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ggml_cgraph, ptr %14, i32 0, i32 2
  %16 = load i32, ptr %15, align 8, !tbaa !18
  %17 = add nsw i32 %13, %16
  %18 = icmp sge i32 %10, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %2
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.1, i32 noundef 1543, ptr noundef @.str.2, ptr noundef @.str.26) #3
  unreachable

20:                                               ; preds = %2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZL30ggml_backend_sched_split_graphP18ggml_backend_schedP11ggml_cgraph(ptr noundef %21, ptr noundef %22)
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ggml_backend_sched_synchronize(ptr noundef %23)
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ggml_backend_sched, ptr %24, i32 0, i32 5
  %26 = load ptr, ptr %25, align 8, !tbaa !19
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ggml_backend_sched, ptr %27, i32 0, i32 13
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ggml_backend_sched, ptr %29, i32 0, i32 9
  %31 = load ptr, ptr %30, align 8, !tbaa !20
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ggml_backend_sched, ptr %32, i32 0, i32 10
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = call zeroext i1 @ggml_gallocr_reserve_n(ptr noundef %26, ptr noundef %28, ptr noundef %31, ptr noundef %34)
  br i1 %35, label %37, label %36

36:                                               ; preds = %20
  store i1 false, ptr %3, align 1
  br label %39

37:                                               ; preds = %20
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ggml_backend_sched_reset(ptr noundef %38)
  store i1 true, ptr %3, align 1
  br label %39

39:                                               ; preds = %37, %36
  %40 = load i1, ptr %3, align 1
  ret i1 %40
}

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

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

declare zeroext i1 @ggml_gallocr_reserve_n(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

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 = { "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 = { 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, !14, i64 272}
!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 = !{!15, !12, i64 4}
!18 = !{!15, !12, i64 8}
!19 = !{!10, !6, i64 264}
!20 = !{!10, !6, i64 312}
!21 = !{!10, !6, i64 320}


; 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.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [77 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
declare dso_local void @ggml_backend_sched_reset(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @ggml_backend_sched_reserve(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 272
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = trunc i64 %4 to i32
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !16
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !17
  %10 = add nsw i32 %9, %7
  %.not = icmp sgt i32 %10, %5
  br i1 %.not, label %11, label %12

11:                                               ; preds = %2
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.1, i32 noundef 1543, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.26) #3
  unreachable

12:                                               ; preds = %2
  tail call void @_ZL30ggml_backend_sched_split_graphP18ggml_backend_schedP11ggml_cgraph(ptr noundef nonnull %0, ptr noundef nonnull %1)
  tail call void @ggml_backend_sched_synchronize(ptr noundef nonnull %0)
  %13 = getelementptr inbounds i8, ptr %0, i64 264
  %14 = load ptr, ptr %13, align 8, !tbaa !18
  %15 = getelementptr inbounds i8, ptr %0, i64 344
  %16 = getelementptr inbounds i8, ptr %0, i64 312
  %17 = load ptr, ptr %16, align 8, !tbaa !19
  %18 = getelementptr inbounds i8, ptr %0, i64 320
  %19 = load ptr, ptr %18, align 8, !tbaa !20
  %20 = tail call zeroext i1 @ggml_gallocr_reserve_n(ptr noundef %14, ptr noundef nonnull %15, ptr noundef %17, ptr noundef %19)
  br i1 %20, label %21, label %22

21:                                               ; preds = %12
  tail call void @ggml_backend_sched_reset(ptr noundef nonnull %0)
  br label %22

22:                                               ; preds = %12, %21
  ret i1 %20
}

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

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

declare zeroext i1 @ggml_gallocr_reserve_n(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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 = { "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 = { 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, !13, i64 272}
!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 = !{!14, !10, i64 4}
!17 = !{!14, !10, i64 8}
!18 = !{!6, !11, i64 264}
!19 = !{!6, !11, i64 312}
!20 = !{!6, !11, i64 320}


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