; LLVM IR from pixelsdb/mini-pixels :: pixels-core/lib/encoding/RunLenIntDecoder.ll (ZN16RunLenIntDecoder16readDirectValuesEi)

; 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.RunLenIntDecoder = type <{ %class.Decoder, ptr, i8, [3 x i8], i32, i32, [4 x i8], %"class.std::shared_ptr", %class.EncodingUtils, i8, [7 x i8] }>
%class.Decoder = type { ptr }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%class.EncodingUtils = type { ptr, 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 noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) #1 align 2

declare noundef zeroext i8 @_ZN10ByteBuffer3getEv(ptr noundef nonnull align 8 dereferenceable(62)) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN16RunLenIntDecoder16readDirectValuesEi(ptr noundef nonnull align 8 dereferenceable(65) %0, i32 noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = ashr i32 %10, 1
  %12 = and i32 %11, 31
  %13 = trunc i32 %12 to i8
  store i8 %13, ptr %5, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %14 = getelementptr inbounds %class.RunLenIntDecoder, ptr %9, i32 0, i32 8
  %15 = load i8, ptr %5, align 1, !tbaa !11
  %16 = zext i8 %15 to i32
  %17 = call noundef i32 @_ZN13EncodingUtils14decodeBitWidthEi(ptr noundef nonnull align 8 dereferenceable(16) %14, i32 noundef %16)
  store i32 %17, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = and i32 %18, 1
  %20 = shl i32 %19, 8
  store i32 %20, ptr %7, align 4, !tbaa !9
  %21 = getelementptr inbounds %class.RunLenIntDecoder, ptr %9, i32 0, i32 7
  %22 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %21) #4
  %23 = call noundef zeroext i8 @_ZN10ByteBuffer3getEv(ptr noundef nonnull align 8 dereferenceable(62) %22)
  %24 = zext i8 %23 to i32
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = or i32 %25, %24
  store i32 %26, ptr %7, align 4, !tbaa !9
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %7, align 4, !tbaa !9
  %29 = getelementptr inbounds %class.RunLenIntDecoder, ptr %9, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = getelementptr inbounds %class.RunLenIntDecoder, ptr %9, i32 0, i32 4
  %32 = load i32, ptr %31, align 4, !tbaa !20
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = getelementptr inbounds %class.RunLenIntDecoder, ptr %9, i32 0, i32 7
  call void @_ZN16RunLenIntDecoder8readIntsEPliiiRKSt10shared_ptrI10ByteBufferE(ptr noundef nonnull align 8 dereferenceable(65) %9, ptr noundef %30, i32 noundef %32, i32 noundef %33, i32 noundef %34, ptr noundef nonnull align 8 dereferenceable(16) %35)
  %36 = getelementptr inbounds %class.RunLenIntDecoder, ptr %9, i32 0, i32 2
  %37 = load i8, ptr %36, align 8, !tbaa !21, !range !22, !noundef !23
  %38 = trunc i8 %37 to i1
  br i1 %38, label %39, label %67

39:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %63, %39
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %66

45:                                               ; preds = %40
  %46 = getelementptr inbounds %class.RunLenIntDecoder, ptr %9, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !12
  %48 = getelementptr inbounds %class.RunLenIntDecoder, ptr %9, i32 0, i32 4
  %49 = load i32, ptr %48, align 4, !tbaa !20
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i64, ptr %47, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !24
  %53 = call noundef i64 @_ZN16RunLenIntDecoder12zigzagDecodeEl(ptr noundef nonnull align 8 dereferenceable(65) %9, i64 noundef %52)
  %54 = getelementptr inbounds %class.RunLenIntDecoder, ptr %9, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !12
  %56 = getelementptr inbounds %class.RunLenIntDecoder, ptr %9, i32 0, i32 4
  %57 = load i32, ptr %56, align 4, !tbaa !20
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i64, ptr %55, i64 %58
  store i64 %53, ptr %59, align 8, !tbaa !24
  %60 = getelementptr inbounds %class.RunLenIntDecoder, ptr %9, i32 0, i32 4
  %61 = load i32, ptr %60, align 4, !tbaa !20
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %60, align 4, !tbaa !20
  br label %63

63:                                               ; preds = %45
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %8, align 4, !tbaa !9
  br label %40, !llvm.loop !26

66:                                               ; preds = %44
  br label %72

67:                                               ; preds = %2
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = getelementptr inbounds %class.RunLenIntDecoder, ptr %9, i32 0, i32 4
  %70 = load i32, ptr %69, align 4, !tbaa !20
  %71 = add nsw i32 %70, %68
  store i32 %71, ptr %69, align 4, !tbaa !20
  br label %72

72:                                               ; preds = %67, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  ret void
}

declare noundef i32 @_ZN13EncodingUtils14decodeBitWidthEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN16RunLenIntDecoder8readIntsEPliiiRKSt10shared_ptrI10ByteBufferE(ptr noundef nonnull align 8 dereferenceable(65), ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN16RunLenIntDecoder12zigzagDecodeEl(ptr noundef nonnull align 8 dereferenceable(65), i64 noundef) #1 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 = { "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 = { 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 #4 = { 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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"_ZTS16RunLenIntDecoder", !14, i64 0, !6, i64 8, !15, i64 16, !10, i64 20, !10, i64 24, !16, i64 32, !19, i64 48, !15, i64 64}
!14 = !{!"_ZTS7Decoder"}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSSt10shared_ptrI10ByteBufferE", !17, i64 0}
!17 = !{!"_ZTSSt12__shared_ptrI10ByteBufferLN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0, !18, i64 8}
!18 = !{!"_ZTSSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0}
!19 = !{!"_ZTS13EncodingUtils", !6, i64 0, !6, i64 8}
!20 = !{!13, !10, i64 20}
!21 = !{!13, !15, i64 16}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!25, !25, i64 0}
!25 = !{!"long", !7, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"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 noundef zeroext i8 @_ZN10ByteBuffer3getEv(ptr noundef nonnull align 8 dereferenceable(62)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN16RunLenIntDecoder16readDirectValuesEi(ptr noundef nonnull align 8 dereferenceable(65) %0, i32 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = lshr i32 %1, 1
  %4 = and i32 %3, 31
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = tail call noundef i32 @_ZN13EncodingUtils14decodeBitWidthEi(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef %4)
  %7 = shl i32 %1, 8
  %8 = and i32 %7, 256
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %9) #3
  %11 = tail call noundef zeroext i8 @_ZN10ByteBuffer3getEv(ptr noundef nonnull align 8 dereferenceable(62) %10)
  %12 = zext i8 %11 to i32
  %13 = or disjoint i32 %8, %12
  %14 = add nuw nsw i32 %13, 1
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 20
  %18 = load i32, ptr %17, align 4, !tbaa !17
  tail call void @_ZN16RunLenIntDecoder8readIntsEPliiiRKSt10shared_ptrI10ByteBufferE(ptr noundef nonnull align 8 dereferenceable(65) %0, ptr noundef %16, i32 noundef %18, i32 noundef %14, i32 noundef %6, ptr noundef nonnull align 8 dereferenceable(16) %9)
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load i8, ptr %19, align 8, !tbaa !18, !range !19, !noundef !20
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %.preheader.preheader, label %35

.preheader.preheader:                             ; preds = %2
  %22 = or disjoint i32 %8, %12
  %.pre = load ptr, ptr %15, align 8, !tbaa !5
  %.pre12 = load i32, ptr %17, align 4, !tbaa !17
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %23 = phi i32 [ %33, %.preheader ], [ %.pre12, %.preheader.preheader ]
  %24 = phi ptr [ %29, %.preheader ], [ %.pre, %.preheader.preheader ]
  %.011 = phi i32 [ %34, %.preheader ], [ 0, %.preheader.preheader ]
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds i64, ptr %24, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !21
  %28 = tail call noundef i64 @_ZN16RunLenIntDecoder12zigzagDecodeEl(ptr noundef nonnull align 8 dereferenceable(65) %0, i64 noundef %27)
  %29 = load ptr, ptr %15, align 8, !tbaa !5
  %30 = load i32, ptr %17, align 4, !tbaa !17
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i64, ptr %29, i64 %31
  store i64 %28, ptr %32, align 8, !tbaa !21
  %33 = add nsw i32 %30, 1
  store i32 %33, ptr %17, align 4, !tbaa !17
  %34 = add nuw nsw i32 %.011, 1
  %exitcond.not = icmp eq i32 %.011, %22
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !23

35:                                               ; preds = %2
  %36 = load i32, ptr %17, align 4, !tbaa !17
  %37 = add nsw i32 %36, %14
  store i32 %37, ptr %17, align 4, !tbaa !17
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %35
  ret void
}

declare noundef i32 @_ZN13EncodingUtils14decodeBitWidthEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN16RunLenIntDecoder8readIntsEPliiiRKSt10shared_ptrI10ByteBufferE(ptr noundef nonnull align 8 dereferenceable(65), ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN16RunLenIntDecoder12zigzagDecodeEl(ptr noundef nonnull align 8 dereferenceable(65), i64 noundef) 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 = { "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, !8, i64 8}
!6 = !{!"_ZTS16RunLenIntDecoder", !7, i64 0, !8, i64 8, !11, i64 16, !12, i64 20, !12, i64 24, !13, i64 32, !16, i64 48, !11, i64 64}
!7 = !{!"_ZTS7Decoder"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"bool", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!"_ZTSSt10shared_ptrI10ByteBufferE", !14, i64 0}
!14 = !{!"_ZTSSt12__shared_ptrI10ByteBufferLN9__gnu_cxx12_Lock_policyE2EE", !8, i64 0, !15, i64 8}
!15 = !{!"_ZTSSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EE", !8, i64 0}
!16 = !{!"_ZTS13EncodingUtils", !8, i64 0, !8, i64 8}
!17 = !{!6, !12, i64 20}
!18 = !{!6, !11, i64 16}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!22, !22, i64 0}
!22 = !{!"long", !9, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass