; 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._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._ENetChannel = type { i16, i16, i16, [16 x i16], i16, i16, %struct._ENetList, %struct._ENetList }
%struct._ENetAcknowledgement = type { %struct._ENetListNode, i32, %union._ENetProtocol }
%union._ENetProtocol = type { %struct._ENetProtocolConnect }
%struct._ENetProtocolConnect = type { %struct._ENetProtocolCommandHeader, i16, i8, i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; 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_malloc(i64 noundef) #1

declare ptr @enet_list_insert(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @enet_peer_queue_acknowledgement(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i16, align 2
  %11 = alloca i16, align 2
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i16 %2, ptr %7, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._ENetProtocolCommandHeader, ptr %13, i32 0, i32 1
  %15 = load i8, ptr %14, align 1, !tbaa !11
  %16 = zext i8 %15 to i64
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._ENetPeer, ptr %17, i32 0, i32 11
  %19 = load i64, ptr %18, align 8, !tbaa !12
  %20 = icmp ult i64 %16, %19
  br i1 %20, label %21, label %76

21:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._ENetPeer, ptr %22, i32 0, i32 10
  %24 = load ptr, ptr %23, align 8, !tbaa !19
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._ENetProtocolCommandHeader, ptr %25, i32 0, i32 1
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = zext i8 %27 to i64
  %29 = getelementptr inbounds %struct._ENetChannel, ptr %24, i64 %28
  store ptr %29, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #4
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._ENetProtocolCommandHeader, ptr %30, i32 0, i32 2
  %32 = load i16, ptr %31, align 1, !tbaa !11
  %33 = zext i16 %32 to i32
  %34 = sdiv i32 %33, 4096
  %35 = trunc i32 %34 to i16
  store i16 %35, ptr %10, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #4
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._ENetChannel, ptr %36, i32 0, i32 4
  %38 = load i16, ptr %37, align 2, !tbaa !20
  %39 = zext i16 %38 to i32
  %40 = sdiv i32 %39, 4096
  %41 = trunc i32 %40 to i16
  store i16 %41, ptr %11, align 2, !tbaa !9
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._ENetProtocolCommandHeader, ptr %42, i32 0, i32 2
  %44 = load i16, ptr %43, align 1, !tbaa !11
  %45 = zext i16 %44 to i32
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._ENetChannel, ptr %46, i32 0, i32 4
  %48 = load i16, ptr %47, align 2, !tbaa !20
  %49 = zext i16 %48 to i32
  %50 = icmp slt i32 %45, %49
  br i1 %50, label %51, label %56

51:                                               ; preds = %21
  %52 = load i16, ptr %10, align 2, !tbaa !9
  %53 = zext i16 %52 to i32
  %54 = add nsw i32 %53, 16
  %55 = trunc i32 %54 to i16
  store i16 %55, ptr %10, align 2, !tbaa !9
  br label %56

56:                                               ; preds = %51, %21
  %57 = load i16, ptr %10, align 2, !tbaa !9
  %58 = zext i16 %57 to i32
  %59 = load i16, ptr %11, align 2, !tbaa !9
  %60 = zext i16 %59 to i32
  %61 = add nsw i32 %60, 8
  %62 = sub nsw i32 %61, 1
  %63 = icmp sge i32 %58, %62
  br i1 %63, label %64, label %72

64:                                               ; preds = %56
  %65 = load i16, ptr %10, align 2, !tbaa !9
  %66 = zext i16 %65 to i32
  %67 = load i16, ptr %11, align 2, !tbaa !9
  %68 = zext i16 %67 to i32
  %69 = add nsw i32 %68, 8
  %70 = icmp sle i32 %66, %69
  br i1 %70, label %71, label %72

71:                                               ; preds = %64
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %73

72:                                               ; preds = %64, %56
  store i32 0, ptr %12, align 4
  br label %73

73:                                               ; preds = %72, %71
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %74 = load i32, ptr %12, align 4
  switch i32 %74, label %101 [
    i32 0, label %75
  ]

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75, %3
  %77 = call ptr @enet_malloc(i64 noundef 72)
  store ptr %77, ptr %8, align 8, !tbaa !5
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = icmp eq ptr %78, null
  br i1 %79, label %80, label %81

80:                                               ; preds = %76
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %101

81:                                               ; preds = %76
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._ENetPeer, ptr %82, i32 0, i32 17
  %84 = load i32, ptr %83, align 4, !tbaa !22
  %85 = zext i32 %84 to i64
  %86 = add i64 %85, 8
  %87 = trunc i64 %86 to i32
  store i32 %87, ptr %83, align 4, !tbaa !22
  %88 = load i16, ptr %7, align 2, !tbaa !9
  %89 = zext i16 %88 to i32
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct._ENetAcknowledgement, ptr %90, i32 0, i32 1
  store i32 %89, ptr %91, align 8, !tbaa !23
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct._ENetAcknowledgement, ptr %92, i32 0, i32 2
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %93, ptr align 1 %94, i64 48, i1 false), !tbaa.struct !25
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct._ENetPeer, ptr %95, i32 0, i32 48
  %97 = getelementptr inbounds %struct._ENetList, ptr %96, i32 0, i32 0
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = call ptr @enet_list_insert(ptr noundef %97, ptr noundef %98)
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %100, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %101

101:                                              ; preds = %81, %80, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %102 = load ptr, ptr %4, align 8
  ret ptr %102
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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


; 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_malloc(i64 noundef) local_unnamed_addr #0

declare ptr @enet_list_insert(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @enet_peer_queue_acknowledgement(ptr noundef %0, ptr nocapture noundef readonly %1, i16 noundef zeroext %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %1, i64 1
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %6 = zext i8 %5 to i64
  %7 = getelementptr inbounds i8, ptr %0, i64 72
  %8 = load i64, ptr %7, align 8, !tbaa !8
  %9 = icmp ugt i64 %8, %6
  br i1 %9, label %10, label %.critedge

10:                                               ; preds = %3
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  %12 = load ptr, ptr %11, align 8, !tbaa !17
  %13 = getelementptr inbounds i8, ptr %1, i64 2
  %14 = load i16, ptr %13, align 1, !tbaa !5
  %15 = lshr i16 %14, 12
  %16 = getelementptr inbounds %struct._ENetChannel, ptr %12, i64 %6, i32 4
  %17 = load i16, ptr %16, align 2, !tbaa !18
  %18 = lshr i16 %17, 12
  %19 = icmp ult i16 %14, %17
  %20 = or disjoint i16 %15, 16
  %spec.select = select i1 %19, i16 %20, i16 %15
  %21 = add nuw nsw i16 %18, 7
  %.not = icmp ugt i16 %21, %spec.select
  %narrow = add nuw nsw i16 %18, 8
  %.not28 = icmp ugt i16 %spec.select, %narrow
  %or.cond = select i1 %.not, i1 true, i1 %.not28
  br i1 %or.cond, label %.critedge, label %33

.critedge:                                        ; preds = %10, %3
  %22 = tail call ptr @enet_malloc(i64 noundef 72) #3
  %23 = icmp eq ptr %22, null
  br i1 %23, label %33, label %24

24:                                               ; preds = %.critedge
  %25 = getelementptr inbounds i8, ptr %0, i64 100
  %26 = load i32, ptr %25, align 4, !tbaa !20
  %27 = add i32 %26, 8
  store i32 %27, ptr %25, align 4, !tbaa !20
  %28 = zext i16 %2 to i32
  %29 = getelementptr inbounds i8, ptr %22, i64 16
  store i32 %28, ptr %29, align 8, !tbaa !21
  %30 = getelementptr inbounds i8, ptr %22, i64 20
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(48) %30, ptr noundef nonnull align 1 dereferenceable(48) %1, i64 48, i1 false), !tbaa.struct !23
  %31 = getelementptr inbounds i8, ptr %0, i64 224
  %32 = tail call ptr @enet_list_insert(ptr noundef nonnull %31, ptr noundef nonnull %22) #3
  br label %33

33:                                               ; preds = %.critedge, %10, %24
  %.1 = phi ptr [ %22, %24 ], [ null, %10 ], [ null, %.critedge ]
  ret ptr %.1
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !15, i64 72}
!9 = !{!"_ENetPeer", !10, i64 0, !11, i64 16, !12, i64 24, !12, i64 26, !13, i64 28, !6, i64 32, !6, i64 33, !14, i64 36, !11, i64 48, !13, i64 56, !11, 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, !6, i64 328, !13, i64 456, !15, i64 464}
!10 = !{!"_ENetListNode", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!"short", !6, i64 0}
!13 = !{!"int", !6, i64 0}
!14 = !{!"_ENetAddress", !13, i64 0, !12, i64 4}
!15 = !{!"long", !6, i64 0}
!16 = !{!"_ENetList", !10, i64 0}
!17 = !{!9, !11, i64 64}
!18 = !{!19, !12, i64 38}
!19 = !{!"_ENetChannel", !12, i64 0, !12, i64 2, !12, i64 4, !6, i64 6, !12, i64 38, !12, i64 40, !16, i64 48, !16, i64 64}
!20 = !{!9, !13, i64 100}
!21 = !{!22, !13, i64 16}
!22 = !{!"_ENetAcknowledgement", !10, i64 0, !13, i64 16, !6, i64 20}
!23 = !{i64 0, i64 48, !5}


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