; 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.14 = external hidden unnamed_addr constant [79 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [38 x i8], align 1
@__func__.ggml_backend_tensor_copy = external hidden unnamed_addr constant [25 x i8], align 1

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

declare i64 @ggml_nbytes(ptr noundef) #1

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local zeroext i1 @ggml_backend_buffer_is_host(ptr noundef) #2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @ggml_backend_tensor_copy(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call noundef zeroext i1 @_ZL20ggml_are_same_layoutPK11ggml_tensorS1_(ptr noundef %7, ptr noundef %8)
  br i1 %9, label %11, label %10

10:                                               ; preds = %2
  call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef @.str.1, i32 noundef 371, ptr noundef @.str.2, ptr noundef @.str.14) #7
  unreachable

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp eq ptr %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  br label %66

16:                                               ; preds = %11
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ggml_tensor, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = call zeroext i1 @ggml_backend_buffer_is_host(ptr noundef %19)
  br i1 %20, label %21, label %28

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ggml_tensor, ptr %23, i32 0, i32 10
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = call i64 @ggml_nbytes(ptr noundef %26)
  call void @ggml_backend_tensor_set(ptr noundef %22, ptr noundef %25, i64 noundef 0, i64 noundef %27)
  br label %66

28:                                               ; preds = %16
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ggml_tensor, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = call zeroext i1 @ggml_backend_buffer_is_host(ptr noundef %31)
  br i1 %32, label %33, label %40

33:                                               ; preds = %28
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ggml_tensor, ptr %35, i32 0, i32 10
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = call i64 @ggml_nbytes(ptr noundef %38)
  call void @ggml_backend_tensor_get(ptr noundef %34, ptr noundef %37, i64 noundef 0, i64 noundef %39)
  br label %65

40:                                               ; preds = %28
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = call zeroext i1 @ggml_backend_buffer_copy_tensor(ptr noundef %41, ptr noundef %42)
  br i1 %43, label %64, label %44

44:                                               ; preds = %40
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ggml_tensor, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = call ptr @ggml_backend_buffer_name(ptr noundef %47)
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ggml_tensor, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = call ptr @ggml_backend_buffer_name(ptr noundef %51)
  call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 1, ptr noundef @.str.15, ptr noundef @__func__.ggml_backend_tensor_copy, ptr noundef %48, ptr noundef %52)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #8
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = call i64 @ggml_nbytes(ptr noundef %53)
  store i64 %54, ptr %5, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #8
  %55 = load i64, ptr %5, align 8, !tbaa !16
  %56 = call noalias ptr @malloc(i64 noundef %55) #9
  store ptr %56, ptr %6, align 8, !tbaa !5
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load i64, ptr %5, align 8, !tbaa !16
  call void @ggml_backend_tensor_get(ptr noundef %57, ptr noundef %58, i64 noundef 0, i64 noundef %59)
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i64, ptr %5, align 8, !tbaa !16
  call void @ggml_backend_tensor_set(ptr noundef %60, ptr noundef %61, i64 noundef 0, i64 noundef %62)
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %63) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #8
  br label %64

64:                                               ; preds = %44, %40
  br label %65

65:                                               ; preds = %64, %33
  br label %66

66:                                               ; preds = %65, %21, %15
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL20ggml_are_same_layoutPK11ggml_tensorS1_(ptr noundef, ptr noundef) #4

declare void @ggml_log_internal(i32 noundef, ptr noundef, ...) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #5

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #4 = { 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 #5 = { nounwind allocsize(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 #6 = { 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 #7 = { noreturn }
attributes #8 = { nounwind }
attributes #9 = { nounwind allocsize(0) }

!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 = !{!14, !14, i64 0}


; 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.14 = external hidden unnamed_addr constant [79 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [38 x i8], align 1
@__func__.ggml_backend_tensor_copy = external hidden unnamed_addr constant [25 x i8], align 1

declare i64 @ggml_nbytes(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local ptr @ggml_backend_buffer_name(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 zeroext i1 @ggml_backend_buffer_is_host(ptr noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @ggml_backend_tensor_copy(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call noundef zeroext i1 @_ZL20ggml_are_same_layoutPK11ggml_tensorS1_(ptr noundef %0, ptr noundef %1)
  br i1 %3, label %5, label %4

4:                                                ; preds = %2
  tail call void (ptr, i32, ptr, ...) @ggml_abort(ptr noundef nonnull @.str.1, i32 noundef 371, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.14) #6
  unreachable

5:                                                ; preds = %2
  %6 = icmp eq ptr %0, %1
  br i1 %6, label %32, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = tail call zeroext i1 @ggml_backend_buffer_is_host(ptr noundef %9)
  br i1 %10, label %11, label %15

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 248
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = tail call i64 @ggml_nbytes(ptr noundef nonnull %0)
  tail call void @ggml_backend_tensor_set(ptr noundef %1, ptr noundef %13, i64 noundef 0, i64 noundef %14)
  br label %32

15:                                               ; preds = %7
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = tail call zeroext i1 @ggml_backend_buffer_is_host(ptr noundef %17)
  br i1 %18, label %19, label %23

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %1, i64 248
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = tail call i64 @ggml_nbytes(ptr noundef nonnull %0)
  tail call void @ggml_backend_tensor_get(ptr noundef nonnull %0, ptr noundef %21, i64 noundef 0, i64 noundef %22)
  br label %32

23:                                               ; preds = %15
  %24 = tail call zeroext i1 @ggml_backend_buffer_copy_tensor(ptr noundef nonnull %0, ptr noundef nonnull %1)
  br i1 %24, label %32, label %25

25:                                               ; preds = %23
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = tail call ptr @ggml_backend_buffer_name(ptr noundef %26)
  %28 = load ptr, ptr %16, align 8, !tbaa !5
  %29 = tail call ptr @ggml_backend_buffer_name(ptr noundef %28)
  tail call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 1, ptr noundef nonnull @.str.15, ptr noundef nonnull @__func__.ggml_backend_tensor_copy, ptr noundef %27, ptr noundef %29)
  %30 = tail call i64 @ggml_nbytes(ptr noundef nonnull %0)
  %31 = tail call noalias ptr @malloc(i64 noundef %30) #7
  tail call void @ggml_backend_tensor_get(ptr noundef nonnull %0, ptr noundef %31, i64 noundef 0, i64 noundef %30)
  tail call void @ggml_backend_tensor_set(ptr noundef nonnull %1, ptr noundef %31, i64 noundef 0, i64 noundef %30)
  tail call void @free(ptr noundef %31) #8
  br label %32

32:                                               ; preds = %19, %25, %23, %5, %11
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL20ggml_are_same_layoutPK11ggml_tensorS1_(ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @ggml_log_internal(i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

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

attributes #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 = { 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 #4 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #5 = { 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 #6 = { noreturn }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { 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 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}


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