; LLVM IR from pixelsdb/mini-pixels :: pixels-core/lib/utils (EncodingUtils)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13EncodingUtils16unrolledBitPack2EPliiSt10shared_ptrI10ByteBufferE(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) #3 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i8, align 1
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = load i32, ptr %11, align 4, !tbaa !9
  %22 = srem i32 %20, %21
  store i32 %22, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = add nsw i32 %23, %24
  store i32 %25, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %26 = load i32, ptr %13, align 4, !tbaa !9
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = sub nsw i32 %26, %27
  store i32 %28, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #4
  store i8 0, ptr %15, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %29 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %29, ptr %16, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %75, %5
  %31 = load i32, ptr %16, align 4, !tbaa !9
  %32 = load i32, ptr %14, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %79

35:                                               ; preds = %30
  %36 = load i8, ptr %15, align 1, !tbaa !11
  %37 = zext i8 %36 to i64
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load i32, ptr %16, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i64, ptr %38, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !12
  %43 = and i64 %42, 3
  %44 = shl i64 %43, 6
  %45 = or i64 %37, %44
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i32, ptr %16, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i64, ptr %46, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !12
  %52 = and i64 %51, 3
  %53 = shl i64 %52, 4
  %54 = or i64 %45, %53
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load i32, ptr %16, align 4, !tbaa !9
  %57 = add nsw i32 %56, 2
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i64, ptr %55, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !12
  %61 = and i64 %60, 3
  %62 = shl i64 %61, 2
  %63 = or i64 %54, %62
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = load i32, ptr %16, align 4, !tbaa !9
  %66 = add nsw i32 %65, 3
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i64, ptr %64, i64 %67
  %69 = load i64, ptr %68, align 8, !tbaa !12
  %70 = and i64 %69, 3
  %71 = or i64 %63, %70
  %72 = trunc i64 %71 to i8
  store i8 %72, ptr %15, align 1, !tbaa !11
  %73 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %4) #4
  %74 = load i8, ptr %15, align 1, !tbaa !11
  call void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62) %73, i8 noundef zeroext %74)
  store i8 0, ptr %15, align 1, !tbaa !11
  br label %75

75:                                               ; preds = %35
  %76 = load i32, ptr %11, align 4, !tbaa !9
  %77 = load i32, ptr %16, align 4, !tbaa !9
  %78 = add nsw i32 %77, %76
  store i32 %78, ptr %16, align 4, !tbaa !9
  br label %30, !llvm.loop !14

79:                                               ; preds = %34
  %80 = load i32, ptr %12, align 4, !tbaa !9
  %81 = icmp sgt i32 %80, 0
  br i1 %81, label %82, label %112

82:                                               ; preds = %79
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 6, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %83 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %83, ptr %18, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %106, %82
  %85 = load i32, ptr %18, align 4, !tbaa !9
  %86 = load i32, ptr %13, align 4, !tbaa !9
  %87 = icmp slt i32 %85, %86
  br i1 %87, label %89, label %88

88:                                               ; preds = %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  br label %109

89:                                               ; preds = %84
  %90 = load i8, ptr %15, align 1, !tbaa !11
  %91 = zext i8 %90 to i64
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = load i32, ptr %18, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds i64, ptr %92, i64 %94
  %96 = load i64, ptr %95, align 8, !tbaa !12
  %97 = and i64 %96, 3
  %98 = load i32, ptr %17, align 4, !tbaa !9
  %99 = zext i32 %98 to i64
  %100 = shl i64 %97, %99
  %101 = or i64 %91, %100
  %102 = trunc i64 %101 to i32
  %103 = trunc i32 %102 to i8
  store i8 %103, ptr %15, align 1, !tbaa !11
  %104 = load i32, ptr %17, align 4, !tbaa !9
  %105 = sub nsw i32 %104, 2
  store i32 %105, ptr %17, align 4, !tbaa !9
  br label %106

106:                                              ; preds = %89
  %107 = load i32, ptr %18, align 4, !tbaa !9
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %18, align 4, !tbaa !9
  br label %84, !llvm.loop !16

109:                                              ; preds = %88
  %110 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %4) #4
  %111 = load i8, ptr %15, align 1, !tbaa !11
  call void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62) %110, i8 noundef zeroext %111)
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %112

112:                                              ; preds = %109, %79
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  ret void
}

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, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 @_ZN13EncodingUtils16unrolledBitPack2EPliiSt10shared_ptrI10ByteBufferE(ptr nocapture noundef nonnull readnone align 8 dereferenceable(16) %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #2 align 2 {
  %6 = srem i32 %3, 4
  %7 = add nsw i32 %3, %2
  %8 = sub nsw i32 %7, %6
  %9 = icmp sgt i32 %8, %2
  br i1 %9, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %10 = sext i32 %2 to i64
  %11 = sext i32 %8 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %5
  %12 = icmp sgt i32 %6, 0
  br i1 %12, label %.lr.ph40.preheader, label %45

.lr.ph40.preheader:                               ; preds = %._crit_edge
  %13 = sext i32 %8 to i64
  %14 = sext i32 %7 to i64
  br label %.lr.ph40

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %10, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %15 = getelementptr inbounds i64, ptr %1, i64 %indvars.iv
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = shl i64 %16, 6
  %18 = getelementptr i8, ptr %15, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = shl i64 %19, 4
  %21 = and i64 %20, 48
  %22 = or disjoint i64 %21, %17
  %23 = getelementptr i8, ptr %15, i64 16
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = shl i64 %24, 2
  %26 = and i64 %25, 12
  %27 = or disjoint i64 %22, %26
  %28 = getelementptr i8, ptr %15, i64 24
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = and i64 %29, 3
  %31 = or disjoint i64 %27, %30
  %32 = trunc i64 %31 to i8
  %33 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %4) #3
  tail call void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62) %33, i8 noundef zeroext %32)
  %indvars.iv.next = add nsw i64 %indvars.iv, 4
  %34 = icmp slt i64 %indvars.iv.next, %11
  br i1 %34, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge41:                                    ; preds = %.lr.ph40
  %35 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %4) #3
  tail call void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62) %35, i8 noundef zeroext %42)
  br label %45

.lr.ph40:                                         ; preds = %.lr.ph40.preheader, %.lr.ph40
  %indvars.iv43 = phi i64 [ %13, %.lr.ph40.preheader ], [ %indvars.iv.next44, %.lr.ph40 ]
  %.03238 = phi i32 [ 6, %.lr.ph40.preheader ], [ %43, %.lr.ph40 ]
  %.137 = phi i8 [ 0, %.lr.ph40.preheader ], [ %42, %.lr.ph40 ]
  %36 = getelementptr inbounds i64, ptr %1, i64 %indvars.iv43
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = and i64 %37, 3
  %39 = zext nneg i32 %.03238 to i64
  %40 = shl i64 %38, %39
  %41 = trunc i64 %40 to i8
  %42 = or i8 %.137, %41
  %43 = add nsw i32 %.03238, -2
  %indvars.iv.next44 = add nsw i64 %indvars.iv43, 1
  %44 = icmp slt i64 %indvars.iv.next44, %14
  br i1 %44, label %.lr.ph40, label %._crit_edge41, !llvm.loop !11

45:                                               ; preds = %._crit_edge41, %._crit_edge
  ret void
}

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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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