; LLVM IR from Bousk/Net :: NetworkLib/src/UDP (ChannelsHandler)

; 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.Bousk::Network::UDP::ChannelHeader" = type { i32, i16 }
%"class.Bousk::Network::UDP::ChannelsHandler" = type { %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::unique_ptr<Bousk::Network::UDP::Protocols::IProtocol>, std::allocator<std::unique_ptr<Bousk::Network::UDP::Protocols::IProtocol>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::unique_ptr<Bousk::Network::UDP::Protocols::IProtocol>, std::allocator<std::unique_ptr<Bousk::Network::UDP::Protocols::IProtocol>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::unique_ptr<Bousk::Network::UDP::Protocols::IProtocol>, std::allocator<std::unique_ptr<Bousk::Network::UDP::Protocols::IProtocol>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::unique_ptr<Bousk::Network::UDP::Protocols::IProtocol>, std::allocator<std::unique_ptr<Bousk::Network::UDP::Protocols::IProtocol>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS4_EEptEv(ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5Bousk7Network3UDP15ChannelsHandler14onDataReceivedEPKht(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i16 noundef zeroext %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i16, align 2
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i16 %2, ptr %6, align 2, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  store i16 0, ptr %7, align 2, !tbaa !9
  br label %12

12:                                               ; preds = %81, %3
  %13 = load i16, ptr %7, align 2, !tbaa !9
  %14 = zext i16 %13 to i32
  %15 = load i16, ptr %6, align 2, !tbaa !9
  %16 = zext i16 %15 to i32
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %18, label %82

18:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %19, ptr %8, align 8, !tbaa !5
  %20 = load i16, ptr %7, align 2, !tbaa !9
  %21 = zext i16 %20 to i32
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.Bousk::Network::UDP::ChannelHeader", ptr %22, i32 0, i32 1
  %24 = load i16, ptr %23, align 4, !tbaa !11
  %25 = zext i16 %24 to i32
  %26 = add nsw i32 %21, %25
  %27 = load i16, ptr %6, align 2, !tbaa !9
  %28 = zext i16 %27 to i32
  %29 = icmp sgt i32 %26, %28
  br i1 %29, label %36, label %30

30:                                               ; preds = %18
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.Bousk::Network::UDP::ChannelHeader", ptr %31, i32 0, i32 1
  %33 = load i16, ptr %32, align 4, !tbaa !11
  %34 = zext i16 %33 to i32
  %35 = icmp sgt i32 %34, 1376
  br i1 %35, label %36, label %37

36:                                               ; preds = %30, %18
  store i32 1, ptr %9, align 4
  br label %79

37:                                               ; preds = %30
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.Bousk::Network::UDP::ChannelHeader", ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 4, !tbaa !14
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds %"class.Bousk::Network::UDP::ChannelsHandler", ptr %11, i32 0, i32 0
  %43 = call noundef i64 @_ZNKSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %42) #3
  %44 = icmp uge i64 %41, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %37
  store i32 1, ptr %9, align 4
  br label %79

46:                                               ; preds = %37
  %47 = getelementptr inbounds %"class.Bousk::Network::UDP::ChannelsHandler", ptr %11, i32 0, i32 0
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.Bousk::Network::UDP::ChannelHeader", ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 4, !tbaa !14
  %51 = zext i32 %50 to i64
  %52 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %47, i64 noundef %51) #3
  %53 = call noundef ptr @_ZNKSt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS4_EEptEv(ptr noundef nonnull align 8 dereferenceable(8) %52) #3
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 6
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds %"struct.Bousk::Network::UDP::ChannelHeader", ptr %56, i32 0, i32 1
  %58 = load i16, ptr %57, align 4, !tbaa !11
  %59 = load ptr, ptr %53, align 8, !tbaa !15
  %60 = getelementptr inbounds ptr, ptr %59, i64 6
  %61 = load ptr, ptr %60, align 8
  call void %61(ptr noundef nonnull align 8 dereferenceable(9) %53, ptr noundef %55, i16 noundef zeroext %58)
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %"struct.Bousk::Network::UDP::ChannelHeader", ptr %62, i32 0, i32 1
  %64 = load i16, ptr %63, align 4, !tbaa !11
  %65 = zext i16 %64 to i32
  %66 = add nsw i32 %65, 6
  %67 = trunc i32 %66 to i16
  store i16 %67, ptr %10, align 2, !tbaa !9
  %68 = load i16, ptr %10, align 2, !tbaa !9
  %69 = zext i16 %68 to i32
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = sext i32 %69 to i64
  %72 = getelementptr inbounds i8, ptr %70, i64 %71
  store ptr %72, ptr %5, align 8, !tbaa !5
  %73 = load i16, ptr %10, align 2, !tbaa !9
  %74 = zext i16 %73 to i32
  %75 = load i16, ptr %7, align 2, !tbaa !9
  %76 = zext i16 %75 to i32
  %77 = add nsw i32 %76, %74
  %78 = trunc i32 %77 to i16
  store i16 %78, ptr %7, align 2, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  store i32 0, ptr %9, align 4
  br label %79

79:                                               ; preds = %46, %45, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %80 = load i32, ptr %9, align 4
  switch i32 %80, label %83 [
    i32 0, label %81
  ]

81:                                               ; preds = %79
  br label %12, !llvm.loop !17

82:                                               ; preds = %12
  store i32 0, ptr %9, align 4
  br label %83

83:                                               ; preds = %82, %79
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  %84 = load i32, ptr %9, align 4
  switch i32 %84, label %86 [
    i32 0, label %85
    i32 1, label %85
  ]

85:                                               ; preds = %83, %83
  ret void

86:                                               ; preds = %83
  unreachable
}

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTSN5Bousk7Network3UDP13ChannelHeaderE", !13, i64 0, !10, i64 4}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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 nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS4_EEptEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5Bousk7Network3UDP15ChannelsHandler14onDataReceivedEPKht(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i16 noundef zeroext %2) local_unnamed_addr #1 align 2 {
  %.not29 = icmp eq i16 %2, 0
  br i1 %.not29, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %4 = zext i16 %2 to i32
  br label %5

5:                                                ; preds = %.lr.ph, %17
  %.026 = phi ptr [ %1, %.lr.ph ], [ %30, %17 ]
  %.01825 = phi i16 [ 0, %.lr.ph ], [ %31, %17 ]
  %6 = zext i16 %.01825 to i32
  %7 = getelementptr inbounds i8, ptr %.026, i64 4
  %8 = load i16, ptr %7, align 4, !tbaa !5
  %9 = zext i16 %8 to i32
  %10 = add nuw nsw i32 %9, %6
  %11 = icmp ugt i32 %10, %4
  %12 = icmp ugt i16 %8, 1376
  %or.cond = or i1 %12, %11
  br i1 %or.cond, label %.thread, label %13

13:                                               ; preds = %5
  %14 = load i32, ptr %.026, align 4, !tbaa !11
  %15 = zext i32 %14 to i64
  %16 = tail call noundef i64 @_ZNKSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %.not = icmp ugt i64 %16, %15
  br i1 %.not, label %17, label %.thread

17:                                               ; preds = %13
  %18 = load i32, ptr %.026, align 4, !tbaa !11
  %19 = zext i32 %18 to i64
  %20 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %19) #2
  %21 = tail call noundef ptr @_ZNKSt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS4_EEptEv(ptr noundef nonnull align 8 dereferenceable(8) %20) #2
  %22 = getelementptr inbounds i8, ptr %.026, i64 6
  %23 = load i16, ptr %7, align 4, !tbaa !5
  %24 = load ptr, ptr %21, align 8, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %24, i64 48
  %26 = load ptr, ptr %25, align 8
  tail call void %26(ptr noundef nonnull align 8 dereferenceable(9) %21, ptr noundef nonnull %22, i16 noundef zeroext %23)
  %27 = load i16, ptr %7, align 4, !tbaa !5
  %28 = add i16 %27, 6
  %29 = zext i16 %28 to i64
  %30 = getelementptr inbounds i8, ptr %.026, i64 %29
  %31 = add i16 %28, %.01825
  %32 = icmp ult i16 %31, %2
  br i1 %32, label %5, label %.thread, !llvm.loop !14

.thread:                                          ; preds = %17, %5, %13, %3
  ret void
}

attributes #0 = { mustprogress 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 = { mustprogress 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, !10, i64 4}
!6 = !{!"_ZTSN5Bousk7Network3UDP13ChannelHeaderE", !7, i64 0, !10, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"vtable pointer", !9, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass