; 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._ENetChannel = type { i16, i16, i16, [16 x i16], i16, i16, %struct._ENetList, %struct._ENetList }

; 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 void @enet_peer_reset_queues(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct._ENetPeer, ptr %4, i32 0, i32 54
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %14

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._ENetPeer, ptr %9, i32 0, i32 0
  %11 = call ptr @enet_list_remove(ptr noundef %10)
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._ENetPeer, ptr %12, i32 0, i32 54
  store i32 0, ptr %13, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %8, %1
  br label %15

15:                                               ; preds = %26, %14
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._ENetPeer, ptr %16, i32 0, i32 48
  %18 = getelementptr inbounds %struct._ENetList, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct._ENetListNode, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._ENetPeer, ptr %21, i32 0, i32 48
  %23 = getelementptr inbounds %struct._ENetList, ptr %22, i32 0, i32 0
  %24 = icmp eq ptr %20, %23
  %25 = xor i1 %24, true
  br i1 %25, label %26, label %33

26:                                               ; preds = %15
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._ENetPeer, ptr %27, i32 0, i32 48
  %29 = getelementptr inbounds %struct._ENetList, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds %struct._ENetListNode, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %32 = call ptr @enet_list_remove(ptr noundef %31)
  call void @enet_free(ptr noundef %32)
  br label %15, !llvm.loop !18

33:                                               ; preds = %15
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._ENetPeer, ptr %34, i32 0, i32 49
  call void @enet_peer_reset_outgoing_commands(ptr noundef %35)
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._ENetPeer, ptr %36, i32 0, i32 50
  call void @enet_peer_reset_outgoing_commands(ptr noundef %37)
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._ENetPeer, ptr %38, i32 0, i32 51
  call void @enet_peer_reset_outgoing_commands(ptr noundef %39)
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._ENetPeer, ptr %40, i32 0, i32 52
  call void @enet_peer_reset_outgoing_commands(ptr noundef %41)
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._ENetPeer, ptr %42, i32 0, i32 53
  call void @enet_peer_reset_incoming_commands(ptr noundef %43)
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._ENetPeer, ptr %44, i32 0, i32 10
  %46 = load ptr, ptr %45, align 8, !tbaa !20
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %79

48:                                               ; preds = %33
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._ENetPeer, ptr %49, i32 0, i32 11
  %51 = load i64, ptr %50, align 8, !tbaa !21
  %52 = icmp ugt i64 %51, 0
  br i1 %52, label %53, label %79

53:                                               ; preds = %48
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._ENetPeer, ptr %54, i32 0, i32 10
  %56 = load ptr, ptr %55, align 8, !tbaa !20
  store ptr %56, ptr %3, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %72, %53
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._ENetPeer, ptr %59, i32 0, i32 10
  %61 = load ptr, ptr %60, align 8, !tbaa !20
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._ENetPeer, ptr %62, i32 0, i32 11
  %64 = load i64, ptr %63, align 8, !tbaa !21
  %65 = getelementptr inbounds %struct._ENetChannel, ptr %61, i64 %64
  %66 = icmp ult ptr %58, %65
  br i1 %66, label %67, label %75

67:                                               ; preds = %57
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._ENetChannel, ptr %68, i32 0, i32 6
  call void @enet_peer_reset_incoming_commands(ptr noundef %69)
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._ENetChannel, ptr %70, i32 0, i32 7
  call void @enet_peer_reset_incoming_commands(ptr noundef %71)
  br label %72

72:                                               ; preds = %67
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._ENetChannel, ptr %73, i32 1
  store ptr %74, ptr %3, align 8, !tbaa !5
  br label %57, !llvm.loop !22

75:                                               ; preds = %57
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._ENetPeer, ptr %76, i32 0, i32 10
  %78 = load ptr, ptr %77, align 8, !tbaa !20
  call void @enet_free(ptr noundef %78)
  br label %79

79:                                               ; preds = %75, %48, %33
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._ENetPeer, ptr %80, i32 0, i32 10
  store ptr null, ptr %81, align 8, !tbaa !20
  %82 = load ptr, ptr %2, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._ENetPeer, ptr %82, i32 0, i32 11
  store i64 0, ptr %83, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @enet_peer_reset_outgoing_commands(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @enet_peer_reset_incoming_commands(ptr noundef) #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 = { 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, !13, i64 320}
!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 = !{!10, !6, i64 224}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !6, i64 64}
!21 = !{!10, !15, i64 72}
!22 = distinct !{!22, !19}


; 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._ENetChannel = type { i16, i16, i16, [16 x i16], i16, i16, %struct._ENetList, %struct._ENetList }
%struct._ENetList = type { %struct._ENetListNode }
%struct._ENetListNode = type { ptr, ptr }

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 void @enet_peer_reset_queues(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 320
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %6, label %4

4:                                                ; preds = %1
  %5 = tail call ptr @enet_list_remove(ptr noundef nonnull %0) #3
  store i32 0, ptr %2, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %4, %1
  %7 = getelementptr inbounds i8, ptr %0, i64 224
  %8 = load ptr, ptr %7, align 8, !tbaa !16
  %.not2427 = icmp eq ptr %8, %7
  br i1 %.not2427, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %.lr.ph
  %9 = phi ptr [ %11, %.lr.ph ], [ %8, %6 ]
  %10 = tail call ptr @enet_list_remove(ptr noundef %9) #3
  tail call void @enet_free(ptr noundef %10) #3
  %11 = load ptr, ptr %7, align 8, !tbaa !16
  %.not24 = icmp eq ptr %11, %7
  br i1 %.not24, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph, %6
  %12 = getelementptr inbounds i8, ptr %0, i64 240
  tail call void @enet_peer_reset_outgoing_commands(ptr noundef nonnull %12)
  %13 = getelementptr inbounds i8, ptr %0, i64 256
  tail call void @enet_peer_reset_outgoing_commands(ptr noundef nonnull %13)
  %14 = getelementptr inbounds i8, ptr %0, i64 272
  tail call void @enet_peer_reset_outgoing_commands(ptr noundef nonnull %14)
  %15 = getelementptr inbounds i8, ptr %0, i64 288
  tail call void @enet_peer_reset_outgoing_commands(ptr noundef nonnull %15)
  %16 = getelementptr inbounds i8, ptr %0, i64 304
  tail call void @enet_peer_reset_incoming_commands(ptr noundef nonnull %16)
  %17 = getelementptr inbounds i8, ptr %0, i64 64
  %18 = load ptr, ptr %17, align 8, !tbaa !19
  %.not25 = icmp eq ptr %18, null
  br i1 %.not25, label %30, label %19

19:                                               ; preds = %._crit_edge
  %20 = getelementptr inbounds i8, ptr %0, i64 72
  %21 = load i64, ptr %20, align 8, !tbaa !20
  %.not26 = icmp eq i64 %21, 0
  br i1 %.not26, label %30, label %.preheader

.preheader:                                       ; preds = %19
  %22 = icmp sgt i64 %21, 0
  br i1 %22, label %.lr.ph29, label %._crit_edge30

.lr.ph29:                                         ; preds = %.preheader, %.lr.ph29
  %.028 = phi ptr [ %25, %.lr.ph29 ], [ %18, %.preheader ]
  %23 = getelementptr inbounds i8, ptr %.028, i64 48
  tail call void @enet_peer_reset_incoming_commands(ptr noundef nonnull %23)
  %24 = getelementptr inbounds i8, ptr %.028, i64 64
  tail call void @enet_peer_reset_incoming_commands(ptr noundef nonnull %24)
  %25 = getelementptr inbounds i8, ptr %.028, i64 80
  %26 = load ptr, ptr %17, align 8, !tbaa !19
  %27 = load i64, ptr %20, align 8, !tbaa !20
  %28 = getelementptr inbounds %struct._ENetChannel, ptr %26, i64 %27
  %29 = icmp ult ptr %25, %28
  br i1 %29, label %.lr.ph29, label %._crit_edge30, !llvm.loop !21

._crit_edge30:                                    ; preds = %.lr.ph29, %.preheader
  %.lcssa = phi ptr [ %18, %.preheader ], [ %26, %.lr.ph29 ]
  tail call void @enet_free(ptr noundef %.lcssa) #3
  br label %30

30:                                               ; preds = %._crit_edge30, %19, %._crit_edge
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %17, i8 0, i64 16, i1 false)
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @enet_peer_reset_outgoing_commands(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @enet_peer_reset_incoming_commands(ptr noundef) local_unnamed_addr #1

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !12, i64 320}
!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 = !{!6, !8, i64 224}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !8, i64 64}
!20 = !{!6, !14, i64 72}
!21 = distinct !{!21, !18}


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