; 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_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.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [153 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i64 @ggml_backend_buffer_get_size(ptr noundef) #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local i32 @ggml_backend_buffer_init_tensor(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local i64 @ggml_backend_buffer_get_alloc_size(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local i32 @ggml_backend_tensor_alloc(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ggml_tensor, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp eq ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %3
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.1, i32 noundef 1658, ptr noundef @.str.2, ptr noundef @.str.30) #3
  unreachable

12:                                               ; preds = %3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ggml_tensor, ptr %13, i32 0, i32 10
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = icmp eq ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %12
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.1, i32 noundef 1659, ptr noundef @.str.2, ptr noundef @.str.34) #3
  unreachable

18:                                               ; preds = %12
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ggml_tensor, ptr %19, i32 0, i32 8
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = icmp eq ptr %21, null
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.1, i32 noundef 1660, ptr noundef @.str.2, ptr noundef @.str.35) #3
  unreachable

24:                                               ; preds = %18
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call ptr @ggml_backend_buffer_get_base(ptr noundef %26)
  %28 = icmp uge ptr %25, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %24
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.1, i32 noundef 1661, ptr noundef @.str.2, ptr noundef @.str.36) #3
  unreachable

30:                                               ; preds = %24
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = call i64 @ggml_backend_buffer_get_alloc_size(ptr noundef %32, ptr noundef %33)
  %35 = getelementptr inbounds i8, ptr %31, i64 %34
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = call ptr @ggml_backend_buffer_get_base(ptr noundef %36)
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = call i64 @ggml_backend_buffer_get_size(ptr noundef %38)
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  %41 = icmp ule ptr %35, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %30
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.1, i32 noundef 1663, ptr noundef @.str.2, ptr noundef @.str.37) #3
  unreachable

43:                                               ; preds = %30
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ggml_tensor, ptr %45, i32 0, i32 1
  store ptr %44, ptr %46, align 8, !tbaa !9
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ggml_tensor, ptr %48, i32 0, i32 10
  store ptr %47, ptr %49, align 8, !tbaa !15
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = call i32 @ggml_backend_buffer_init_tensor(ptr noundef %50, ptr noundef %51)
  ret i32 %52
}

attributes #0 = { mustprogress 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 #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 = { 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 #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, !6, i64 8}
!10 = !{!"_ZTS11ggml_tensor", !11, i64 0, !6, i64 8, !7, i64 16, !7, i64 48, !12, i64 80, !7, i64 84, !13, i64 148, !7, i64 152, !6, i64 232, !14, i64 240, !6, i64 248, !7, i64 256, !6, i64 320, !7, i64 328}
!11 = !{!"_ZTS9ggml_type", !7, i64 0}
!12 = !{!"_ZTS7ggml_op", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !6, i64 248}
!16 = !{!10, !6, i64 232}


; 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.30 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [153 x i8], align 1

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local i32 @ggml_backend_buffer_init_tensor(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local i64 @ggml_backend_buffer_get_alloc_size(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local i32 @ggml_backend_tensor_alloc(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %8, label %7

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

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %1, i64 248
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = icmp eq ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.1, i32 noundef 1659, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.34) #3
  unreachable

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %1, i64 232
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = icmp eq ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.1, i32 noundef 1660, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.35) #3
  unreachable

18:                                               ; preds = %13
  %19 = tail call ptr @ggml_backend_buffer_get_base(ptr noundef %0)
  %.not = icmp ugt ptr %19, %2
  br i1 %.not, label %20, label %21

20:                                               ; preds = %18
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.1, i32 noundef 1661, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.36) #3
  unreachable

21:                                               ; preds = %18
  %22 = tail call i64 @ggml_backend_buffer_get_alloc_size(ptr noundef %0, ptr noundef nonnull %1)
  %23 = getelementptr inbounds i8, ptr %2, i64 %22
  %24 = tail call ptr @ggml_backend_buffer_get_base(ptr noundef %0)
  %25 = tail call i64 @ggml_backend_buffer_get_size(ptr noundef %0)
  %26 = getelementptr inbounds i8, ptr %24, i64 %25
  %.not16 = icmp ugt ptr %23, %26
  br i1 %.not16, label %27, label %28

27:                                               ; preds = %21
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.1, i32 noundef 1663, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.37) #3
  unreachable

28:                                               ; preds = %21
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !14
  %29 = tail call i32 @ggml_backend_buffer_init_tensor(ptr noundef %0, ptr noundef nonnull %1)
  ret i32 %29
}

attributes #0 = { mustprogress 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 #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 = { 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 #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, !10, i64 8}
!6 = !{!"_ZTS11ggml_tensor", !7, i64 0, !10, i64 8, !8, i64 16, !8, i64 48, !11, i64 80, !8, i64 84, !12, i64 148, !8, i64 152, !10, i64 232, !13, i64 240, !10, i64 248, !8, i64 256, !10, i64 320, !8, i64 328}
!7 = !{!"_ZTS9ggml_type", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTS7ggml_op", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !10, i64 248}
!15 = !{!6, !10, i64 232}


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