; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

7:                                                ; preds = %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.ggml_backend_sched, ptr %8, i32 0, i32 6
  call void @ggml_hash_set_reset(ptr noundef %9)
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ggml_backend_sched, ptr %10, i32 0, i32 7
  %12 = load ptr, ptr %11, align 8, !tbaa !19
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ggml_backend_sched, ptr %13, i32 0, i32 6
  %15 = getelementptr inbounds %struct.ggml_hash_set, ptr %14, i32 0, i32 0
  %16 = load i64, ptr %15, align 8, !tbaa !20
  %17 = mul i64 %16, 4
  call void @llvm.memset.p0.i64(ptr align 4 %12, i8 -1, i64 %17, i1 false)
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ggml_backend_sched, ptr %18, i32 0, i32 8
  %20 = load ptr, ptr %19, align 8, !tbaa !21
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ggml_backend_sched, ptr %21, i32 0, i32 6
  %23 = getelementptr inbounds %struct.ggml_hash_set, ptr %22, i32 0, i32 0
  %24 = load i64, ptr %23, align 8, !tbaa !20
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ggml_backend_sched, ptr %25, i32 0, i32 2
  %27 = load i32, ptr %26, align 4, !tbaa !22
  %28 = sext i32 %27 to i64
  %29 = mul i64 %24, %28
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ggml_backend_sched, ptr %30, i32 0, i32 17
  %32 = load i32, ptr %31, align 8, !tbaa !23
  %33 = sext i32 %32 to i64
  %34 = mul i64 %29, %33
  %35 = mul i64 %34, 8
  call void @llvm.memset.p0.i64(ptr align 8 %20, i8 0, i64 %35, i1 false)
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ggml_backend_sched, ptr %36, i32 0, i32 0
  store i8 1, ptr %37, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %7, %1
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ggml_backend_sched, ptr %39, i32 0, i32 1
  store i8 0, ptr %40, align 1, !tbaa !24
  ret void
}

declare void @ggml_hash_set_reset(ptr noundef) #2

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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" }

!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, !6, i64 296}
!20 = !{!10, !14, i64 272}
!21 = !{!10, !6, i64 304}
!22 = !{!10, !12, i64 4}
!23 = !{!10, !12, i64 440}
!24 = !{!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 nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 272
  tail call void @ggml_hash_set_reset(ptr noundef nonnull %5)
  %6 = getelementptr inbounds i8, ptr %0, i64 296
  %7 = load ptr, ptr %6, align 8, !tbaa !18
  %8 = load i64, ptr %5, align 8, !tbaa !19
  %9 = shl i64 %8, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %7, i8 -1, i64 %9, i1 false)
  %10 = getelementptr inbounds i8, ptr %0, i64 304
  %11 = load ptr, ptr %10, align 8, !tbaa !20
  %12 = load i64, ptr %5, align 8, !tbaa !19
  %13 = getelementptr inbounds i8, ptr %0, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !21
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %0, i64 440
  %17 = load i32, ptr %16, align 8, !tbaa !22
  %18 = sext i32 %17 to i64
  %19 = shl i64 %12, 3
  %20 = mul i64 %19, %15
  %21 = mul i64 %20, %18
  tail call void @llvm.memset.p0.i64(ptr align 8 %11, i8 0, i64 %21, i1 false)
  store i8 1, ptr %0, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %4, %1
  %23 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 0, ptr %23, align 1, !tbaa !23
  ret void
}

declare void @ggml_hash_set_reset(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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" }

!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, !11, i64 296}
!19 = !{!6, !13, i64 272}
!20 = !{!6, !11, i64 304}
!21 = !{!6, !10, i64 4}
!22 = !{!6, !10, i64 440}
!23 = !{!6, !7, i64 1}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass