; LLVM IR from vczh/herodb :: Kernel/Source/Vlpp.ll (ZN2vl6stream15BroadcastStream5WriteEPvl)

; 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.vl::stream::BroadcastStream" = type { %"class.vl::Object", i8, i64, %"class.vl::collections::List.1115", %"class.vl::stream::IStream" }
%"class.vl::Object" = type { ptr }
%"class.vl::collections::List.1115" = type { %"class.vl::collections::ListBase.base.1121", %"class.vl::collections::IEnumerable.1119" }
%"class.vl::collections::ListBase.base.1121" = type <{ %"class.vl::collections::ArrayBase.base.1120", i64, i8 }>
%"class.vl::collections::ArrayBase.base.1120" = type { %"class.vl::collections::ListStore.1118", ptr, i64 }
%"class.vl::collections::ListStore.1118" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable.1119" = type { %"class.vl::Interface" }
%"class.vl::Interface" = type { ptr }
%"class.vl::stream::IStream" = type { %"class.vl::Interface" }

; 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: mustprogress uwtable
define dso_local noundef i64 @_ZN2vl6stream15BroadcastStream5WriteEPvl(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %26, %3
  %10 = load i64, ptr %7, align 8, !tbaa !9
  %11 = getelementptr inbounds %"class.vl::stream::BroadcastStream", ptr %8, i32 0, i32 3
  %12 = call noundef i64 @_ZNK2vl11collections9ArrayBaseIPNS_6stream7IStreamEE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %11)
  %13 = icmp slt i64 %10, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %29

15:                                               ; preds = %9
  %16 = getelementptr inbounds %"class.vl::stream::BroadcastStream", ptr %8, i32 0, i32 3
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2vl11collections4ListIPNS_6stream7IStreamES4_EixEl(ptr noundef nonnull align 8 dereferenceable(33) %16, i64 noundef %17)
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = load ptr, ptr %19, align 8, !tbaa !11
  %23 = getelementptr inbounds ptr, ptr %22, i64 15
  %24 = load ptr, ptr %23, align 8
  %25 = call noundef i64 %24(ptr noundef nonnull align 8 dereferenceable(8) %19, ptr noundef %20, i64 noundef %21)
  br label %26

26:                                               ; preds = %15
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = add nsw i64 %27, 1
  store i64 %28, ptr %7, align 8, !tbaa !9
  br label %9, !llvm.loop !13

29:                                               ; preds = %14
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = getelementptr inbounds %"class.vl::stream::BroadcastStream", ptr %8, i32 0, i32 2
  %32 = load i64, ptr %31, align 8, !tbaa !15
  %33 = add nsw i64 %32, %30
  store i64 %33, ptr %31, align 8, !tbaa !15
  %34 = load i64, ptr %6, align 8, !tbaa !9
  ret i64 %34
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN2vl11collections4ListIPNS_6stream7IStreamES4_EixEl(ptr noundef nonnull align 8 dereferenceable(33), i64 noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 16}
!16 = !{!"_ZTSN2vl6stream15BroadcastStreamE", !17, i64 0, !18, i64 8, !10, i64 16, !19, i64 24}
!17 = !{!"_ZTSN2vl6ObjectE"}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"_ZTSN2vl11collections4ListIPNS_6stream7IStreamES4_EE", !20, i64 0}
!20 = !{!"_ZTSN2vl11collections8ListBaseIPNS_6stream7IStreamES4_EE", !21, i64 0, !10, i64 24, !18, i64 32}
!21 = !{!"_ZTSN2vl11collections9ArrayBaseIPNS_6stream7IStreamEEE", !22, i64 0, !6, i64 8, !10, i64 16}
!22 = !{!"_ZTSN2vl11collections9ListStoreIPNS_6stream7IStreamELb1EEE", !17, i64 0}


; 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 uwtable
define dso_local noundef i64 @_ZN2vl6stream15BroadcastStream5WriteEPvl(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef %1, i64 noundef returned %2) unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = tail call noundef i64 @_ZNK2vl11collections9ArrayBaseIPNS_6stream7IStreamEE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  %6 = icmp sgt i64 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %3
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = add nsw i64 %8, %2
  store i64 %9, ptr %7, align 8, !tbaa !5
  ret i64 %2

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.07 = phi i64 [ %16, %.lr.ph ], [ 0, %3 ]
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN2vl11collections4ListIPNS_6stream7IStreamES4_EixEl(ptr noundef nonnull align 8 dereferenceable(33) %4, i64 noundef %.07)
  %11 = load ptr, ptr %10, align 8, !tbaa !17
  %12 = load ptr, ptr %11, align 8, !tbaa !18
  %13 = getelementptr inbounds i8, ptr %12, i64 120
  %14 = load ptr, ptr %13, align 8
  %15 = tail call noundef i64 %14(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef %1, i64 noundef %2)
  %16 = add nuw nsw i64 %.07, 1
  %17 = tail call noundef i64 @_ZNK2vl11collections9ArrayBaseIPNS_6stream7IStreamEE5CountEv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  %18 = icmp slt i64 %16, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !20
}

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

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

attributes #0 = { 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 #1 = { 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" }

!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, !11, i64 16}
!6 = !{!"_ZTSN2vl6stream15BroadcastStreamE", !7, i64 0, !8, i64 8, !11, i64 16, !12, i64 24}
!7 = !{!"_ZTSN2vl6ObjectE"}
!8 = !{!"bool", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"_ZTSN2vl11collections4ListIPNS_6stream7IStreamES4_EE", !13, i64 0}
!13 = !{!"_ZTSN2vl11collections8ListBaseIPNS_6stream7IStreamES4_EE", !14, i64 0, !11, i64 24, !8, i64 32}
!14 = !{!"_ZTSN2vl11collections9ArrayBaseIPNS_6stream7IStreamEEE", !15, i64 0, !16, i64 8, !11, i64 16}
!15 = !{!"_ZTSN2vl11collections9ListStoreIPNS_6stream7IStreamELb1EEE", !7, i64 0}
!16 = !{!"any pointer", !9, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !10, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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