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

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

declare void @enet_free(ptr noundef) #1

declare void @enet_socket_destroy(i32 noundef) #1

declare void @enet_peer_reset(ptr noundef) #1

; 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_destroy(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  store i32 1, ptr %4, align 4
  br label %56

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._ENetHost, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !9
  call void @enet_socket_destroy(i32 noundef %11)
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._ENetHost, ptr %12, i32 0, i32 9
  %14 = load ptr, ptr %13, align 8, !tbaa !18
  store ptr %14, ptr %3, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %27, %8
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._ENetHost, ptr %17, i32 0, i32 9
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._ENetHost, ptr %20, i32 0, i32 10
  %22 = load i64, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds %struct._ENetPeer, ptr %19, i64 %22
  %24 = icmp ult ptr %16, %23
  br i1 %24, label %25, label %30

25:                                               ; preds = %15
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  call void @enet_peer_reset(ptr noundef %26)
  br label %27

27:                                               ; preds = %25
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._ENetPeer, ptr %28, i32 1
  store ptr %29, ptr %3, align 8, !tbaa !5
  br label %15, !llvm.loop !20

30:                                               ; preds = %15
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._ENetHost, ptr %31, i32 0, i32 25
  %33 = getelementptr inbounds %struct._ENetCompressor, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !22
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %51

36:                                               ; preds = %30
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._ENetHost, ptr %37, i32 0, i32 25
  %39 = getelementptr inbounds %struct._ENetCompressor, ptr %38, i32 0, i32 3
  %40 = load ptr, ptr %39, align 8, !tbaa !23
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %51

42:                                               ; preds = %36
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._ENetHost, ptr %43, i32 0, i32 25
  %45 = getelementptr inbounds %struct._ENetCompressor, ptr %44, i32 0, i32 3
  %46 = load ptr, ptr %45, align 8, !tbaa !23
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._ENetHost, ptr %47, i32 0, i32 25
  %49 = getelementptr inbounds %struct._ENetCompressor, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !22
  call void %46(ptr noundef %50)
  br label %51

51:                                               ; preds = %42, %36, %30
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._ENetHost, ptr %52, i32 0, i32 9
  %54 = load ptr, ptr %53, align 8, !tbaa !18
  call void @enet_free(ptr noundef %54)
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  call void @enet_free(ptr noundef %55)
  store i32 0, ptr %4, align 4
  br label %56

56:                                               ; preds = %51, %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %57 = load i32, ptr %4, align 4
  switch i32 %57, label %59 [
    i32 0, label %58
    i32 1, label %58
  ]

58:                                               ; preds = %56, %56
  ret void

59:                                               ; preds = %56
  unreachable
}

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, !11, i64 0}
!10 = !{!"_ENetHost", !11, i64 0, !12, i64 4, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !6, i64 40, !14, i64 48, !14, i64 56, !11, i64 64, !15, i64 72, !11, i64 88, !14, i64 96, !13, i64 104, !7, i64 106, !14, i64 1648, !7, i64 1656, !14, i64 2696, !6, i64 2704, !17, i64 2712, !7, i64 2744, !12, i64 10936, !6, i64 10944, !14, i64 10952, !11, i64 10960, !11, i64 10964, !11, i64 10968, !11, i64 10972, !6, i64 10976, !14, i64 10984, !14, i64 10992, !14, i64 11000, !14, i64 11008, !14, i64 11016}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ENetAddress", !11, i64 0, !13, i64 4}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ENetList", !16, i64 0}
!16 = !{!"_ENetListNode", !6, i64 0, !6, i64 8}
!17 = !{!"_ENetCompressor", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!18 = !{!10, !6, i64 40}
!19 = !{!10, !14, i64 48}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!10, !6, i64 2712}
!23 = !{!10, !6, i64 2736}


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

declare void @enet_free(ptr noundef) local_unnamed_addr #0

declare void @enet_socket_destroy(i32 noundef) local_unnamed_addr #0

declare void @enet_peer_reset(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @enet_host_destroy(ptr noundef %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %24, label %3

3:                                                ; preds = %1
  %4 = load i32, ptr %0, align 8, !tbaa !5
  tail call void @enet_socket_destroy(i32 noundef %4) #2
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = load ptr, ptr %5, align 8, !tbaa !17
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = load i64, ptr %7, align 8, !tbaa !18
  %9 = icmp sgt i64 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.018 = phi ptr [ %10, %.lr.ph ], [ %6, %3 ]
  tail call void @enet_peer_reset(ptr noundef %.018) #2
  %10 = getelementptr inbounds i8, ptr %.018, i64 472
  %11 = load ptr, ptr %5, align 8, !tbaa !17
  %12 = load i64, ptr %7, align 8, !tbaa !18
  %13 = getelementptr inbounds %struct._ENetPeer, ptr %11, i64 %12
  %14 = icmp ult ptr %10, %13
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph, %3
  %15 = phi ptr [ %6, %3 ], [ %11, %.lr.ph ]
  %16 = getelementptr inbounds i8, ptr %0, i64 2712
  %17 = load ptr, ptr %16, align 8, !tbaa !21
  %.not = icmp eq ptr %17, null
  br i1 %.not, label %22, label %18

18:                                               ; preds = %._crit_edge
  %19 = getelementptr inbounds i8, ptr %0, i64 2736
  %20 = load ptr, ptr %19, align 8, !tbaa !22
  %.not17 = icmp eq ptr %20, null
  br i1 %.not17, label %22, label %21

21:                                               ; preds = %18
  tail call void %20(ptr noundef nonnull %17) #2
  %.pre = load ptr, ptr %5, align 8, !tbaa !17
  br label %22

22:                                               ; preds = %21, %18, %._crit_edge
  %23 = phi ptr [ %.pre, %21 ], [ %15, %18 ], [ %15, %._crit_edge ]
  tail call void @enet_free(ptr noundef %23) #2
  tail call void @enet_free(ptr noundef nonnull %0) #2
  br label %24

24:                                               ; preds = %1, %22
  ret void
}

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, !7, i64 0}
!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 = !{!6, !13, i64 48}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!6, !12, i64 2712}
!22 = !{!6, !12, i64 2736}


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