; 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_8u(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 = zext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  store ptr %24, 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 %25

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

29:                                               ; preds = %25
  store i32 2, ptr %16, align 4
  br label %59

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

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

41:                                               ; preds = %38
  store i32 221, ptr %12, align 4, !tbaa !9
  store i32 2, ptr %16, align 4
  br label %59

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

46:                                               ; preds = %42
  store i32 225, ptr %12, align 4, !tbaa !9
  store i32 2, ptr %16, align 4
  br label %59

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

53:                                               ; preds = %47, %30
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = add i32 %54, 1
  store i32 %55, ptr %11, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %53
  %57 = load i32, ptr %15, align 4, !tbaa !9
  %58 = add i32 %57, 1
  store i32 %58, ptr %15, align 4, !tbaa !9
  br label %25, !llvm.loop !12

59:                                               ; preds = %46, %41, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  br label %60

60:                                               ; preds = %59
  %61 = load ptr, ptr %13, align 8, !tbaa !5
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %61, ptr %62, align 8, !tbaa !5
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %63, ptr %64, align 4, !tbaa !9
  %65 = 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 %65
}

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 = distinct !{!12, !13}
!13 = !{!"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_8u(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 = zext i32 %3 to i64
  %9 = getelementptr inbounds i8, ptr %7, i64 %8
  %.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, %18
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %18 ]
  %.02025 = phi i32 [ %6, %.lr.ph.preheader ], [ %19, %18 ]
  %.02124 = phi ptr [ %7, %.lr.ph.preheader ], [ %.1, %18 ]
  %10 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %11 = load i8, ptr %10, align 1, !tbaa !11
  %.not = icmp eq i8 %11, 0
  br i1 %.not, label %18, label %12

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

14:                                               ; preds = %12
  %.not23 = icmp ult ptr %.02124, %9
  br i1 %.not23, label %15, label %._crit_edge

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

18:                                               ; preds = %15, %.lr.ph
  %.1 = phi ptr [ %17, %15 ], [ %.02124, %.lr.ph ]
  %19 = 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 !12

._crit_edge:                                      ; preds = %18, %12, %14, %5
  %.021.lcssa = phi ptr [ %7, %5 ], [ %.02124, %14 ], [ %.02124, %12 ], [ %.1, %18 ]
  %.020.lcssa = phi i32 [ %6, %5 ], [ %.02025, %14 ], [ %.02025, %12 ], [ %19, %18 ]
  %.022 = phi i32 [ 0, %5 ], [ 225, %14 ], [ 221, %12 ], [ 0, %18 ]
  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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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