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

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

@_ZTIN2vl5ErrorE = external dso_local constant { ptr, ptr }, align 8
@.str.584 = external hidden unnamed_addr constant [52 x i32], align 4

; 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

declare i32 @__gxx_personality_v0(...)

declare ptr @__cxa_allocate_exception(i64)

declare void @__cxa_throw(ptr, ptr, ptr)

declare void @__cxa_free_exception(ptr)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2vl6stream10LzwEncoder5FlushEv(ptr noundef nonnull align 8 dereferenceable(1240) %0) #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %9 = getelementptr inbounds %"class.vl::stream::LzwEncoder", ptr %8, i32 0, i32 4
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %11 = sdiv i64 %10, 8
  store i64 %11, ptr %4, align 8, !tbaa !9
  %12 = getelementptr inbounds %"class.vl::stream::LzwEncoder", ptr %8, i32 0, i32 4
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = srem i64 %13, 8
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %1
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = add nsw i64 %17, 1
  store i64 %18, ptr %4, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %16, %1
  br label %20

20:                                               ; preds = %50, %19
  %21 = load i64, ptr %3, align 8, !tbaa !9
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = icmp slt i64 %21, %22
  br i1 %23, label %24, label %54

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %25 = getelementptr inbounds %"class.vl::stream::LzwEncoder", ptr %8, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !28
  %27 = getelementptr inbounds %"class.vl::stream::LzwEncoder", ptr %8, i32 0, i32 3
  %28 = getelementptr inbounds [1024 x i8], ptr %27, i64 0, i64 0
  %29 = load i64, ptr %3, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %28, i64 %29
  %31 = load i64, ptr %4, align 8, !tbaa !9
  %32 = load i64, ptr %3, align 8, !tbaa !9
  %33 = sub nsw i64 %31, %32
  %34 = load ptr, ptr %26, align 8, !tbaa !29
  %35 = getelementptr inbounds ptr, ptr %34, i64 15
  %36 = load ptr, ptr %35, align 8
  %37 = call noundef i64 %36(ptr noundef nonnull align 8 dereferenceable(8) %26, ptr noundef %30, i64 noundef %33)
  store i64 %37, ptr %5, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %24
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = icmp ne i64 %39, 0
  br i1 %40, label %48, label %41

41:                                               ; preds = %38
  %42 = call ptr @__cxa_allocate_exception(i64 8) #2
  invoke void @_ZN2vl5ErrorC1EPKw(ptr noundef nonnull align 8 dereferenceable(8) %42, ptr noundef @.str.584)
          to label %43 unwind label %44

43:                                               ; preds = %41
  call void @__cxa_throw(ptr %42, ptr @_ZTIN2vl5ErrorE, ptr null) #3
  unreachable

44:                                               ; preds = %41
  %45 = landingpad { ptr, i32 }
          cleanup
  %46 = extractvalue { ptr, i32 } %45, 0
  store ptr %46, ptr %6, align 8
  %47 = extractvalue { ptr, i32 } %45, 1
  store i32 %47, ptr %7, align 4
  call void @__cxa_free_exception(ptr %42) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %56

48:                                               ; preds = %38
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = load i64, ptr %5, align 8, !tbaa !9
  %52 = load i64, ptr %3, align 8, !tbaa !9
  %53 = add nsw i64 %52, %51
  store i64 %53, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %20, !llvm.loop !31

54:                                               ; preds = %20
  %55 = getelementptr inbounds %"class.vl::stream::LzwEncoder", ptr %8, i32 0, i32 4
  store i64 0, ptr %55, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void

56:                                               ; preds = %44
  %57 = load ptr, ptr %6, align 8
  %58 = load i32, ptr %7, align 4
  %59 = insertvalue { ptr, i32 } poison, ptr %57, 0
  %60 = insertvalue { ptr, i32 } %59, i32 %58, 1
  resume { ptr, i32 } %60
}

declare void @_ZN2vl5ErrorC1EPKw(ptr, ptr)

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 = { nounwind }
attributes #3 = { noreturn }

!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, !10, i64 1224}
!12 = !{!"_ZTSN2vl6stream10LzwEncoderE", !13, i64 0, !26, i64 184, !6, i64 192, !7, i64 200, !10, i64 1224, !6, i64 1232}
!13 = !{!"_ZTSN2vl6stream7LzwBaseE", !14, i64 0, !15, i64 8, !21, i64 80, !6, i64 152, !10, i64 160, !10, i64 168, !10, i64 176}
!14 = !{!"_ZTSN2vl6ObjectE"}
!15 = !{!"_ZTSN2vl11collections17PushOnlyAllocatorINS_6stream3lzw4CodeEEE", !14, i64 0, !10, i64 8, !10, i64 16, !16, i64 24}
!16 = !{!"_ZTSN2vl11collections4ListIPNS_6stream3lzw4CodeES5_EE", !17, i64 0}
!17 = !{!"_ZTSN2vl11collections8ListBaseIPNS_6stream3lzw4CodeES5_EE", !18, i64 0, !10, i64 24, !20, i64 32}
!18 = !{!"_ZTSN2vl11collections9ArrayBaseIPNS_6stream3lzw4CodeEEE", !19, i64 0, !6, i64 8, !10, i64 16}
!19 = !{!"_ZTSN2vl11collections9ListStoreIPNS_6stream3lzw4CodeELb1EEE", !14, i64 0}
!20 = !{!"bool", !7, i64 0}
!21 = !{!"_ZTSN2vl11collections17PushOnlyAllocatorINS0_10bom_helper8TreeNodeEEE", !14, i64 0, !10, i64 8, !10, i64 16, !22, i64 24}
!22 = !{!"_ZTSN2vl11collections4ListIPNS0_10bom_helper8TreeNodeES4_EE", !23, i64 0}
!23 = !{!"_ZTSN2vl11collections8ListBaseIPNS0_10bom_helper8TreeNodeES4_EE", !24, i64 0, !10, i64 24, !20, i64 32}
!24 = !{!"_ZTSN2vl11collections9ArrayBaseIPNS0_10bom_helper8TreeNodeEEE", !25, i64 0, !6, i64 8, !10, i64 16}
!25 = !{!"_ZTSN2vl11collections9ListStoreIPNS0_10bom_helper8TreeNodeELb1EEE", !14, i64 0}
!26 = !{!"_ZTSN2vl6stream8IEncoderE", !27, i64 0}
!27 = !{!"_ZTSN2vl9InterfaceE"}
!28 = !{!12, !6, i64 192}
!29 = !{!30, !30, i64 0}
!30 = !{!"vtable pointer", !8, i64 0}
!31 = distinct !{!31, !32}
!32 = !{!"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"

@_ZTIN2vl5ErrorE = external dso_local constant { ptr, ptr }, align 8
@.str.584 = external hidden unnamed_addr constant [52 x i32], align 4

declare i32 @__gxx_personality_v0(...)

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

declare void @__cxa_free_exception(ptr) local_unnamed_addr

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2vl6stream10LzwEncoder5FlushEv(ptr noundef nonnull align 8 dereferenceable(1240) %0) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 1224
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = sdiv i64 %3, 8
  %5 = and i64 %3, 7
  %.not = icmp ne i64 %5, 0
  %6 = zext i1 %.not to i64
  %spec.select = add nsw i64 %4, %6
  %7 = icmp sgt i64 %spec.select, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 192
  %9 = getelementptr inbounds i8, ptr %0, i64 200
  br label %13

10:                                               ; preds = %13
  %11 = add nsw i64 %20, %.014
  %12 = icmp slt i64 %11, %spec.select
  br i1 %12, label %13, label %._crit_edge, !llvm.loop !26

13:                                               ; preds = %.lr.ph, %10
  %.014 = phi i64 [ 0, %.lr.ph ], [ %11, %10 ]
  %14 = load ptr, ptr %8, align 8, !tbaa !28
  %15 = getelementptr inbounds i8, ptr %9, i64 %.014
  %16 = sub nsw i64 %spec.select, %.014
  %17 = load ptr, ptr %14, align 8, !tbaa !29
  %18 = getelementptr inbounds i8, ptr %17, i64 120
  %19 = load ptr, ptr %18, align 8
  %20 = tail call noundef i64 %19(ptr noundef nonnull align 8 dereferenceable(8) %14, ptr noundef nonnull %15, i64 noundef %16)
  %.not13 = icmp eq i64 %20, 0
  br i1 %.not13, label %21, label %10

21:                                               ; preds = %13
  %22 = tail call ptr @__cxa_allocate_exception(i64 8) #1
  invoke void @_ZN2vl5ErrorC1EPKw(ptr noundef nonnull align 8 dereferenceable(8) %22, ptr noundef nonnull @.str.584)
          to label %23 unwind label %24

23:                                               ; preds = %21
  tail call void @__cxa_throw(ptr %22, ptr nonnull @_ZTIN2vl5ErrorE, ptr null) #2
  unreachable

24:                                               ; preds = %21
  %25 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_free_exception(ptr %22) #1
  resume { ptr, i32 } %25

._crit_edge:                                      ; preds = %10, %1
  store i64 0, ptr %2, align 8, !tbaa !5
  ret void
}

declare void @_ZN2vl5ErrorC1EPKw(ptr, ptr) local_unnamed_addr

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 = { nounwind }
attributes #2 = { noreturn }

!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 1224}
!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 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!6, !17, i64 192}
!29 = !{!30, !30, i64 0}
!30 = !{!"vtable pointer", !12, i64 0}


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