; 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

declare noundef zeroext i8 @_ZN10ByteBuffer3getEv(ptr noundef nonnull align 8 dereferenceable(62)) #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 @_ZN13EncodingUtils15unrolledUnPack2EPliiRKSt10shared_ptrI10ByteBufferE(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 8 dereferenceable(16) %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 i32, align 4
  %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 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !9
  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 = %74, %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 %78

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

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

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

81:                                               ; preds = %78
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 6, ptr %17, align 4, !tbaa !9
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %82) #4
  %84 = call noundef zeroext i8 @_ZN10ByteBuffer3getEv(ptr noundef nonnull align 8 dereferenceable(62) %83)
  %85 = zext i8 %84 to i32
  store i32 %85, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %86 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %86, ptr %18, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %104, %81
  %88 = load i32, ptr %18, align 4, !tbaa !9
  %89 = load i32, ptr %13, align 4, !tbaa !9
  %90 = icmp slt i32 %88, %89
  br i1 %90, label %92, label %91

91:                                               ; preds = %87
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  br label %107

92:                                               ; preds = %87
  %93 = load i32, ptr %15, align 4, !tbaa !9
  %94 = load i32, ptr %17, align 4, !tbaa !9
  %95 = lshr i32 %93, %94
  %96 = and i32 %95, 3
  %97 = zext i32 %96 to i64
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = load i32, ptr %18, align 4, !tbaa !9
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds i64, ptr %98, i64 %100
  store i64 %97, ptr %101, align 8, !tbaa !11
  %102 = load i32, ptr %17, align 4, !tbaa !9
  %103 = sub nsw i32 %102, 2
  store i32 %103, ptr %17, align 4, !tbaa !9
  br label %104

104:                                              ; preds = %92
  %105 = load i32, ptr %18, align 4, !tbaa !9
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %18, align 4, !tbaa !9
  br label %87, !llvm.loop !15

107:                                              ; preds = %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %108

108:                                              ; preds = %107, %78
  call void @llvm.lifetime.end.p0(i64 4, 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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 @_ZN13EncodingUtils15unrolledUnPack2EPliiRKSt10shared_ptrI10ByteBufferE(ptr nocapture noundef nonnull readnone align 8 dereferenceable(16) %0, ptr nocapture noundef writeonly %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 8 dereferenceable(16) %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.ph42.preheader, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %10, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %13 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %4) #3
  %14 = tail call noundef zeroext i8 @_ZN10ByteBuffer3getEv(ptr noundef nonnull align 8 dereferenceable(62) %13)
  %15 = zext i8 %14 to i32
  %16 = lshr i32 %15, 6
  %17 = zext nneg i32 %16 to i64
  %18 = getelementptr inbounds i64, ptr %1, i64 %indvars.iv
  store i64 %17, ptr %18, align 8, !tbaa !5
  %19 = lshr i32 %15, 4
  %20 = and i32 %19, 3
  %21 = zext nneg i32 %20 to i64
  %22 = getelementptr i8, ptr %18, i64 8
  store i64 %21, ptr %22, align 8, !tbaa !5
  %23 = lshr i32 %15, 2
  %24 = and i32 %23, 3
  %25 = zext nneg i32 %24 to i64
  %26 = getelementptr i8, ptr %18, i64 16
  store i64 %25, ptr %26, align 8, !tbaa !5
  %27 = and i32 %15, 3
  %28 = zext nneg i32 %27 to i64
  %29 = getelementptr i8, ptr %18, i64 24
  store i64 %28, ptr %29, align 8, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 4
  %30 = icmp slt i64 %indvars.iv.next, %11
  br i1 %30, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.lr.ph42.preheader:                               ; preds = %._crit_edge
  %31 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %4) #3
  %32 = tail call noundef zeroext i8 @_ZN10ByteBuffer3getEv(ptr noundef nonnull align 8 dereferenceable(62) %31)
  %33 = zext i8 %32 to i32
  %34 = sext i32 %8 to i64
  %35 = sext i32 %7 to i64
  br label %.lr.ph42

.lr.ph42:                                         ; preds = %.lr.ph42.preheader, %.lr.ph42
  %indvars.iv44 = phi i64 [ %34, %.lr.ph42.preheader ], [ %indvars.iv.next45, %.lr.ph42 ]
  %.03539 = phi i32 [ 6, %.lr.ph42.preheader ], [ %40, %.lr.ph42 ]
  %36 = lshr i32 %33, %.03539
  %37 = and i32 %36, 3
  %38 = zext nneg i32 %37 to i64
  %39 = getelementptr inbounds i64, ptr %1, i64 %indvars.iv44
  store i64 %38, ptr %39, align 8, !tbaa !5
  %40 = add nsw i32 %.03539, -2
  %indvars.iv.next45 = add nsw i64 %indvars.iv44, 1
  %41 = icmp slt i64 %indvars.iv.next45, %35
  br i1 %41, label %.lr.ph42, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph42, %._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,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass