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

; 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::LzwEncoder" = type { %"class.vl::stream::LzwBase", %"class.vl::stream::IEncoder", ptr, [1024 x i8], i64, ptr }
%"class.vl::stream::LzwBase" = type { %"class.vl::Object", %"class.vl::collections::PushOnlyAllocator", %"class.vl::collections::PushOnlyAllocator.30", ptr, i64, i64, i64 }
%"class.vl::Object" = type { ptr }
%"class.vl::collections::PushOnlyAllocator" = type { %"class.vl::Object", i64, i64, %"class.vl::collections::List.22" }
%"class.vl::collections::List.22" = type { %"class.vl::collections::ListBase.base.28", %"class.vl::collections::IEnumerable.26" }
%"class.vl::collections::ListBase.base.28" = type <{ %"class.vl::collections::ArrayBase.base.27", i64, i8 }>
%"class.vl::collections::ArrayBase.base.27" = type { %"class.vl::collections::ListStore.25", ptr, i64 }
%"class.vl::collections::ListStore.25" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable.26" = type { %"class.vl::Interface" }
%"class.vl::Interface" = type { ptr }
%"class.vl::collections::PushOnlyAllocator.30" = type { %"class.vl::Object", i64, i64, %"class.vl::collections::List.31" }
%"class.vl::collections::List.31" = type { %"class.vl::collections::ListBase.base.37", %"class.vl::collections::IEnumerable.35" }
%"class.vl::collections::ListBase.base.37" = type <{ %"class.vl::collections::ArrayBase.base.36", i64, i8 }>
%"class.vl::collections::ArrayBase.base.36" = type { %"class.vl::collections::ListStore.34", ptr, i64 }
%"class.vl::collections::ListStore.34" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable.35" = type { %"class.vl::Interface" }
%"class.vl::stream::IEncoder" = type { %"class.vl::Interface" }
%"struct.vl::stream::lzw::Code" = type { i8, i64, ptr, i64, %"class.vl::collections::ByteObjectMap" }
%"class.vl::collections::ByteObjectMap" = type { %"class.vl::Object", ptr }

; 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 nounwind uwtable
declare dso_local void @_ZN2vl6stream7LzwBase15UpdateIndexBitsEv(ptr noundef nonnull align 8 dereferenceable(184)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN2vl6stream7LzwBase10CreateCodeEPNS0_3lzw4CodeEh(ptr noundef nonnull align 8 dereferenceable(184), ptr noundef, i8 noundef zeroext) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl6stream10LzwEncoder11WriteNumberEll(ptr noundef nonnull align 8 dereferenceable(1240), i64 noundef, i64 noundef) #2 align 2

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

13:                                               ; preds = %56, %3
  %14 = load i64, ptr %8, align 8, !tbaa !9
  %15 = load i64, ptr %6, align 8, !tbaa !9
  %16 = icmp slt i64 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %59

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %19, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11
  store i8 %22, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %23 = getelementptr inbounds %"class.vl::stream::LzwEncoder", ptr %11, i32 0, i32 5
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = getelementptr inbounds %"struct.vl::stream::lzw::Code", ptr %24, i32 0, i32 4
  %26 = load i8, ptr %9, align 1, !tbaa !11
  %27 = call noundef ptr @_ZN2vl11collections13ByteObjectMapINS_6stream3lzw4CodeEE3GetEh(ptr noundef nonnull align 8 dereferenceable(16) %25, i8 noundef zeroext %26)
  store ptr %27, ptr %10, align 8, !tbaa !5
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %33

30:                                               ; preds = %18
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %"class.vl::stream::LzwEncoder", ptr %11, i32 0, i32 5
  store ptr %31, ptr %32, align 8, !tbaa !12
  br label %55

33:                                               ; preds = %18
  %34 = getelementptr inbounds %"class.vl::stream::LzwEncoder", ptr %11, i32 0, i32 5
  %35 = load ptr, ptr %34, align 8, !tbaa !12
  %36 = getelementptr inbounds %"struct.vl::stream::lzw::Code", ptr %35, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !29
  %38 = getelementptr inbounds %"class.vl::stream::LzwBase", ptr %11, i32 0, i32 6
  %39 = load i64, ptr %38, align 8, !tbaa !32
  call void @_ZN2vl6stream10LzwEncoder11WriteNumberEll(ptr noundef nonnull align 8 dereferenceable(1240) %11, i64 noundef %37, i64 noundef %39)
  %40 = getelementptr inbounds %"class.vl::stream::LzwBase", ptr %11, i32 0, i32 5
  %41 = load i64, ptr %40, align 8, !tbaa !33
  %42 = icmp slt i64 %41, 16777216
  br i1 %42, label %43, label %48

43:                                               ; preds = %33
  call void @_ZN2vl6stream7LzwBase15UpdateIndexBitsEv(ptr noundef nonnull align 8 dereferenceable(184) %11)
  %44 = getelementptr inbounds %"class.vl::stream::LzwEncoder", ptr %11, i32 0, i32 5
  %45 = load ptr, ptr %44, align 8, !tbaa !12
  %46 = load i8, ptr %9, align 1, !tbaa !11
  %47 = call noundef ptr @_ZN2vl6stream7LzwBase10CreateCodeEPNS0_3lzw4CodeEh(ptr noundef nonnull align 8 dereferenceable(184) %11, ptr noundef %45, i8 noundef zeroext %46)
  br label %48

48:                                               ; preds = %43, %33
  %49 = getelementptr inbounds %"class.vl::stream::LzwBase", ptr %11, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !34
  %51 = getelementptr inbounds %"struct.vl::stream::lzw::Code", ptr %50, i32 0, i32 4
  %52 = load i8, ptr %9, align 1, !tbaa !11
  %53 = call noundef ptr @_ZN2vl11collections13ByteObjectMapINS_6stream3lzw4CodeEE3GetEh(ptr noundef nonnull align 8 dereferenceable(16) %51, i8 noundef zeroext %52)
  %54 = getelementptr inbounds %"class.vl::stream::LzwEncoder", ptr %11, i32 0, i32 5
  store ptr %53, ptr %54, align 8, !tbaa !12
  br label %55

55:                                               ; preds = %48, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  br label %56

56:                                               ; preds = %55
  %57 = load i64, ptr %8, align 8, !tbaa !9
  %58 = add nsw i64 %57, 1
  store i64 %58, ptr %8, align 8, !tbaa !9
  br label %13, !llvm.loop !35

59:                                               ; preds = %17
  %60 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %60
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN2vl11collections13ByteObjectMapINS_6stream3lzw4CodeEE3GetEh(ptr noundef nonnull align 8 dereferenceable(16), i8 noundef zeroext) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 1232}
!13 = !{!"_ZTSN2vl6stream10LzwEncoderE", !14, i64 0, !27, i64 184, !6, i64 192, !7, i64 200, !10, i64 1224, !6, i64 1232}
!14 = !{!"_ZTSN2vl6stream7LzwBaseE", !15, i64 0, !16, i64 8, !22, i64 80, !6, i64 152, !10, i64 160, !10, i64 168, !10, i64 176}
!15 = !{!"_ZTSN2vl6ObjectE"}
!16 = !{!"_ZTSN2vl11collections17PushOnlyAllocatorINS_6stream3lzw4CodeEEE", !15, i64 0, !10, i64 8, !10, i64 16, !17, i64 24}
!17 = !{!"_ZTSN2vl11collections4ListIPNS_6stream3lzw4CodeES5_EE", !18, i64 0}
!18 = !{!"_ZTSN2vl11collections8ListBaseIPNS_6stream3lzw4CodeES5_EE", !19, i64 0, !10, i64 24, !21, i64 32}
!19 = !{!"_ZTSN2vl11collections9ArrayBaseIPNS_6stream3lzw4CodeEEE", !20, i64 0, !6, i64 8, !10, i64 16}
!20 = !{!"_ZTSN2vl11collections9ListStoreIPNS_6stream3lzw4CodeELb1EEE", !15, i64 0}
!21 = !{!"bool", !7, i64 0}
!22 = !{!"_ZTSN2vl11collections17PushOnlyAllocatorINS0_10bom_helper8TreeNodeEEE", !15, i64 0, !10, i64 8, !10, i64 16, !23, i64 24}
!23 = !{!"_ZTSN2vl11collections4ListIPNS0_10bom_helper8TreeNodeES4_EE", !24, i64 0}
!24 = !{!"_ZTSN2vl11collections8ListBaseIPNS0_10bom_helper8TreeNodeES4_EE", !25, i64 0, !10, i64 24, !21, i64 32}
!25 = !{!"_ZTSN2vl11collections9ArrayBaseIPNS0_10bom_helper8TreeNodeEEE", !26, i64 0, !6, i64 8, !10, i64 16}
!26 = !{!"_ZTSN2vl11collections9ListStoreIPNS0_10bom_helper8TreeNodeELb1EEE", !15, i64 0}
!27 = !{!"_ZTSN2vl6stream8IEncoderE", !28, i64 0}
!28 = !{!"_ZTSN2vl9InterfaceE"}
!29 = !{!30, !10, i64 8}
!30 = !{!"_ZTSN2vl6stream3lzw4CodeE", !7, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !31, i64 32}
!31 = !{!"_ZTSN2vl11collections13ByteObjectMapINS_6stream3lzw4CodeEEE", !15, i64 0, !6, i64 8}
!32 = !{!14, !10, i64 176}
!33 = !{!14, !10, i64 168}
!34 = !{!14, !6, i64 152}
!35 = distinct !{!35, !36}
!36 = !{!"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 void @_ZN2vl6stream7LzwBase15UpdateIndexBitsEv(ptr noundef nonnull align 8 dereferenceable(184)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN2vl6stream7LzwBase10CreateCodeEPNS0_3lzw4CodeEh(ptr noundef nonnull align 8 dereferenceable(184), ptr noundef, i8 noundef zeroext) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl6stream10LzwEncoder11WriteNumberEll(ptr noundef nonnull align 8 dereferenceable(1240), i64 noundef, i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN2vl6stream10LzwEncoder5WriteEPvl(ptr noundef nonnull align 8 dereferenceable(1240) %0, ptr nocapture noundef readonly %1, i64 noundef returned %2) unnamed_addr #1 align 2 {
  %4 = icmp sgt i64 %2, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 1232
  %6 = getelementptr inbounds i8, ptr %0, i64 176
  %7 = getelementptr inbounds i8, ptr %0, i64 168
  %8 = getelementptr inbounds i8, ptr %0, i64 152
  %.pre = load ptr, ptr %5, align 8, !tbaa !5
  br label %9

._crit_edge:                                      ; preds = %29, %3
  ret i64 %2

9:                                                ; preds = %.lr.ph, %29
  %10 = phi ptr [ %.pre, %.lr.ph ], [ %storemerge, %29 ]
  %.014 = phi i64 [ 0, %.lr.ph ], [ %30, %29 ]
  %11 = getelementptr inbounds i8, ptr %1, i64 %.014
  %12 = load i8, ptr %11, align 1, !tbaa !26
  %13 = getelementptr inbounds i8, ptr %10, i64 32
  %14 = tail call noundef ptr @_ZN2vl11collections13ByteObjectMapINS_6stream3lzw4CodeEE3GetEh(ptr noundef nonnull align 8 dereferenceable(16) %13, i8 noundef zeroext %12)
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %15, label %29

15:                                               ; preds = %9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load i64, ptr %17, align 8, !tbaa !27
  %19 = load i64, ptr %6, align 8, !tbaa !30
  tail call void @_ZN2vl6stream10LzwEncoder11WriteNumberEll(ptr noundef nonnull align 8 dereferenceable(1240) %0, i64 noundef %18, i64 noundef %19)
  %20 = load i64, ptr %7, align 8, !tbaa !31
  %21 = icmp slt i64 %20, 16777216
  br i1 %21, label %22, label %25

22:                                               ; preds = %15
  tail call void @_ZN2vl6stream7LzwBase15UpdateIndexBitsEv(ptr noundef nonnull align 8 dereferenceable(184) %0)
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = tail call noundef ptr @_ZN2vl6stream7LzwBase10CreateCodeEPNS0_3lzw4CodeEh(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %23, i8 noundef zeroext %12)
  br label %25

25:                                               ; preds = %22, %15
  %26 = load ptr, ptr %8, align 8, !tbaa !32
  %27 = getelementptr inbounds i8, ptr %26, i64 32
  %28 = tail call noundef ptr @_ZN2vl11collections13ByteObjectMapINS_6stream3lzw4CodeEE3GetEh(ptr noundef nonnull align 8 dereferenceable(16) %27, i8 noundef zeroext %12)
  br label %29

29:                                               ; preds = %9, %25
  %storemerge = phi ptr [ %28, %25 ], [ %14, %9 ]
  store ptr %storemerge, ptr %5, align 8, !tbaa !5
  %30 = add nuw nsw i64 %.014, 1
  %exitcond.not = icmp eq i64 %30, %2
  br i1 %exitcond.not, label %._crit_edge, label %9, !llvm.loop !33
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN2vl11collections13ByteObjectMapINS_6stream3lzw4CodeEE3GetEh(ptr noundef nonnull align 8 dereferenceable(16), i8 noundef zeroext) local_unnamed_addr #1 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 = { 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" }

!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, !17, i64 1232}
!6 = !{!"_ZTSN2vl6stream10LzwEncoderE", !7, i64 0, !24, i64 184, !17, i64 192, !11, i64 200, !10, i64 1224, !17, i64 1232}
!7 = !{!"_ZTSN2vl6stream7LzwBaseE", !8, i64 0, !9, i64 8, !19, i64 80, !17, i64 152, !10, i64 160, !10, i64 168, !10, i64 176}
!8 = !{!"_ZTSN2vl6ObjectE"}
!9 = !{!"_ZTSN2vl11collections17PushOnlyAllocatorINS_6stream3lzw4CodeEEE", !8, i64 0, !10, i64 8, !10, i64 16, !13, i64 24}
!10 = !{!"long", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"_ZTSN2vl11collections4ListIPNS_6stream3lzw4CodeES5_EE", !14, i64 0}
!14 = !{!"_ZTSN2vl11collections8ListBaseIPNS_6stream3lzw4CodeES5_EE", !15, i64 0, !10, i64 24, !18, i64 32}
!15 = !{!"_ZTSN2vl11collections9ArrayBaseIPNS_6stream3lzw4CodeEEE", !16, i64 0, !17, i64 8, !10, i64 16}
!16 = !{!"_ZTSN2vl11collections9ListStoreIPNS_6stream3lzw4CodeELb1EEE", !8, i64 0}
!17 = !{!"any pointer", !11, i64 0}
!18 = !{!"bool", !11, i64 0}
!19 = !{!"_ZTSN2vl11collections17PushOnlyAllocatorINS0_10bom_helper8TreeNodeEEE", !8, i64 0, !10, i64 8, !10, i64 16, !20, i64 24}
!20 = !{!"_ZTSN2vl11collections4ListIPNS0_10bom_helper8TreeNodeES4_EE", !21, i64 0}
!21 = !{!"_ZTSN2vl11collections8ListBaseIPNS0_10bom_helper8TreeNodeES4_EE", !22, i64 0, !10, i64 24, !18, i64 32}
!22 = !{!"_ZTSN2vl11collections9ArrayBaseIPNS0_10bom_helper8TreeNodeEEE", !23, i64 0, !17, i64 8, !10, i64 16}
!23 = !{!"_ZTSN2vl11collections9ListStoreIPNS0_10bom_helper8TreeNodeELb1EEE", !8, i64 0}
!24 = !{!"_ZTSN2vl6stream8IEncoderE", !25, i64 0}
!25 = !{!"_ZTSN2vl9InterfaceE"}
!26 = !{!11, !11, i64 0}
!27 = !{!28, !10, i64 8}
!28 = !{!"_ZTSN2vl6stream3lzw4CodeE", !11, i64 0, !10, i64 8, !17, i64 16, !10, i64 24, !29, i64 32}
!29 = !{!"_ZTSN2vl11collections13ByteObjectMapINS_6stream3lzw4CodeEEE", !8, i64 0, !17, i64 8}
!30 = !{!7, !10, i64 176}
!31 = !{!7, !10, i64 168}
!32 = !{!7, !17, i64 152}
!33 = distinct !{!33, !34}
!34 = !{!"llvm.loop.mustprogress"}


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