; LLVM IR from ggml-org/ggml :: src/ggml-rpc (ggml-rpc)

; 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.std::pair.26" = type <{ %"struct.std::__detail::_Node_iterator.28", i8, [7 x i8] }>
%"struct.std::__detail::_Node_iterator.28" = type { %"struct.std::__detail::_Node_iterator_base.29" }
%"struct.std::__detail::_Node_iterator_base.29" = type { ptr }
%class.rpc_server = type { ptr, ptr, %"class.std::unordered_set" }
%"class.std::unordered_set" = type { %"class.std::_Hashtable.7" }
%"class.std::_Hashtable.7" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"struct.std::__detail::_Hash_node_base" = type { ptr }
%"struct.std::__detail::_Prime_rehash_policy" = type { float, i64 }
%struct.rpc_msg_alloc_buffer_req = type { i64 }
%struct.rpc_msg_alloc_buffer_rsp = type { i64, i64 }
%struct.ggml_backend_buffer = type { %struct.ggml_backend_buffer_i, ptr, ptr, i64, i32 }
%struct.ggml_backend_buffer_i = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str.7 = external hidden unnamed_addr constant [26 x i8], align 1
@__func__._ZN10rpc_server12alloc_bufferERK24rpc_msg_alloc_buffer_reqR24rpc_msg_alloc_buffer_rsp = external hidden unnamed_addr constant [13 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

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

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

declare ptr @ggml_backend_get_default_buffer_type(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10rpc_server12alloc_bufferERK24rpc_msg_alloc_buffer_reqR24rpc_msg_alloc_buffer_rsp(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef nonnull align 1 dereferenceable(8) %1, ptr noundef nonnull align 1 dereferenceable(16) %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %"struct.std::pair.26", 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
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %11 = getelementptr inbounds %class.rpc_server, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = call ptr @ggml_backend_get_default_buffer_type(ptr noundef %12)
  store ptr %13, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.rpc_msg_alloc_buffer_req, ptr %15, i32 0, i32 0
  %17 = load i64, ptr %16, align 1, !tbaa !17
  %18 = call ptr @ggml_backend_buft_alloc_buffer(ptr noundef %14, i64 noundef %17)
  store ptr %18, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.rpc_msg_alloc_buffer_rsp, ptr %19, i32 0, i32 0
  store i64 0, ptr %20, align 1, !tbaa !19
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.rpc_msg_alloc_buffer_rsp, ptr %21, i32 0, i32 1
  store i64 0, ptr %22, align 1, !tbaa !21
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %41

25:                                               ; preds = %3
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = ptrtoint ptr %26 to i64
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.rpc_msg_alloc_buffer_rsp, ptr %28, i32 0, i32 0
  store i64 %27, ptr %29, align 1, !tbaa !19
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ggml_backend_buffer, ptr %30, i32 0, i32 3
  %32 = load i64, ptr %31, align 8, !tbaa !22
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.rpc_msg_alloc_buffer_rsp, ptr %33, i32 0, i32 1
  store i64 %32, ptr %34, align 1, !tbaa !21
  %35 = getelementptr inbounds %class.rpc_server, ptr %10, i32 0, i32 2
  %36 = call { ptr, i8 } @_ZNSt13unordered_setIP19ggml_backend_bufferSt4hashIS1_ESt8equal_toIS1_ESaIS1_EE6insertERKS1_(ptr noundef nonnull align 8 dereferenceable(56) %35, ptr noundef nonnull align 8 dereferenceable(8) %8)
  %37 = getelementptr inbounds { ptr, i8 }, ptr %9, i32 0, i32 0
  %38 = extractvalue { ptr, i8 } %36, 0
  store ptr %38, ptr %37, align 8
  %39 = getelementptr inbounds { ptr, i8 }, ptr %9, i32 0, i32 1
  %40 = extractvalue { ptr, i8 } %36, 1
  store i8 %40, ptr %39, align 8
  br label %45

41:                                               ; preds = %3
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.rpc_msg_alloc_buffer_req, ptr %42, i32 0, i32 0
  %44 = load i64, ptr %43, align 1, !tbaa !17
  call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 4, ptr noundef @.str.7, ptr noundef @__func__._ZN10rpc_server12alloc_bufferERK24rpc_msg_alloc_buffer_reqR24rpc_msg_alloc_buffer_rsp, i64 noundef %44)
  br label %45

45:                                               ; preds = %41, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

declare ptr @ggml_backend_buft_alloc_buffer(ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i8 } @_ZNSt13unordered_setIP19ggml_backend_bufferSt4hashIS1_ESt8equal_toIS1_ESaIS1_EE6insertERKS1_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

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 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS10rpc_server", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"_ZTSSt13unordered_setIP19ggml_backend_bufferSt4hashIS1_ESt8equal_toIS1_ESaIS1_EE", !12, i64 0}
!12 = !{!"_ZTSSt10_HashtableIP19ggml_backend_bufferS1_SaIS1_ENSt8__detail9_IdentityESt8equal_toIS1_ESt4hashIS1_ENS3_18_Mod_range_hashingENS3_20_Default_ranged_hashENS3_20_Prime_rehash_policyENS3_17_Hashtable_traitsILb0ELb1ELb1EEEE", !6, i64 0, !13, i64 8, !14, i64 16, !13, i64 24, !15, i64 32, !6, i64 48}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_ZTSNSt8__detail15_Hash_node_baseE", !6, i64 0}
!15 = !{!"_ZTSNSt8__detail20_Prime_rehash_policyE", !16, i64 0, !13, i64 8}
!16 = !{!"float", !7, i64 0}
!17 = !{!18, !13, i64 0}
!18 = !{!"_ZTS24rpc_msg_alloc_buffer_req", !13, i64 0}
!19 = !{!20, !13, i64 0}
!20 = !{!"_ZTS24rpc_msg_alloc_buffer_rsp", !13, i64 0, !13, i64 8}
!21 = !{!20, !13, i64 8}
!22 = !{!23, !13, i64 88}
!23 = !{!"_ZTS19ggml_backend_buffer", !24, i64 0, !6, i64 72, !6, i64 80, !13, i64 88, !25, i64 96}
!24 = !{!"_ZTS21ggml_backend_buffer_i", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!25 = !{!"_ZTS25ggml_backend_buffer_usage", !7, 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.7 = external hidden unnamed_addr constant [26 x i8], align 1
@__func__._ZN10rpc_server12alloc_bufferERK24rpc_msg_alloc_buffer_reqR24rpc_msg_alloc_buffer_rsp = external hidden unnamed_addr constant [13 x i8], align 1

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

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

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

declare ptr @ggml_backend_get_default_buffer_type(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10rpc_server12alloc_bufferERK24rpc_msg_alloc_buffer_reqR24rpc_msg_alloc_buffer_rsp(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr nocapture noundef nonnull readonly align 1 dereferenceable(8) %1, ptr nocapture noundef nonnull writeonly align 1 dereferenceable(16) %2) local_unnamed_addr #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = tail call ptr @ggml_backend_get_default_buffer_type(ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %7 = load i64, ptr %1, align 1, !tbaa !16
  %8 = tail call ptr @ggml_backend_buft_alloc_buffer(ptr noundef %6, i64 noundef %7)
  store ptr %8, ptr %4, align 8, !tbaa !18
  %.not = icmp eq ptr %8, null
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  br i1 %.not, label %16, label %9

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %2, i64 8
  %11 = ptrtoint ptr %8 to i64
  store i64 %11, ptr %2, align 1, !tbaa !19
  %12 = getelementptr inbounds i8, ptr %8, i64 88
  %13 = load i64, ptr %12, align 8, !tbaa !21
  store i64 %13, ptr %10, align 1, !tbaa !25
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = call { ptr, i8 } @_ZNSt13unordered_setIP19ggml_backend_bufferSt4hashIS1_ESt8equal_toIS1_ESaIS1_EE6insertERKS1_(ptr noundef nonnull align 8 dereferenceable(56) %14, ptr noundef nonnull align 8 dereferenceable(8) %4)
  br label %18

16:                                               ; preds = %3
  %17 = load i64, ptr %1, align 1, !tbaa !16
  tail call void (i32, ptr, ...) @ggml_log_internal(i32 noundef 4, ptr noundef nonnull @.str.7, ptr noundef nonnull @__func__._ZN10rpc_server12alloc_bufferERK24rpc_msg_alloc_buffer_reqR24rpc_msg_alloc_buffer_rsp, i64 noundef %17)
  br label %18

18:                                               ; preds = %16, %9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret void
}

declare ptr @ggml_backend_buft_alloc_buffer(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i8 } @_ZNSt13unordered_setIP19ggml_backend_bufferSt4hashIS1_ESt8equal_toIS1_ESaIS1_EE6insertERKS1_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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, !7, i64 0}
!6 = !{!"_ZTS10rpc_server", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt13unordered_setIP19ggml_backend_bufferSt4hashIS1_ESt8equal_toIS1_ESaIS1_EE", !11, i64 0}
!11 = !{!"_ZTSSt10_HashtableIP19ggml_backend_bufferS1_SaIS1_ENSt8__detail9_IdentityESt8equal_toIS1_ESt4hashIS1_ENS3_18_Mod_range_hashingENS3_20_Default_ranged_hashENS3_20_Prime_rehash_policyENS3_17_Hashtable_traitsILb0ELb1ELb1EEEE", !7, i64 0, !12, i64 8, !13, i64 16, !12, i64 24, !14, i64 32, !7, i64 48}
!12 = !{!"long", !8, i64 0}
!13 = !{!"_ZTSNSt8__detail15_Hash_node_baseE", !7, i64 0}
!14 = !{!"_ZTSNSt8__detail20_Prime_rehash_policyE", !15, i64 0, !12, i64 8}
!15 = !{!"float", !8, i64 0}
!16 = !{!17, !12, i64 0}
!17 = !{!"_ZTS24rpc_msg_alloc_buffer_req", !12, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!20, !12, i64 0}
!20 = !{!"_ZTS24rpc_msg_alloc_buffer_rsp", !12, i64 0, !12, i64 8}
!21 = !{!22, !12, i64 88}
!22 = !{!"_ZTS19ggml_backend_buffer", !23, i64 0, !7, i64 72, !7, i64 80, !12, i64 88, !24, i64 96}
!23 = !{!"_ZTS21ggml_backend_buffer_i", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64}
!24 = !{!"_ZTS25ggml_backend_buffer_usage", !8, i64 0}
!25 = !{!20, !12, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass