; LLVM IR from intel/qpl :: sources/core-sw/src/filtering (qplc_pack_be_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_be_8u32u(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  store i64 %20, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  store ptr %22, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %23 = load ptr, ptr %14, align 8, !tbaa !5
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  store ptr %26, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %61, %5
  %28 = load i32, ptr %16, align 4, !tbaa !9
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = icmp ult i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 2, ptr %17, align 4
  br label %64

32:                                               ; preds = %27
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i32, ptr %16, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = zext i8 %37 to i32
  %39 = icmp ult i32 0, %38
  br i1 %39, label %40, label %58

40:                                               ; preds = %32
  %41 = load i64, ptr %12, align 8, !tbaa !11
  %42 = icmp ult i64 4294967295, %41
  br i1 %42, label %43, label %45

43:                                               ; preds = %40
  store i32 221, ptr %13, align 4, !tbaa !9
  %44 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %44, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %64

45:                                               ; preds = %40
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = load ptr, ptr %15, align 8, !tbaa !5
  %48 = icmp uge ptr %46, %47
  br i1 %48, label %49, label %51

49:                                               ; preds = %45
  store i32 225, ptr %13, align 4, !tbaa !9
  %50 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %50, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %64

51:                                               ; preds = %45
  %52 = load i64, ptr %12, align 8, !tbaa !11
  %53 = trunc i64 %52 to i32
  %54 = call i32 @qplc_swap_bytes_32u(i32 noundef %53)
  %55 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 %54, ptr %55, align 4, !tbaa !9
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = getelementptr inbounds i32, ptr %56, i32 1
  store ptr %57, ptr %14, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %51, %32
  %59 = load i64, ptr %12, align 8, !tbaa !11
  %60 = add i64 %59, 1
  store i64 %60, ptr %12, align 8, !tbaa !11
  br label %61

61:                                               ; preds = %58
  %62 = load i32, ptr %16, align 4, !tbaa !9
  %63 = add i32 %62, 1
  store i32 %63, ptr %16, align 4, !tbaa !9
  br label %27, !llvm.loop !14

64:                                               ; preds = %49, %43, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  %65 = load i32, ptr %17, align 4
  switch i32 %65, label %73 [
    i32 2, label %66
  ]

66:                                               ; preds = %64
  %67 = load ptr, ptr %14, align 8, !tbaa !5
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %67, ptr %68, align 8, !tbaa !5
  %69 = load i64, ptr %12, align 8, !tbaa !11
  %70 = trunc i64 %69 to i32
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %70, ptr %71, align 4, !tbaa !9
  %72 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %72, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %73

73:                                               ; preds = %66, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %74 = load i32, ptr %6, align 4
  ret i32 %74
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @qplc_swap_bytes_32u(i32 noundef) #2

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 = { inlinehint 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 #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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !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: nounwind uwtable
define dso_local noundef i32 @px_qplc_pack_index_be_8u32u(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
  %.not3136.not = icmp eq i32 %1, 0
  br i1 %.not3136.not, label %._crit_edge, label %.lr.ph.preheader

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

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %20 ]
  %.02638 = phi ptr [ %7, %.lr.ph.preheader ], [ %.127, %20 ]
  %.02937 = phi i64 [ %10, %.lr.ph.preheader ], [ %21, %20 ]
  %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 %20, label %13

13:                                               ; preds = %.lr.ph
  %14 = icmp ugt i64 %.02937, 4294967295
  br i1 %14, label %.thread, label %15

15:                                               ; preds = %13
  %.not30 = icmp ult ptr %.02638, %9
  br i1 %.not30, label %16, label %.thread

16:                                               ; preds = %15
  %17 = trunc nuw i64 %.02937 to i32
  %18 = tail call i32 @qplc_swap_bytes_32u(i32 noundef %17)
  store i32 %18, ptr %.02638, align 4, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.02638, i64 4
  br label %20

20:                                               ; preds = %16, %.lr.ph
  %.127 = phi ptr [ %19, %16 ], [ %.02638, %.lr.ph ]
  %21 = add nuw nsw i64 %.02937, 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.loopexit, label %.lr.ph, !llvm.loop !12

._crit_edge.loopexit:                             ; preds = %20
  %22 = trunc i64 %21 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %5
  %.029.lcssa = phi i32 [ %6, %5 ], [ %22, %._crit_edge.loopexit ]
  %.026.lcssa = phi ptr [ %7, %5 ], [ %.127, %._crit_edge.loopexit ]
  store ptr %.026.lcssa, ptr %2, align 8, !tbaa !9
  store i32 %.029.lcssa, ptr %4, align 4, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %13, %15, %._crit_edge
  %.1 = phi i32 [ 0, %._crit_edge ], [ 221, %13 ], [ 225, %15 ]
  ret i32 %.1
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @qplc_swap_bytes_32u(i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 = { inlinehint 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" }

!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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass