; LLVM IR from pixelsdb/mini-pixels :: pixels-core/lib/encoding (RunLenIntEncoder)

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

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

declare void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62), i8 noundef zeroext) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN16RunLenIntEncoder11writeVulongESt10shared_ptrI10ByteBufferEl(ptr noundef nonnull align 8 dereferenceable(168) %0, ptr noundef %1, i64 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = 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
  %7 = load ptr, ptr %4, align 8
  br label %8

8:                                                ; preds = %26, %3
  %9 = load i64, ptr %6, align 8, !tbaa !9
  %10 = and i64 %9, -128
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %12, label %16

12:                                               ; preds = %8
  %13 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %1) #3
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = trunc i64 %14 to i8
  call void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62) %13, i8 noundef zeroext %15)
  ret void

16:                                               ; preds = %8
  %17 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %1) #3
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = and i64 %18, 127
  %20 = or i64 128, %19
  %21 = trunc i64 %20 to i8
  call void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62) %17, i8 noundef zeroext %21)
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = trunc i64 %22 to i32
  %24 = lshr i32 %23, 7
  %25 = zext i32 %24 to i64
  store i64 %25, ptr %6, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %16
  br label %8, !llvm.loop !11
}

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 = { "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 = distinct !{!11, !12}
!12 = !{!"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 ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #0 align 2

declare void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62), i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN16RunLenIntEncoder11writeVulongESt10shared_ptrI10ByteBufferEl(ptr nocapture noundef nonnull readnone align 8 dereferenceable(168) %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #2 align 2 {
  %4 = icmp ult i64 %2, 128
  br i1 %4, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.0.lcssa = phi i64 [ %2, %3 ], [ %11, %.lr.ph ]
  %5 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %1) #3
  %6 = trunc nuw i64 %.0.lcssa to i8
  tail call void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62) %5, i8 noundef zeroext %6)
  ret void

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.04 = phi i64 [ %11, %.lr.ph ], [ %2, %3 ]
  %7 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %1) #3
  %8 = trunc i64 %.04 to i8
  %9 = or i8 %8, -128
  tail call void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62) %7, i8 noundef zeroext %9)
  %10 = lshr i64 %.04, 7
  %11 = and i64 %10, 33554431
  %12 = icmp ult i64 %11, 128
  br i1 %12, label %._crit_edge, label %.lr.ph, !llvm.loop !5
}

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 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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