; 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 @_ZN13EncodingUtils15unrolledUnPack4EPliiRKSt10shared_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 2, 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 = %56, %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 %60

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, 4
  %42 = and i32 %41, 15
  %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 = and i32 %48, 15
  %50 = sext i32 %49 to i64
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load i32, ptr %16, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i64, ptr %51, i64 %54
  store i64 %50, ptr %55, align 8, !tbaa !11
  br label %56

56:                                               ; preds = %35
  %57 = load i32, ptr %11, align 4, !tbaa !9
  %58 = load i32, ptr %16, align 4, !tbaa !9
  %59 = add nsw i32 %58, %57
  store i32 %59, ptr %16, align 4, !tbaa !9
  br label %30, !llvm.loop !13

60:                                               ; preds = %34
  %61 = load i32, ptr %12, align 4, !tbaa !9
  %62 = icmp sgt i32 %61, 0
  br i1 %62, label %63, label %90

63:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 4, ptr %17, align 4, !tbaa !9
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %64) #4
  %66 = call noundef zeroext i8 @_ZN10ByteBuffer3getEv(ptr noundef nonnull align 8 dereferenceable(62) %65)
  %67 = zext i8 %66 to i32
  store i32 %67, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %68 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %68, ptr %18, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %86, %63
  %70 = load i32, ptr %18, align 4, !tbaa !9
  %71 = load i32, ptr %13, align 4, !tbaa !9
  %72 = icmp slt i32 %70, %71
  br i1 %72, label %74, label %73

73:                                               ; preds = %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  br label %89

74:                                               ; preds = %69
  %75 = load i32, ptr %15, align 4, !tbaa !9
  %76 = load i32, ptr %17, align 4, !tbaa !9
  %77 = lshr i32 %75, %76
  %78 = and i32 %77, 15
  %79 = zext i32 %78 to i64
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load i32, ptr %18, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i64, ptr %80, i64 %82
  store i64 %79, ptr %83, align 8, !tbaa !11
  %84 = load i32, ptr %17, align 4, !tbaa !9
  %85 = sub nsw i32 %84, 4
  store i32 %85, ptr %17, align 4, !tbaa !9
  br label %86

86:                                               ; preds = %74
  %87 = load i32, ptr %18, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %18, align 4, !tbaa !9
  br label %69, !llvm.loop !15

89:                                               ; preds = %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %90

90:                                               ; preds = %89, %60
  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 @_ZN13EncodingUtils15unrolledUnPack4EPliiRKSt10shared_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, 2
  %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.ph36.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, 4
  %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 = and i32 %15, 15
  %20 = zext nneg i32 %19 to i64
  %21 = getelementptr i8, ptr %18, i64 8
  store i64 %20, ptr %21, align 8, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 2
  %22 = icmp slt i64 %indvars.iv.next, %11
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.lr.ph36.preheader:                               ; preds = %._crit_edge
  %23 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %4) #3
  %24 = tail call noundef zeroext i8 @_ZN10ByteBuffer3getEv(ptr noundef nonnull align 8 dereferenceable(62) %23)
  %25 = sext i32 %8 to i64
  %26 = lshr i8 %24, 4
  %27 = zext nneg i8 %26 to i64
  %28 = getelementptr inbounds i64, ptr %1, i64 %25
  store i64 %27, ptr %28, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph36.preheader, %._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"}


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