; LLVM IR from nem0/lumixengine_net :: external/enet (peer)

; 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._ENetOutgoingCommand = type { %struct._ENetListNode, i16, i16, i32, i32, i32, i32, i16, i16, %union._ENetProtocol, ptr }
%struct._ENetListNode = type { ptr, ptr }
%union._ENetProtocol = type { %struct._ENetProtocolConnect }
%struct._ENetProtocolConnect = type { %struct._ENetProtocolCommandHeader, i16, i8, i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct._ENetProtocolCommandHeader = type { i8, i8, i16 }
%struct._ENetPacket = type { i64, i32, ptr, i64, ptr, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local ptr @enet_peer_queue_outgoing_command(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i16 noundef zeroext %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i16, align 2
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i16 %4, ptr %11, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %14 = call ptr @enet_malloc(i64 noundef 96)
  store ptr %14, ptr %12, align 8, !tbaa !5
  %15 = load ptr, ptr %12, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %5
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %42

18:                                               ; preds = %5
  %19 = load ptr, ptr %12, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._ENetOutgoingCommand, ptr %19, i32 0, i32 9
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %20, ptr align 1 %21, i64 48, i1 false), !tbaa.struct !13
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._ENetOutgoingCommand, ptr %23, i32 0, i32 6
  store i32 %22, ptr %24, align 8, !tbaa !15
  %25 = load i16, ptr %11, align 2, !tbaa !11
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._ENetOutgoingCommand, ptr %26, i32 0, i32 7
  store i16 %25, ptr %27, align 4, !tbaa !18
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._ENetOutgoingCommand, ptr %29, i32 0, i32 10
  store ptr %28, ptr %30, align 8, !tbaa !19
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %38

33:                                               ; preds = %18
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._ENetPacket, ptr %34, i32 0, i32 0
  %36 = load i64, ptr %35, align 8, !tbaa !20
  %37 = add i64 %36, 1
  store i64 %37, ptr %35, align 8, !tbaa !20
  br label %38

38:                                               ; preds = %33, %18
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  call void @enet_peer_setup_outgoing_command(ptr noundef %39, ptr noundef %40)
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %41, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %42

42:                                               ; preds = %38, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %43 = load ptr, ptr %6, align 8
  ret ptr %43
}

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

declare ptr @enet_malloc(i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @enet_peer_setup_outgoing_command(ptr noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{i64 0, i64 48, !14}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !10, i64 32}
!16 = !{!"_ENetOutgoingCommand", !17, i64 0, !12, i64 16, !12, i64 18, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !12, i64 36, !12, i64 38, !7, i64 40, !6, i64 88}
!17 = !{!"_ENetListNode", !6, i64 0, !6, i64 8}
!18 = !{!16, !12, i64 36}
!19 = !{!16, !6, i64 88}
!20 = !{!21, !22, i64 0}
!21 = !{!"_ENetPacket", !22, i64 0, !10, i64 8, !6, i64 16, !22, i64 24, !6, i64 32, !6, i64 40}
!22 = !{!"long", !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"

; Function Attrs: nounwind uwtable
define dso_local ptr @enet_peer_queue_outgoing_command(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, i32 noundef %3, i16 noundef zeroext %4) local_unnamed_addr #0 {
  %6 = tail call ptr @enet_malloc(i64 noundef 96) #3
  %7 = icmp eq ptr %6, null
  br i1 %7, label %17, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %6, i64 40
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %9, ptr noundef nonnull align 1 dereferenceable(48) %1, i64 48, i1 false), !tbaa.struct !5
  %10 = getelementptr inbounds i8, ptr %6, i64 32
  store i32 %3, ptr %10, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %6, i64 36
  store i16 %4, ptr %11, align 4, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %6, i64 88
  store ptr %2, ptr %12, align 8, !tbaa !16
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %16, label %13

13:                                               ; preds = %8
  %14 = load i64, ptr %2, align 8, !tbaa !17
  %15 = add i64 %14, 1
  store i64 %15, ptr %2, align 8, !tbaa !17
  br label %16

16:                                               ; preds = %13, %8
  tail call void @enet_peer_setup_outgoing_command(ptr noundef %0, ptr noundef nonnull %6)
  br label %17

17:                                               ; preds = %5, %16
  ret ptr %6
}

declare ptr @enet_malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @enet_peer_setup_outgoing_command(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { 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 = { "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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 48, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !14, i64 32}
!10 = !{!"_ENetOutgoingCommand", !11, i64 0, !13, i64 16, !13, i64 18, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !13, i64 36, !13, i64 38, !7, i64 40, !12, i64 88}
!11 = !{!"_ENetListNode", !12, i64 0, !12, i64 8}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!10, !13, i64 36}
!16 = !{!10, !12, i64 88}
!17 = !{!18, !19, i64 0}
!18 = !{!"_ENetPacket", !19, i64 0, !14, i64 8, !12, i64 16, !19, i64 24, !12, i64 32, !12, i64 40}
!19 = !{!"long", !7, i64 0}


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