; 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._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 }
%struct._ENetIncomingCommand = type { %struct._ENetListNode, i16, i16, %union._ENetProtocol, i32, i32, 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare ptr @enet_list_remove(ptr noundef) #1

declare void @enet_free(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @enet_peer_receive(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._ENetPeer, ptr %9, i32 0, i32 53
  %11 = getelementptr inbounds %struct._ENetList, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds %struct._ENetListNode, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._ENetPeer, ptr %14, i32 0, i32 53
  %16 = getelementptr inbounds %struct._ENetList, ptr %15, i32 0, i32 0
  %17 = icmp eq ptr %13, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %60

19:                                               ; preds = %2
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._ENetPeer, ptr %20, i32 0, i32 53
  %22 = getelementptr inbounds %struct._ENetList, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds %struct._ENetListNode, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = call ptr @enet_list_remove(ptr noundef %24)
  store ptr %25, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %34

28:                                               ; preds = %19
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._ENetIncomingCommand, ptr %29, i32 0, i32 3
  %31 = getelementptr inbounds %struct._ENetProtocolCommandHeader, ptr %30, i32 0, i32 1
  %32 = load i8, ptr %31, align 1, !tbaa !17
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %32, ptr %33, align 1, !tbaa !17
  br label %34

34:                                               ; preds = %28, %19
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._ENetIncomingCommand, ptr %35, i32 0, i32 7
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  store ptr %37, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._ENetPacket, ptr %38, i32 0, i32 0
  %40 = load i64, ptr %39, align 8, !tbaa !20
  %41 = add i64 %40, -1
  store i64 %41, ptr %39, align 8, !tbaa !20
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._ENetIncomingCommand, ptr %42, i32 0, i32 6
  %44 = load ptr, ptr %43, align 8, !tbaa !22
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %50

46:                                               ; preds = %34
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._ENetIncomingCommand, ptr %47, i32 0, i32 6
  %49 = load ptr, ptr %48, align 8, !tbaa !22
  call void @enet_free(ptr noundef %49)
  br label %50

50:                                               ; preds = %46, %34
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  call void @enet_free(ptr noundef %51)
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._ENetPacket, ptr %52, i32 0, i32 3
  %54 = load i64, ptr %53, align 8, !tbaa !23
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._ENetPeer, ptr %55, i32 0, i32 59
  %57 = load i64, ptr %56, align 8, !tbaa !24
  %58 = sub i64 %57, %54
  store i64 %58, ptr %56, align 8, !tbaa !24
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %59, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %60

60:                                               ; preds = %50, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %61 = load ptr, ptr %3, align 8
  ret ptr %61
}

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 = { 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 #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 = !{!10, !6, i64 304}
!10 = !{!"_ENetPeer", !11, i64 0, !6, i64 16, !12, i64 24, !12, i64 26, !13, i64 28, !7, i64 32, !7, i64 33, !14, i64 36, !6, i64 48, !13, i64 56, !6, i64 64, !15, i64 72, !13, i64 80, !13, i64 84, !13, i64 88, !13, i64 92, !13, i64 96, !13, i64 100, !13, i64 104, !13, i64 108, !13, i64 112, !13, i64 116, !13, i64 120, !13, i64 124, !13, i64 128, !13, i64 132, !13, i64 136, !13, i64 140, !13, i64 144, !13, i64 148, !13, i64 152, !13, i64 156, !13, i64 160, !13, i64 164, !13, i64 168, !13, i64 172, !13, i64 176, !13, i64 180, !13, i64 184, !13, i64 188, !13, i64 192, !13, i64 196, !13, i64 200, !13, i64 204, !13, i64 208, !13, i64 212, !13, i64 216, !12, i64 220, !16, i64 224, !16, i64 240, !16, i64 256, !16, i64 272, !16, i64 288, !16, i64 304, !13, i64 320, !12, i64 324, !12, i64 326, !7, i64 328, !13, i64 456, !15, i64 464}
!11 = !{!"_ENetListNode", !6, i64 0, !6, i64 8}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ENetAddress", !13, i64 0, !12, i64 4}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ENetList", !11, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!19, !6, i64 88}
!19 = !{!"_ENetIncomingCommand", !11, i64 0, !12, i64 16, !12, i64 18, !7, i64 20, !13, i64 68, !13, i64 72, !6, i64 80, !6, i64 88}
!20 = !{!21, !15, i64 0}
!21 = !{!"_ENetPacket", !15, i64 0, !13, i64 8, !6, i64 16, !15, i64 24, !6, i64 32, !6, i64 40}
!22 = !{!19, !6, i64 80}
!23 = !{!21, !15, i64 24}
!24 = !{!10, !15, i64 464}


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

declare ptr @enet_list_remove(ptr noundef) local_unnamed_addr #0

declare void @enet_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @enet_peer_receive(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 304
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, %3
  br i1 %5, label %25, label %6

6:                                                ; preds = %2
  %7 = tail call ptr @enet_list_remove(ptr noundef %4) #2
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %11, label %8

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %7, i64 21
  %10 = load i8, ptr %9, align 1, !tbaa !16
  store i8 %10, ptr %1, align 1, !tbaa !16
  br label %11

11:                                               ; preds = %8, %6
  %12 = getelementptr inbounds i8, ptr %7, i64 88
  %13 = load ptr, ptr %12, align 8, !tbaa !17
  %14 = load i64, ptr %13, align 8, !tbaa !19
  %15 = add i64 %14, -1
  store i64 %15, ptr %13, align 8, !tbaa !19
  %16 = getelementptr inbounds i8, ptr %7, i64 80
  %17 = load ptr, ptr %16, align 8, !tbaa !21
  %.not18 = icmp eq ptr %17, null
  br i1 %.not18, label %19, label %18

18:                                               ; preds = %11
  tail call void @enet_free(ptr noundef nonnull %17) #2
  br label %19

19:                                               ; preds = %18, %11
  tail call void @enet_free(ptr noundef nonnull %7) #2
  %20 = getelementptr inbounds i8, ptr %13, i64 24
  %21 = load i64, ptr %20, align 8, !tbaa !22
  %22 = getelementptr inbounds i8, ptr %0, i64 464
  %23 = load i64, ptr %22, align 8, !tbaa !23
  %24 = sub i64 %23, %21
  store i64 %24, ptr %22, align 8, !tbaa !23
  br label %25

25:                                               ; preds = %2, %19
  %.0 = phi ptr [ %13, %19 ], [ null, %2 ]
  ret ptr %.0
}

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 = { 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 = { 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, !8, i64 304}
!6 = !{!"_ENetPeer", !7, i64 0, !8, i64 16, !11, i64 24, !11, i64 26, !12, i64 28, !9, i64 32, !9, i64 33, !13, i64 36, !8, i64 48, !12, i64 56, !8, i64 64, !14, 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, !11, i64 220, !15, i64 224, !15, i64 240, !15, i64 256, !15, i64 272, !15, i64 288, !15, i64 304, !12, i64 320, !11, i64 324, !11, i64 326, !9, i64 328, !12, i64 456, !14, i64 464}
!7 = !{!"_ENetListNode", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"short", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!"_ENetAddress", !12, i64 0, !11, i64 4}
!14 = !{!"long", !9, i64 0}
!15 = !{!"_ENetList", !7, i64 0}
!16 = !{!9, !9, i64 0}
!17 = !{!18, !8, i64 88}
!18 = !{!"_ENetIncomingCommand", !7, i64 0, !11, i64 16, !11, i64 18, !9, i64 20, !12, i64 68, !12, i64 72, !8, i64 80, !8, i64 88}
!19 = !{!20, !14, i64 0}
!20 = !{!"_ENetPacket", !14, i64 0, !12, i64 8, !8, i64 16, !14, i64 24, !8, i64 32, !8, i64 40}
!21 = !{!18, !8, i64 80}
!22 = !{!20, !14, i64 24}
!23 = !{!6, !14, i64 464}


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