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

; Function Attrs: nounwind uwtable
define dso_local i32 @enet_peer_throttle(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct._ENetPeer, ptr %6, i32 0, i32 38
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._ENetPeer, ptr %9, i32 0, i32 40
  %11 = load i32, ptr %10, align 8, !tbaa !18
  %12 = icmp ule i32 %8, %11
  br i1 %12, label %13, label %19

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._ENetPeer, ptr %14, i32 0, i32 28
  %16 = load i32, ptr %15, align 8, !tbaa !19
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._ENetPeer, ptr %17, i32 0, i32 27
  store i32 %16, ptr %18, align 4, !tbaa !20
  br label %80

19:                                               ; preds = %2
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._ENetPeer, ptr %21, i32 0, i32 38
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = icmp ult i32 %20, %23
  br i1 %24, label %25, label %47

25:                                               ; preds = %19
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._ENetPeer, ptr %26, i32 0, i32 31
  %28 = load i32, ptr %27, align 4, !tbaa !21
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._ENetPeer, ptr %29, i32 0, i32 27
  %31 = load i32, ptr %30, align 4, !tbaa !20
  %32 = add i32 %31, %28
  store i32 %32, ptr %30, align 4, !tbaa !20
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._ENetPeer, ptr %33, i32 0, i32 27
  %35 = load i32, ptr %34, align 4, !tbaa !20
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._ENetPeer, ptr %36, i32 0, i32 28
  %38 = load i32, ptr %37, align 8, !tbaa !19
  %39 = icmp ugt i32 %35, %38
  br i1 %39, label %40, label %46

40:                                               ; preds = %25
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._ENetPeer, ptr %41, i32 0, i32 28
  %43 = load i32, ptr %42, align 8, !tbaa !19
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._ENetPeer, ptr %44, i32 0, i32 27
  store i32 %43, ptr %45, align 4, !tbaa !20
  br label %46

46:                                               ; preds = %40, %25
  store i32 1, ptr %3, align 4
  br label %81

47:                                               ; preds = %19
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._ENetPeer, ptr %49, i32 0, i32 38
  %51 = load i32, ptr %50, align 8, !tbaa !11
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._ENetPeer, ptr %52, i32 0, i32 40
  %54 = load i32, ptr %53, align 8, !tbaa !18
  %55 = mul i32 2, %54
  %56 = add i32 %51, %55
  %57 = icmp ugt i32 %48, %56
  br i1 %57, label %58, label %78

58:                                               ; preds = %47
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._ENetPeer, ptr %59, i32 0, i32 27
  %61 = load i32, ptr %60, align 4, !tbaa !20
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._ENetPeer, ptr %62, i32 0, i32 32
  %64 = load i32, ptr %63, align 8, !tbaa !22
  %65 = icmp ugt i32 %61, %64
  br i1 %65, label %66, label %74

66:                                               ; preds = %58
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._ENetPeer, ptr %67, i32 0, i32 32
  %69 = load i32, ptr %68, align 8, !tbaa !22
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._ENetPeer, ptr %70, i32 0, i32 27
  %72 = load i32, ptr %71, align 4, !tbaa !20
  %73 = sub i32 %72, %69
  store i32 %73, ptr %71, align 4, !tbaa !20
  br label %77

74:                                               ; preds = %58
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._ENetPeer, ptr %75, i32 0, i32 27
  store i32 0, ptr %76, align 4, !tbaa !20
  br label %77

77:                                               ; preds = %74, %66
  store i32 -1, ptr %3, align 4
  br label %81

78:                                               ; preds = %47
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79, %13
  store i32 0, ptr %3, align 4
  br label %81

81:                                               ; preds = %80, %77, %46
  %82 = load i32, ptr %3, align 4
  ret i32 %82
}

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

!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 184}
!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 = !{!12, !10, i64 192}
!19 = !{!12, !10, i64 144}
!20 = !{!12, !10, i64 140}
!21 = !{!12, !10, i64 156}
!22 = !{!12, !10, i64 160}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local range(i32 -1, 2) i32 @enet_peer_throttle(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 184
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 192
  %6 = load i32, ptr %5, align 8, !tbaa !16
  %.not = icmp ugt i32 %4, %6
  br i1 %.not, label %11, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 144
  %9 = load i32, ptr %8, align 8, !tbaa !17
  %10 = getelementptr inbounds i8, ptr %0, i64 140
  store i32 %9, ptr %10, align 4, !tbaa !18
  br label %30

11:                                               ; preds = %2
  %12 = icmp ugt i32 %4, %1
  br i1 %12, label %13, label %21

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %0, i64 156
  %15 = load i32, ptr %14, align 4, !tbaa !19
  %16 = getelementptr inbounds i8, ptr %0, i64 140
  %17 = load i32, ptr %16, align 4, !tbaa !18
  %18 = add i32 %17, %15
  %19 = getelementptr inbounds i8, ptr %0, i64 144
  %20 = load i32, ptr %19, align 8, !tbaa !17
  %spec.store.select = tail call i32 @llvm.umin.i32(i32 %18, i32 %20)
  store i32 %spec.store.select, ptr %16, align 4
  br label %30

21:                                               ; preds = %11
  %22 = shl i32 %6, 1
  %23 = add i32 %22, %4
  %24 = icmp ult i32 %23, %1
  br i1 %24, label %25, label %30

25:                                               ; preds = %21
  %26 = getelementptr inbounds i8, ptr %0, i64 140
  %27 = load i32, ptr %26, align 4, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %0, i64 160
  %29 = load i32, ptr %28, align 8, !tbaa !20
  %storemerge = tail call i32 @llvm.usub.sat.i32(i32 %27, i32 %29)
  store i32 %storemerge, ptr %26, align 4, !tbaa !18
  br label %30

30:                                               ; preds = %7, %21, %25, %13
  %.0 = phi i32 [ 1, %13 ], [ -1, %25 ], [ 0, %21 ], [ 0, %7 ]
  ret i32 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.usub.sat.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 184}
!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, !12, i64 192}
!17 = !{!6, !12, i64 144}
!18 = !{!6, !12, i64 140}
!19 = !{!6, !12, i64 156}
!20 = !{!6, !12, i64 160}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass