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

%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._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._ENetProtocolDisconnect = type { %struct._ENetProtocolCommandHeader, i32 }

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__bswap_32(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @enet_peer_queue_outgoing_command(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i16 noundef zeroext) #2

; 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
declare dso_local void @enet_peer_reset_queues(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @enet_peer_on_disconnect(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @enet_peer_reset(ptr noundef) #2

declare void @enet_host_flush(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @enet_peer_disconnect(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %union._ENetProtocol, align 1
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 48, ptr %5) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._ENetPeer, ptr %7, i32 0, i32 9
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = icmp eq i32 %9, 7
  br i1 %10, label %26, label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._ENetPeer, ptr %12, i32 0, i32 9
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %26, label %16

16:                                               ; preds = %11
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._ENetPeer, ptr %17, i32 0, i32 9
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp eq i32 %19, 8
  br i1 %20, label %26, label %21

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

26:                                               ; preds = %21, %16, %11, %2
  store i32 1, ptr %6, align 4
  br label %77

27:                                               ; preds = %21
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  call void @enet_peer_reset_queues(ptr noundef %28)
  %29 = getelementptr inbounds %struct._ENetProtocolCommandHeader, ptr %5, i32 0, i32 0
  store i8 4, ptr %29, align 1, !tbaa !18
  %30 = getelementptr inbounds %struct._ENetProtocolCommandHeader, ptr %5, i32 0, i32 1
  store i8 -1, ptr %30, align 1, !tbaa !18
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = call i32 @__bswap_32(i32 noundef %31)
  %33 = getelementptr inbounds %struct._ENetProtocolDisconnect, ptr %5, i32 0, i32 1
  store i32 %32, ptr %33, align 1, !tbaa !18
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._ENetPeer, ptr %34, i32 0, i32 9
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = icmp eq i32 %36, 5
  br i1 %37, label %43, label %38

38:                                               ; preds = %27
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._ENetPeer, ptr %39, i32 0, i32 9
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = icmp eq i32 %41, 6
  br i1 %42, label %43, label %49

43:                                               ; preds = %38, %27
  %44 = getelementptr inbounds %struct._ENetProtocolCommandHeader, ptr %5, i32 0, i32 0
  %45 = load i8, ptr %44, align 1, !tbaa !18
  %46 = zext i8 %45 to i32
  %47 = or i32 %46, 128
  %48 = trunc i32 %47 to i8
  store i8 %48, ptr %44, align 1, !tbaa !18
  br label %55

49:                                               ; preds = %38
  %50 = getelementptr inbounds %struct._ENetProtocolCommandHeader, ptr %5, i32 0, i32 0
  %51 = load i8, ptr %50, align 1, !tbaa !18
  %52 = zext i8 %51 to i32
  %53 = or i32 %52, 64
  %54 = trunc i32 %53 to i8
  store i8 %54, ptr %50, align 1, !tbaa !18
  br label %55

55:                                               ; preds = %49, %43
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = call ptr @enet_peer_queue_outgoing_command(ptr noundef %56, ptr noundef %5, ptr noundef null, i32 noundef 0, i16 noundef zeroext 0)
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._ENetPeer, ptr %58, i32 0, i32 9
  %60 = load i32, ptr %59, align 8, !tbaa !11
  %61 = icmp eq i32 %60, 5
  br i1 %61, label %67, label %62

62:                                               ; preds = %55
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._ENetPeer, ptr %63, i32 0, i32 9
  %65 = load i32, ptr %64, align 8, !tbaa !11
  %66 = icmp eq i32 %65, 6
  br i1 %66, label %67, label %71

67:                                               ; preds = %62, %55
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  call void @enet_peer_on_disconnect(ptr noundef %68)
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._ENetPeer, ptr %69, i32 0, i32 9
  store i32 7, ptr %70, align 8, !tbaa !11
  br label %76

71:                                               ; preds = %62
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._ENetPeer, ptr %72, i32 0, i32 1
  %74 = load ptr, ptr %73, align 8, !tbaa !19
  call void @enet_host_flush(ptr noundef %74)
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  call void @enet_peer_reset(ptr noundef %75)
  br label %76

76:                                               ; preds = %71, %67
  store i32 0, ptr %6, align 4
  br label %77

77:                                               ; preds = %76, %26
  call void @llvm.lifetime.end.p0(i64 48, ptr %5) #4
  %78 = load i32, ptr %6, align 4
  switch i32 %78, label %80 [
    i32 0, label %79
    i32 1, label %79
  ]

79:                                               ; preds = %77, %77
  ret void

80:                                               ; preds = %77
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 = { "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 #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, !10, i64 56}
!12 = !{!"_ENetPeer", !13, i64 0, !6, i64 16, !14, i64 24, !14, i64 26, !10, i64 28, !7, i64 32, !7, i64 33, !15, i64 36, !6, i64 48, !10, i64 56, !6, i64 64, !16, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !10, i64 148, !10, i64 152, !10, i64 156, !10, i64 160, !10, i64 164, !10, i64 168, !10, i64 172, !10, i64 176, !10, i64 180, !10, i64 184, !10, i64 188, !10, i64 192, !10, i64 196, !10, i64 200, !10, i64 204, !10, i64 208, !10, i64 212, !10, i64 216, !14, i64 220, !17, i64 224, !17, i64 240, !17, i64 256, !17, i64 272, !17, i64 288, !17, i64 304, !10, i64 320, !14, i64 324, !14, i64 326, !7, i64 328, !10, i64 456, !16, i64 464}
!13 = !{!"_ENetListNode", !6, i64 0, !6, i64 8}
!14 = !{!"short", !7, i64 0}
!15 = !{!"_ENetAddress", !10, i64 0, !14, i64 4}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ENetList", !13, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!12, !6, i64 16}


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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__bswap_32(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @enet_peer_queue_outgoing_command(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @enet_peer_reset_queues(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @enet_peer_on_disconnect(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @enet_peer_reset(ptr noundef) local_unnamed_addr #2

declare void @enet_host_flush(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @enet_peer_disconnect(ptr noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = alloca %union._ENetProtocol, align 1
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %3) #4
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  %5 = load i32, ptr %4, align 8, !tbaa !5
  switch i32 %5, label %6 [
    i32 7, label %17
    i32 0, label %17
    i32 8, label %17
    i32 9, label %17
  ]

6:                                                ; preds = %2
  tail call void @enet_peer_reset_queues(ptr noundef nonnull %0)
  %7 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 -1, ptr %7, align 1, !tbaa !16
  %8 = tail call i32 @__bswap_32(i32 noundef %1)
  %9 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %8, ptr %9, align 1, !tbaa !16
  %10 = load i32, ptr %4, align 8, !tbaa !5
  %.off = add i32 %10, -5
  %switch = icmp ult i32 %.off, 2
  %storemerge = select i1 %switch, i8 -124, i8 68
  store i8 %storemerge, ptr %3, align 1, !tbaa !16
  %11 = call ptr @enet_peer_queue_outgoing_command(ptr noundef nonnull %0, ptr noundef nonnull %3, ptr noundef null, i32 noundef 0, i16 noundef zeroext 0)
  %12 = load i32, ptr %4, align 8, !tbaa !5
  %.off16 = add i32 %12, -5
  %switch17 = icmp ult i32 %.off16, 2
  br i1 %switch17, label %13, label %14

13:                                               ; preds = %6
  call void @enet_peer_on_disconnect(ptr noundef nonnull %0)
  store i32 7, ptr %4, align 8, !tbaa !5
  br label %17

14:                                               ; preds = %6
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  call void @enet_host_flush(ptr noundef %16) #4
  call void @enet_peer_reset(ptr noundef nonnull %0)
  br label %17

17:                                               ; preds = %13, %14, %2, %2, %2, %2
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %3) #4
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 = { "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 #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, !12, i64 56}
!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 = !{!6, !8, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass