; 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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13EncodingUtils16unrolledBitPack1EPliiSt10shared_ptrI10ByteBufferE(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) #2 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 8, 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 = %111, %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 %115

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, 1
  %44 = shl i64 %43, 7
  %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, 1
  %53 = shl i64 %52, 6
  %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, 1
  %62 = shl i64 %61, 5
  %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, 1
  %71 = shl i64 %70, 4
  %72 = or i64 %63, %71
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = load i32, ptr %16, align 4, !tbaa !9
  %75 = add nsw i32 %74, 4
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i64, ptr %73, i64 %76
  %78 = load i64, ptr %77, align 8, !tbaa !12
  %79 = and i64 %78, 1
  %80 = shl i64 %79, 3
  %81 = or i64 %72, %80
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = load i32, ptr %16, align 4, !tbaa !9
  %84 = add nsw i32 %83, 5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds i64, ptr %82, i64 %85
  %87 = load i64, ptr %86, align 8, !tbaa !12
  %88 = and i64 %87, 1
  %89 = shl i64 %88, 2
  %90 = or i64 %81, %89
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = load i32, ptr %16, align 4, !tbaa !9
  %93 = add nsw i32 %92, 6
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds i64, ptr %91, i64 %94
  %96 = load i64, ptr %95, align 8, !tbaa !12
  %97 = and i64 %96, 1
  %98 = shl i64 %97, 1
  %99 = or i64 %90, %98
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = load i32, ptr %16, align 4, !tbaa !9
  %102 = add nsw i32 %101, 7
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds i64, ptr %100, i64 %103
  %105 = load i64, ptr %104, align 8, !tbaa !12
  %106 = and i64 %105, 1
  %107 = or i64 %99, %106
  %108 = trunc i64 %107 to i8
  store i8 %108, ptr %15, align 1, !tbaa !11
  %109 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %4) #4
  %110 = load i8, ptr %15, align 1, !tbaa !11
  call void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62) %109, i8 noundef zeroext %110)
  store i8 0, ptr %15, align 1, !tbaa !11
  br label %111

111:                                              ; preds = %35
  %112 = load i32, ptr %11, align 4, !tbaa !9
  %113 = load i32, ptr %16, align 4, !tbaa !9
  %114 = add nsw i32 %113, %112
  store i32 %114, ptr %16, align 4, !tbaa !9
  br label %30, !llvm.loop !14

115:                                              ; preds = %34
  %116 = load i32, ptr %12, align 4, !tbaa !9
  %117 = icmp sgt i32 %116, 0
  br i1 %117, label %118, label %147

118:                                              ; preds = %115
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 7, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %119 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %119, ptr %18, align 4, !tbaa !9
  br label %120

120:                                              ; preds = %141, %118
  %121 = load i32, ptr %18, align 4, !tbaa !9
  %122 = load i32, ptr %13, align 4, !tbaa !9
  %123 = icmp slt i32 %121, %122
  br i1 %123, label %125, label %124

124:                                              ; preds = %120
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  br label %144

125:                                              ; preds = %120
  %126 = load i8, ptr %15, align 1, !tbaa !11
  %127 = zext i8 %126 to i64
  %128 = load ptr, ptr %7, align 8, !tbaa !5
  %129 = load i32, ptr %18, align 4, !tbaa !9
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds i64, ptr %128, i64 %130
  %132 = load i64, ptr %131, align 8, !tbaa !12
  %133 = and i64 %132, 1
  %134 = load i32, ptr %17, align 4, !tbaa !9
  %135 = zext i32 %134 to i64
  %136 = shl i64 %133, %135
  %137 = or i64 %127, %136
  %138 = trunc i64 %137 to i8
  store i8 %138, ptr %15, align 1, !tbaa !11
  %139 = load i32, ptr %17, align 4, !tbaa !9
  %140 = add nsw i32 %139, -1
  store i32 %140, ptr %17, align 4, !tbaa !9
  br label %141

141:                                              ; preds = %125
  %142 = load i32, ptr %18, align 4, !tbaa !9
  %143 = add nsw i32 %142, 1
  store i32 %143, ptr %18, align 4, !tbaa !9
  br label %120, !llvm.loop !16

144:                                              ; preds = %124
  %145 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %4) #4
  %146 = load i8, ptr %15, align 1, !tbaa !11
  call void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62) %145, i8 noundef zeroext %146)
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %147

147:                                              ; preds = %144, %115
  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
}

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

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 = { "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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13EncodingUtils16unrolledBitPack1EPliiSt10shared_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 #1 align 2 {
  %6 = srem i32 %3, 8
  %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.ph48.preheader, label %66

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

.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, 7
  %18 = and i64 %17, 128
  %19 = getelementptr i8, ptr %15, i64 8
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = shl i64 %20, 6
  %22 = and i64 %21, 64
  %23 = or disjoint i64 %22, %18
  %24 = getelementptr i8, ptr %15, i64 16
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = shl i64 %25, 5
  %27 = and i64 %26, 32
  %28 = or disjoint i64 %23, %27
  %29 = getelementptr i8, ptr %15, i64 24
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = shl i64 %30, 4
  %32 = and i64 %31, 16
  %33 = or disjoint i64 %28, %32
  %34 = getelementptr i8, ptr %15, i64 32
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = shl i64 %35, 3
  %37 = and i64 %36, 8
  %38 = or disjoint i64 %33, %37
  %39 = getelementptr i8, ptr %15, i64 40
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = shl i64 %40, 2
  %42 = and i64 %41, 4
  %43 = or disjoint i64 %38, %42
  %44 = getelementptr i8, ptr %15, i64 48
  %45 = load i64, ptr %44, align 8, !tbaa !5
  %46 = shl i64 %45, 1
  %47 = and i64 %46, 2
  %48 = or i64 %43, %47
  %49 = getelementptr i8, ptr %15, i64 56
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = and i64 %50, 1
  %52 = or i64 %48, %51
  %53 = trunc nuw i64 %52 to i8
  %54 = 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) %54, i8 noundef zeroext %53)
  %indvars.iv.next = add nsw i64 %indvars.iv, 8
  %55 = icmp slt i64 %indvars.iv.next, %11
  br i1 %55, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge49:                                    ; preds = %.lr.ph48
  %56 = 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) %56, i8 noundef zeroext %63)
  br label %66

.lr.ph48:                                         ; preds = %.lr.ph48.preheader, %.lr.ph48
  %indvars.iv51 = phi i64 [ %13, %.lr.ph48.preheader ], [ %indvars.iv.next52, %.lr.ph48 ]
  %.04046 = phi i32 [ 7, %.lr.ph48.preheader ], [ %64, %.lr.ph48 ]
  %.145 = phi i8 [ 0, %.lr.ph48.preheader ], [ %63, %.lr.ph48 ]
  %57 = getelementptr inbounds i64, ptr %1, i64 %indvars.iv51
  %58 = load i64, ptr %57, align 8, !tbaa !5
  %59 = and i64 %58, 1
  %60 = zext nneg i32 %.04046 to i64
  %61 = shl nuw i64 %59, %60
  %62 = trunc i64 %61 to i8
  %63 = or i8 %.145, %62
  %64 = add nsw i32 %.04046, -1
  %indvars.iv.next52 = add nsw i64 %indvars.iv51, 1
  %65 = icmp slt i64 %indvars.iv.next52, %14
  br i1 %65, label %.lr.ph48, label %._crit_edge49, !llvm.loop !11

66:                                               ; preds = %._crit_edge49, %._crit_edge
  ret void
}

declare void @_ZN10ByteBuffer3putEh(ptr noundef nonnull align 8 dereferenceable(62), i8 noundef zeroext) local_unnamed_addr #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" }
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 = { 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