; LLVM IR from nem0/lumixengine_net :: external/enet (packet)

; 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.ENetBuffer = type { ptr, i64 }

@initializedCRC32 = external hidden global i32, align 4
@crcTable = external hidden global [256 x i32], align 16

; 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

; Function Attrs: nounwind uwtable
define dso_local i32 @enet_crc32(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 -1, ptr %5, align 4, !tbaa !11
  %8 = load i32, ptr @initializedCRC32, align 4, !tbaa !11
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %11, label %10

10:                                               ; preds = %2
  call void @initialize_crc32()
  br label %11

11:                                               ; preds = %10, %2
  br label %12

12:                                               ; preds = %43, %11
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = add i64 %13, -1
  store i64 %14, ptr %4, align 8, !tbaa !9
  %15 = icmp ugt i64 %13, 0
  br i1 %15, label %16, label %46

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ENetBuffer, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  store ptr %19, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ENetBuffer, ptr %21, i32 0, i32 1
  %23 = load i64, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %20, i64 %23
  store ptr %24, ptr %7, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %29, %16
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = icmp ult ptr %26, %27
  br i1 %28, label %29, label %43

29:                                               ; preds = %25
  %30 = load i32, ptr %5, align 4, !tbaa !11
  %31 = lshr i32 %30, 8
  %32 = load i32, ptr %5, align 4, !tbaa !11
  %33 = and i32 %32, 255
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i32 1
  store ptr %35, ptr %6, align 8, !tbaa !5
  %36 = load i8, ptr %34, align 1, !tbaa !16
  %37 = zext i8 %36 to i32
  %38 = xor i32 %33, %37
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds [256 x i32], ptr @crcTable, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = xor i32 %31, %41
  store i32 %42, ptr %5, align 4, !tbaa !11
  br label %25, !llvm.loop !17

43:                                               ; preds = %25
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ENetBuffer, ptr %44, i32 1
  store ptr %45, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %12, !llvm.loop !19

46:                                               ; preds = %12
  %47 = load i32, ptr %5, align 4, !tbaa !11
  %48 = xor i32 %47, -1
  %49 = call i32 @__bswap_32(i32 noundef %48)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %49
}

; Function Attrs: nounwind uwtable
declare hidden void @initialize_crc32() #1

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

@initializedCRC32 = external hidden local_unnamed_addr global i32, align 4
@crcTable = external hidden local_unnamed_addr global [256 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @enet_crc32(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @initializedCRC32, align 4, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %5

4:                                                ; preds = %2
  tail call void @initialize_crc32()
  br label %5

5:                                                ; preds = %4, %2
  %.not1316 = icmp eq i64 %1, 0
  br i1 %.not1316, label %._crit_edge21, label %.lr.ph20

.lr.ph20:                                         ; preds = %5, %._crit_edge
  %.in = phi i64 [ %6, %._crit_edge ], [ %1, %5 ]
  %.018 = phi ptr [ %23, %._crit_edge ], [ %0, %5 ]
  %.01117 = phi i32 [ %.1.lcssa, %._crit_edge ], [ -1, %5 ]
  %6 = add i64 %.in, -1
  %7 = load ptr, ptr %.018, align 8, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %.018, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %7, i64 %9
  %11 = icmp sgt i64 %9, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph20, %.lr.ph
  %.01015 = phi ptr [ %14, %.lr.ph ], [ %7, %.lr.ph20 ]
  %.114 = phi i32 [ %21, %.lr.ph ], [ %.01117, %.lr.ph20 ]
  %12 = lshr i32 %.114, 8
  %13 = and i32 %.114, 255
  %14 = getelementptr inbounds i8, ptr %.01015, i64 1
  %15 = load i8, ptr %.01015, align 1, !tbaa !14
  %16 = zext i8 %15 to i32
  %17 = xor i32 %13, %16
  %18 = zext nneg i32 %17 to i64
  %19 = getelementptr inbounds [256 x i32], ptr @crcTable, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = xor i32 %20, %12
  %22 = icmp ult ptr %14, %10
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph20
  %.1.lcssa = phi i32 [ %.01117, %.lr.ph20 ], [ %21, %.lr.ph ]
  %23 = getelementptr inbounds i8, ptr %.018, i64 16
  %.not13 = icmp eq i64 %6, 0
  br i1 %.not13, label %._crit_edge21.loopexit, label %.lr.ph20, !llvm.loop !17

._crit_edge21.loopexit:                           ; preds = %._crit_edge
  %24 = xor i32 %.1.lcssa, -1
  br label %._crit_edge21

._crit_edge21:                                    ; preds = %._crit_edge21.loopexit, %5
  %.011.lcssa = phi i32 [ 0, %5 ], [ %24, %._crit_edge21.loopexit ]
  %25 = tail call i32 @__bswap_32(i32 noundef %.011.lcssa)
  ret i32 %25
}

; Function Attrs: nounwind uwtable
declare hidden void @initialize_crc32() local_unnamed_addr #0

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

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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