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

; 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._ENetHost = type <{ i32, %struct._ENetAddress, i32, i32, i32, i32, i32, i32, [4 x i8], ptr, i64, i64, i32, [4 x i8], %struct._ENetList, i32, [4 x i8], i64, i16, [32 x %union._ENetProtocol], [6 x i8], i64, [65 x %struct.ENetBuffer], i64, ptr, %struct._ENetCompressor, [2 x [4096 x i8]], %struct._ENetAddress, ptr, i64, i32, i32, i32, i32, ptr, i64, i64, i64, i64, i64 }>
%struct._ENetList = type { %struct._ENetListNode }
%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.ENetBuffer = type { ptr, i64 }
%struct._ENetCompressor = type { ptr, ptr, ptr, ptr }
%struct._ENetAddress = type { i32, i16 }
%struct._ENetPeer = type { %struct._ENetListNode, ptr, i16, i16, i32, i8, i8, %struct._ENetAddress, ptr, i32, ptr, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, %struct._ENetList, %struct._ENetList, %struct._ENetList, %struct._ENetList, %struct._ENetList, %struct._ENetList, i32, i16, i16, [32 x i32], i32, i64 }
%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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @enet_host_broadcast(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._ENetHost, ptr %8, i32 0, i32 9
  %10 = load ptr, ptr %9, align 8, !tbaa !10
  store ptr %10, ptr %7, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %32, %3
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._ENetHost, ptr %13, i32 0, i32 9
  %15 = load ptr, ptr %14, align 8, !tbaa !10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._ENetHost, ptr %16, i32 0, i32 10
  %18 = load i64, ptr %17, align 8, !tbaa !19
  %19 = getelementptr inbounds %struct._ENetPeer, ptr %15, i64 %18
  %20 = icmp ult ptr %12, %19
  br i1 %20, label %21, label %35

21:                                               ; preds = %11
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._ENetPeer, ptr %22, i32 0, i32 9
  %24 = load i32, ptr %23, align 8, !tbaa !20
  %25 = icmp ne i32 %24, 5
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  br label %32

27:                                               ; preds = %21
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load i8, ptr %5, align 1, !tbaa !9
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call i32 @enet_peer_send(ptr noundef %28, i8 noundef zeroext %29, ptr noundef %30)
  br label %32

32:                                               ; preds = %27, %26
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._ENetPeer, ptr %33, i32 1
  store ptr %34, ptr %7, align 8, !tbaa !5
  br label %11, !llvm.loop !22

35:                                               ; preds = %11
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._ENetPacket, ptr %36, i32 0, i32 0
  %38 = load i64, ptr %37, align 8, !tbaa !24
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %35
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  call void @enet_packet_destroy(ptr noundef %41)
  br label %42

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

declare i32 @enet_peer_send(ptr noundef, i8 noundef zeroext, ptr noundef) #2

declare void @enet_packet_destroy(ptr noundef) #2

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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 40}
!11 = !{!"_ENetHost", !12, i64 0, !13, i64 4, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !6, i64 40, !15, i64 48, !15, i64 56, !12, i64 64, !16, i64 72, !12, i64 88, !15, i64 96, !14, i64 104, !7, i64 106, !15, i64 1648, !7, i64 1656, !15, i64 2696, !6, i64 2704, !18, i64 2712, !7, i64 2744, !13, i64 10936, !6, i64 10944, !15, i64 10952, !12, i64 10960, !12, i64 10964, !12, i64 10968, !12, i64 10972, !6, i64 10976, !15, i64 10984, !15, i64 10992, !15, i64 11000, !15, i64 11008, !15, i64 11016}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ENetAddress", !12, i64 0, !14, i64 4}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ENetList", !17, i64 0}
!17 = !{!"_ENetListNode", !6, i64 0, !6, i64 8}
!18 = !{!"_ENetCompressor", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!19 = !{!11, !15, i64 48}
!20 = !{!21, !12, i64 56}
!21 = !{!"_ENetPeer", !17, i64 0, !6, i64 16, !14, i64 24, !14, i64 26, !12, i64 28, !7, i64 32, !7, i64 33, !13, i64 36, !6, i64 48, !12, i64 56, !6, i64 64, !15, i64 72, !12, i64 80, !12, i64 84, !12, i64 88, !12, i64 92, !12, i64 96, !12, i64 100, !12, i64 104, !12, i64 108, !12, i64 112, !12, i64 116, !12, i64 120, !12, i64 124, !12, i64 128, !12, i64 132, !12, i64 136, !12, i64 140, !12, i64 144, !12, i64 148, !12, i64 152, !12, i64 156, !12, i64 160, !12, i64 164, !12, i64 168, !12, i64 172, !12, i64 176, !12, i64 180, !12, i64 184, !12, i64 188, !12, i64 192, !12, i64 196, !12, i64 200, !12, i64 204, !12, i64 208, !12, i64 212, !12, i64 216, !14, i64 220, !16, i64 224, !16, i64 240, !16, i64 256, !16, i64 272, !16, i64 288, !16, i64 304, !12, i64 320, !14, i64 324, !14, i64 326, !7, i64 328, !12, i64 456, !15, i64 464}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!25, !15, i64 0}
!25 = !{!"_ENetPacket", !15, i64 0, !12, i64 8, !6, i64 16, !15, i64 24, !6, i64 32, !6, i64 40}


; 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"

%struct._ENetPeer = type { %struct._ENetListNode, ptr, i16, i16, i32, i8, i8, %struct._ENetAddress, ptr, i32, ptr, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, %struct._ENetList, %struct._ENetList, %struct._ENetList, %struct._ENetList, %struct._ENetList, %struct._ENetList, i32, i16, i16, [32 x i32], i32, i64 }
%struct._ENetListNode = type { ptr, ptr }
%struct._ENetAddress = type { i32, i16 }
%struct._ENetList = type { %struct._ENetListNode }

; Function Attrs: nounwind uwtable
define dso_local void @enet_host_broadcast(ptr nocapture noundef readonly %0, i8 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i64 %6, 0
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %8 = load ptr, ptr %4, align 8, !tbaa !17
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %15
  %9 = phi i64 [ %16, %15 ], [ %6, %.lr.ph.preheader ]
  %10 = phi ptr [ %17, %15 ], [ %8, %.lr.ph.preheader ]
  %.010 = phi ptr [ %18, %15 ], [ %8, %.lr.ph.preheader ]
  %11 = getelementptr inbounds i8, ptr %.010, i64 56
  %12 = load i32, ptr %11, align 8, !tbaa !18
  %.not = icmp eq i32 %12, 5
  br i1 %.not, label %13, label %15

13:                                               ; preds = %.lr.ph
  %14 = tail call i32 @enet_peer_send(ptr noundef nonnull %.010, i8 noundef zeroext %1, ptr noundef %2) #2
  %.pre = load ptr, ptr %4, align 8, !tbaa !17
  %.pre11 = load i64, ptr %5, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %.lr.ph, %13
  %16 = phi i64 [ %9, %.lr.ph ], [ %.pre11, %13 ]
  %17 = phi ptr [ %10, %.lr.ph ], [ %.pre, %13 ]
  %18 = getelementptr inbounds i8, ptr %.010, i64 472
  %19 = getelementptr inbounds %struct._ENetPeer, ptr %17, i64 %16
  %20 = icmp ult ptr %18, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %15, %3
  %21 = load i64, ptr %2, align 8, !tbaa !22
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %._crit_edge
  tail call void @enet_packet_destroy(ptr noundef nonnull %2) #2
  br label %24

24:                                               ; preds = %23, %._crit_edge
  ret void
}

declare i32 @enet_peer_send(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #1

declare void @enet_packet_destroy(ptr noundef) local_unnamed_addr #1

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 = { 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, !13, i64 48}
!6 = !{!"_ENetHost", !7, i64 0, !10, i64 4, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !12, i64 40, !13, i64 48, !13, i64 56, !7, i64 64, !14, i64 72, !7, i64 88, !13, i64 96, !11, i64 104, !8, i64 106, !13, i64 1648, !8, i64 1656, !13, i64 2696, !12, i64 2704, !16, i64 2712, !8, i64 2744, !10, i64 10936, !12, i64 10944, !13, i64 10952, !7, i64 10960, !7, i64 10964, !7, i64 10968, !7, i64 10972, !12, i64 10976, !13, i64 10984, !13, i64 10992, !13, i64 11000, !13, i64 11008, !13, i64 11016}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_ENetAddress", !7, i64 0, !11, i64 4}
!11 = !{!"short", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!"_ENetList", !15, i64 0}
!15 = !{!"_ENetListNode", !12, i64 0, !12, i64 8}
!16 = !{!"_ENetCompressor", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!17 = !{!6, !12, i64 40}
!18 = !{!19, !7, i64 56}
!19 = !{!"_ENetPeer", !15, i64 0, !12, i64 16, !11, i64 24, !11, i64 26, !7, i64 28, !8, i64 32, !8, i64 33, !10, i64 36, !12, i64 48, !7, i64 56, !12, i64 64, !13, i64 72, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !7, i64 100, !7, i64 104, !7, i64 108, !7, i64 112, !7, i64 116, !7, i64 120, !7, i64 124, !7, i64 128, !7, i64 132, !7, i64 136, !7, i64 140, !7, i64 144, !7, i64 148, !7, i64 152, !7, i64 156, !7, i64 160, !7, i64 164, !7, i64 168, !7, i64 172, !7, i64 176, !7, i64 180, !7, i64 184, !7, i64 188, !7, i64 192, !7, i64 196, !7, i64 200, !7, i64 204, !7, i64 208, !7, i64 212, !7, i64 216, !11, i64 220, !14, i64 224, !14, i64 240, !14, i64 256, !14, i64 272, !14, i64 288, !14, i64 304, !7, i64 320, !11, i64 324, !11, i64 326, !8, i64 328, !7, i64 456, !13, i64 464}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!23, !13, i64 0}
!23 = !{!"_ENetPacket", !13, i64 0, !7, i64 8, !12, i64 16, !13, i64 24, !12, i64 32, !12, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass