; LLVM IR from intel/qpl :: sources/core-sw/src/filtering (qplc_pack_idx)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @px_qplc_pack_index_8u16u(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %18, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %20, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %21 = load ptr, ptr %13, align 8, !tbaa !5
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = lshr i32 %22, 1
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds i16, ptr %21, i64 %24
  store ptr %25, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %57, %5
  %27 = load i32, ptr %15, align 4, !tbaa !9
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = icmp ult i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 2, ptr %16, align 4
  br label %60

31:                                               ; preds = %26
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %15, align 4, !tbaa !9
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %32, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = zext i8 %36 to i32
  %38 = icmp ult i32 0, %37
  br i1 %38, label %39, label %54

39:                                               ; preds = %31
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = icmp ult i32 65535, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  store i32 221, ptr %12, align 4, !tbaa !9
  store i32 2, ptr %16, align 4
  br label %60

43:                                               ; preds = %39
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = load ptr, ptr %14, align 8, !tbaa !5
  %46 = icmp uge ptr %44, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %43
  store i32 225, ptr %12, align 4, !tbaa !9
  store i32 2, ptr %16, align 4
  br label %60

48:                                               ; preds = %43
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = trunc i32 %49 to i16
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  store i16 %50, ptr %51, align 2, !tbaa !12
  %52 = load ptr, ptr %13, align 8, !tbaa !5
  %53 = getelementptr inbounds i16, ptr %52, i32 1
  store ptr %53, ptr %13, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %48, %31
  %55 = load i32, ptr %11, align 4, !tbaa !9
  %56 = add i32 %55, 1
  store i32 %56, ptr %11, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %54
  %58 = load i32, ptr %15, align 4, !tbaa !9
  %59 = add i32 %58, 1
  store i32 %59, ptr %15, align 4, !tbaa !9
  br label %26, !llvm.loop !14

60:                                               ; preds = %47, %42, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %62, ptr %63, align 8, !tbaa !5
  %64 = load i32, ptr %11, align 4, !tbaa !9
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %64, ptr %65, align 4, !tbaa !9
  %66 = load i32, ptr %12, align 4, !tbaa !9
  store i32 1, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret i32 %66
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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: nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 226) i32 @px_qplc_pack_index_8u16u(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef %2, i32 noundef %3, ptr nocapture noundef %4) local_unnamed_addr #0 {
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !9
  %8 = lshr i32 %3, 1
  %9 = zext nneg i32 %8 to i64
  %10 = getelementptr inbounds i16, ptr %7, i64 %9
  %.not37 = icmp eq i32 %1, 0
  br i1 %.not37, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %wide.trip.count = zext i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %19 ]
  %.02025 = phi i32 [ %6, %.lr.ph.preheader ], [ %20, %19 ]
  %.02124 = phi ptr [ %7, %.lr.ph.preheader ], [ %.1, %19 ]
  %11 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %12 = load i8, ptr %11, align 1, !tbaa !11
  %.not = icmp eq i8 %12, 0
  br i1 %.not, label %19, label %13

13:                                               ; preds = %.lr.ph
  %14 = icmp ugt i32 %.02025, 65535
  br i1 %14, label %._crit_edge, label %15

15:                                               ; preds = %13
  %.not23 = icmp ult ptr %.02124, %10
  br i1 %.not23, label %16, label %._crit_edge

16:                                               ; preds = %15
  %17 = trunc nuw i32 %.02025 to i16
  store i16 %17, ptr %.02124, align 2, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %.02124, i64 2
  br label %19

19:                                               ; preds = %16, %.lr.ph
  %.1 = phi ptr [ %18, %16 ], [ %.02124, %.lr.ph ]
  %20 = add i32 %.02025, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %19, %13, %15, %5
  %.021.lcssa = phi ptr [ %7, %5 ], [ %.02124, %15 ], [ %.02124, %13 ], [ %.1, %19 ]
  %.020.lcssa = phi i32 [ %6, %5 ], [ %.02025, %15 ], [ %.02025, %13 ], [ %20, %19 ]
  %.022 = phi i32 [ 0, %5 ], [ 225, %15 ], [ 221, %13 ], [ 0, %19 ]
  store ptr %.021.lcssa, ptr %2, align 8, !tbaa !9
  store i32 %.020.lcssa, ptr %4, align 4, !tbaa !5
  ret i32 %.022
}

attributes #0 = { nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass