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

%"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 }
%"struct.Bousk::Network::UDP::ChannelHeader" = type { i32, i16 }

@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [39 x i8], align 1
@__PRETTY_FUNCTION__._ZN5Bousk7Network3UDP15ChannelsHandler9serializeEPhttb = external hidden unnamed_addr constant [110 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; 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 uwtable
define dso_local noundef zeroext i16 @_ZN5Bousk7Network3UDP15ChannelsHandler9serializeEPhttb(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i16 noundef zeroext %2, i16 noundef zeroext %3, i1 noundef zeroext %4) #2 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %10 = alloca i8, align 1
  %11 = alloca i16, align 2
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i16, align 2
  %17 = alloca i16, align 2
  %18 = alloca ptr, align 8
  %19 = alloca i16, align 2
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i16 %2, ptr %8, align 2, !tbaa !9
  store i16 %3, ptr %9, align 2, !tbaa !9
  %20 = zext i1 %4 to i8
  store i8 %20, ptr %10, align 1, !tbaa !11
  %21 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #4
  %22 = load i16, ptr %8, align 2, !tbaa !9
  store i16 %22, ptr %11, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !13
  br label %23

23:                                               ; preds = %90, %5
  %24 = load i32, ptr %12, align 4, !tbaa !13
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds %"class.Bousk::Network::UDP::ChannelsHandler", ptr %21, i32 0, i32 0
  %27 = call noundef i64 @_ZNKSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %26) #4
  %28 = icmp ult i64 %25, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %93

30:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %31 = getelementptr inbounds %"class.Bousk::Network::UDP::ChannelsHandler", ptr %21, i32 0, i32 0
  %32 = load i32, ptr %12, align 4, !tbaa !13
  %33 = zext i32 %32 to i64
  %34 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %31, i64 noundef %33) #4
  %35 = call noundef ptr @_ZNKSt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS4_EE3getEv(ptr noundef nonnull align 8 dereferenceable(8) %34) #4
  store ptr %35, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %36, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 6
  store ptr %38, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %16) #4
  %39 = load i16, ptr %11, align 2, !tbaa !9
  %40 = zext i16 %39 to i32
  %41 = sub nsw i32 %40, 6
  %42 = trunc i32 %41 to i16
  store i16 %42, ptr %16, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %17) #4
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = load ptr, ptr %15, align 8, !tbaa !5
  %45 = load i16, ptr %16, align 2, !tbaa !9
  %46 = load i16, ptr %9, align 2, !tbaa !9
  %47 = load i8, ptr %10, align 1, !tbaa !11, !range !15, !noundef !16
  %48 = trunc i8 %47 to i1
  %49 = load ptr, ptr %43, align 8, !tbaa !17
  %50 = getelementptr inbounds ptr, ptr %49, i64 3
  %51 = load ptr, ptr %50, align 8
  %52 = call noundef zeroext i16 %51(ptr noundef nonnull align 8 dereferenceable(9) %43, ptr noundef %44, i16 noundef zeroext %45, i16 noundef zeroext %46, i1 noundef zeroext %48)
  store i16 %52, ptr %17, align 2, !tbaa !9
  %53 = load i16, ptr %17, align 2, !tbaa !9
  %54 = zext i16 %53 to i32
  %55 = load i16, ptr %16, align 2, !tbaa !9
  %56 = zext i16 %55 to i32
  %57 = icmp sle i32 %54, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %30
  br label %61

59:                                               ; preds = %30
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 44, ptr noundef @__PRETTY_FUNCTION__._ZN5Bousk7Network3UDP15ChannelsHandler9serializeEPhttb) #5
  unreachable

60:                                               ; No predecessors!
  br label %61

61:                                               ; preds = %60, %58
  %62 = load i16, ptr %17, align 2, !tbaa !9
  %63 = icmp ne i16 %62, 0
  br i1 %63, label %64, label %89

64:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %65 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %65, ptr %18, align 8, !tbaa !5
  %66 = load i32, ptr %12, align 4, !tbaa !13
  %67 = load ptr, ptr %18, align 8, !tbaa !5
  %68 = getelementptr inbounds %"struct.Bousk::Network::UDP::ChannelHeader", ptr %67, i32 0, i32 0
  store i32 %66, ptr %68, align 4, !tbaa !19
  %69 = load i16, ptr %17, align 2, !tbaa !9
  %70 = zext i16 %69 to i32
  %71 = trunc i32 %70 to i16
  %72 = load ptr, ptr %18, align 8, !tbaa !5
  %73 = getelementptr inbounds %"struct.Bousk::Network::UDP::ChannelHeader", ptr %72, i32 0, i32 1
  store i16 %71, ptr %73, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 2, ptr %19) #4
  %74 = load i16, ptr %17, align 2, !tbaa !9
  %75 = zext i16 %74 to i32
  %76 = add nsw i32 %75, 6
  %77 = trunc i32 %76 to i16
  store i16 %77, ptr %19, align 2, !tbaa !9
  %78 = load i16, ptr %19, align 2, !tbaa !9
  %79 = zext i16 %78 to i32
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = sext i32 %79 to i64
  %82 = getelementptr inbounds i8, ptr %80, i64 %81
  store ptr %82, ptr %7, align 8, !tbaa !5
  %83 = load i16, ptr %19, align 2, !tbaa !9
  %84 = zext i16 %83 to i32
  %85 = load i16, ptr %11, align 2, !tbaa !9
  %86 = zext i16 %85 to i32
  %87 = sub nsw i32 %86, %84
  %88 = trunc i32 %87 to i16
  store i16 %88, ptr %11, align 2, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 2, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %89

89:                                               ; preds = %64, %61
  call void @llvm.lifetime.end.p0(i64 2, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %12, align 4, !tbaa !13
  %92 = add i32 %91, 1
  store i32 %92, ptr %12, align 4, !tbaa !13
  br label %23, !llvm.loop !22

93:                                               ; preds = %29
  %94 = load i16, ptr %8, align 2, !tbaa !9
  %95 = zext i16 %94 to i32
  %96 = load i16, ptr %11, align 2, !tbaa !9
  %97 = zext i16 %96 to i32
  %98 = sub nsw i32 %95, %97
  %99 = trunc i32 %98 to i16
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #4
  ret i16 %99
}

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

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

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

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 = { noreturn nounwind "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 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { noreturn 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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !8, i64 0}
!19 = !{!20, !14, i64 0}
!20 = !{!"_ZTSN5Bousk7Network3UDP13ChannelHeaderE", !14, i64 0, !10, i64 4}
!21 = !{!20, !10, i64 4}
!22 = distinct !{!22, !23}
!23 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [39 x i8], align 1
@__PRETTY_FUNCTION__._ZN5Bousk7Network3UDP15ChannelsHandler9serializeEPhttb = external hidden unnamed_addr constant [110 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; 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 uwtable
define dso_local noundef zeroext i16 @_ZN5Bousk7Network3UDP15ChannelsHandler9serializeEPhttb(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i16 noundef zeroext %2, i16 noundef zeroext %3, i1 noundef zeroext %4) local_unnamed_addr #2 align 2 {
  %6 = tail call noundef i64 @_ZNKSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  %.not38 = icmp eq i64 %6, 0
  br i1 %.not38, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %25, %5
  %.027.lcssa = phi i16 [ %2, %5 ], [ %.128, %25 ]
  %7 = sub i16 %2, %.027.lcssa
  ret i16 %7

.lr.ph:                                           ; preds = %5, %25
  %8 = phi i64 [ %27, %25 ], [ 0, %5 ]
  %.037 = phi ptr [ %.1, %25 ], [ %1, %5 ]
  %.02736 = phi i16 [ %.128, %25 ], [ %2, %5 ]
  %.02935 = phi i32 [ %26, %25 ], [ 0, %5 ]
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %8) #3
  %10 = tail call noundef ptr @_ZNKSt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS4_EE3getEv(ptr noundef nonnull align 8 dereferenceable(8) %9) #3
  %11 = getelementptr inbounds i8, ptr %.037, i64 6
  %12 = add i16 %.02736, -6
  %13 = load ptr, ptr %10, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 24
  %15 = load ptr, ptr %14, align 8
  %16 = tail call noundef zeroext i16 %15(ptr noundef nonnull align 8 dereferenceable(9) %10, ptr noundef nonnull %11, i16 noundef zeroext %12, i16 noundef zeroext %3, i1 noundef zeroext %4)
  %.not = icmp ugt i16 %16, %12
  br i1 %.not, label %17, label %18

17:                                               ; preds = %.lr.ph
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 44, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5Bousk7Network3UDP15ChannelsHandler9serializeEPhttb) #4
  unreachable

18:                                               ; preds = %.lr.ph
  %.not33 = icmp eq i16 %16, 0
  br i1 %.not33, label %25, label %19

19:                                               ; preds = %18
  store i32 %.02935, ptr %.037, align 4, !tbaa !8
  %20 = getelementptr inbounds i8, ptr %.037, i64 4
  store i16 %16, ptr %20, align 4, !tbaa !13
  %21 = add i16 %16, 6
  %22 = zext i16 %21 to i64
  %23 = getelementptr inbounds i8, ptr %.037, i64 %22
  %24 = sub i16 %.02736, %21
  br label %25

25:                                               ; preds = %19, %18
  %.128 = phi i16 [ %24, %19 ], [ %.02736, %18 ]
  %.1 = phi ptr [ %23, %19 ], [ %.037, %18 ]
  %26 = add i32 %.02935, 1
  %27 = zext i32 %26 to i64
  %28 = tail call noundef i64 @_ZNKSt6vectorISt10unique_ptrIN5Bousk7Network3UDP9Protocols9IProtocolESt14default_deleteIS5_EESaIS8_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  %29 = icmp ugt i64 %28, %27
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

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

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


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