; LLVM IR from intel/qpl :: sources/core-iaa/sources/aecs (hw_aecs_decompress)

; 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"

%struct.hw_iaa_aecs_decompress = type { [2 x i32], i32, i32, [32 x i64], [32 x i8], i32, i8, i8, i16, [5 x i32], [5 x i32], [5 x i32], [5 x i32], [62 x i32], %union.anon, i16, i16, %union.anon.0, %struct.anon.2, i16, [4096 x i8], [6 x i32] }
%union.anon = type { %struct.anon }
%struct.anon = type { [6 x i32], [224 x i8], [5 x i32] }
%union.anon.0 = type { %struct.anon.1 }
%struct.anon.1 = type { [2 x i32], [144 x i8], [5 x i32] }
%struct.anon.2 = type { i16 }

declare void @call_c_set_zeros_uint8_t(ptr noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local void @hw_iaa_aecs_decompress_set_dictionary(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i32 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !11
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.hw_iaa_aecs_decompress, ptr %12, i32 0, i32 20
  %14 = getelementptr inbounds [4096 x i8], ptr %13, i64 0, i64 0
  %15 = load i32, ptr %10, align 4, !tbaa !11
  call void @call_c_set_zeros_uint8_t(ptr noundef %14, i32 noundef %15)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %35, %5
  %17 = load i32, ptr %11, align 4, !tbaa !11
  %18 = zext i32 %17 to i64
  %19 = load i64, ptr %8, align 8, !tbaa !9
  %20 = icmp ult i64 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %38

22:                                               ; preds = %16
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load i32, ptr %11, align 4, !tbaa !11
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !13
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.hw_iaa_aecs_decompress, ptr %28, i32 0, i32 20
  %30 = load i32, ptr %10, align 4, !tbaa !11
  %31 = load i32, ptr %11, align 4, !tbaa !11
  %32 = add i32 %30, %31
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [4096 x i8], ptr %29, i64 0, i64 %33
  store i8 %27, ptr %34, align 1, !tbaa !13
  br label %35

35:                                               ; preds = %22
  %36 = load i32, ptr %11, align 4, !tbaa !11
  %37 = add i32 %36, 1
  store i32 %37, ptr %11, align 4, !tbaa !11
  br label %16, !llvm.loop !14

38:                                               ; preds = %21
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = trunc i64 %39 to i16
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.hw_iaa_aecs_decompress, ptr %41, i32 0, i32 18
  %43 = load i16, ptr %42, align 4
  %44 = and i16 %40, 32767
  %45 = and i16 %43, -32768
  %46 = or i16 %45, %44
  store i16 %46, ptr %42, align 4
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = icmp uge i64 %47, 4096
  br i1 %48, label %49, label %55

49:                                               ; preds = %38
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.hw_iaa_aecs_decompress, ptr %50, i32 0, i32 18
  %52 = load i16, ptr %51, align 4
  %53 = and i16 %52, 32767
  %54 = or i16 %53, -32768
  store i16 %54, ptr %51, align 4
  br label %55

55:                                               ; preds = %49, %38
  ret void
}

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

declare void @call_c_set_zeros_uint8_t(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @hw_iaa_aecs_decompress_set_dictionary(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2, i64 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = ptrtoint ptr %1 to i64
  %7 = ptrtoint ptr %0 to i64
  %8 = getelementptr inbounds i8, ptr %0, i64 1088
  tail call void @call_c_set_zeros_uint8_t(ptr noundef nonnull %8, i32 noundef %4) #2
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge, label %iter.check

iter.check:                                       ; preds = %5
  %min.iters.check = icmp ult i64 %2, 8
  br i1 %min.iters.check, label %.lr.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %iter.check
  %9 = add i64 %2, -1
  %10 = and i64 %9, 4294967295
  %11 = icmp eq i64 %10, 4294967295
  %12 = trunc i64 %9 to i32
  %13 = xor i32 %4, -1
  %14 = icmp ult i32 %13, %12
  %15 = icmp ugt i64 %9, 4294967295
  %16 = or i1 %14, %15
  %17 = or i1 %11, %16
  br i1 %17, label %.lr.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %vector.scevcheck
  %18 = zext i32 %4 to i64
  %19 = add i64 %7, %18
  %20 = add i64 %19, 1088
  %21 = sub i64 %20, %6
  %diff.check = icmp ult i64 %21, 32
  br i1 %diff.check, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %vector.memcheck
  %min.iters.check15 = icmp ult i64 %2, 32
  br i1 %min.iters.check15, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %2, 8589934560
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = trunc i64 %index to i32
  %22 = getelementptr inbounds i8, ptr %1, i64 %index
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %wide.load = load <16 x i8>, ptr %22, align 1, !tbaa !5
  %wide.load16 = load <16 x i8>, ptr %23, align 1, !tbaa !5
  %24 = add i32 %offset.idx, %4
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [4096 x i8], ptr %8, i64 0, i64 %25
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  store <16 x i8> %wide.load, ptr %26, align 1, !tbaa !5
  store <16 x i8> %wide.load16, ptr %27, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %28 = icmp eq i64 %index.next, %n.vec
  br i1 %28, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %2
  br i1 %cmp.n, label %._crit_edge, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end19 = trunc i64 %n.vec to i32
  %n.vec.remaining = and i64 %2, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %vector.memcheck, %vector.scevcheck, %iter.check, %vec.epilog.iter.check
  %.ph = phi i64 [ 0, %iter.check ], [ 0, %vector.memcheck ], [ 0, %vector.scevcheck ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec18, %vec.epilog.middle.block ]
  %.014.ph = phi i32 [ 0, %iter.check ], [ 0, %vector.memcheck ], [ 0, %vector.scevcheck ], [ %ind.end19, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  br label %.lr.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec18 = and i64 %2, 8589934584
  %ind.end = trunc i64 %n.vec18 to i32
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index21 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next24, %vec.epilog.vector.body ]
  %offset.idx22 = trunc i64 %index21 to i32
  %29 = getelementptr inbounds i8, ptr %1, i64 %index21
  %wide.load23 = load <8 x i8>, ptr %29, align 1, !tbaa !5
  %30 = add i32 %offset.idx22, %4
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds [4096 x i8], ptr %8, i64 0, i64 %31
  store <8 x i8> %wide.load23, ptr %32, align 1, !tbaa !5
  %index.next24 = add nuw i64 %index21, 8
  %33 = icmp eq i64 %index.next24, %n.vec18
  br i1 %33, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !12

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n25 = icmp eq i64 %n.vec18, %2
  br i1 %cmp.n25, label %._crit_edge, label %.lr.ph.preheader

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %vec.epilog.middle.block, %5
  %34 = trunc i64 %3 to i16
  %35 = getelementptr inbounds i8, ptr %0, i64 1084
  %36 = load i16, ptr %35, align 4
  %37 = and i16 %34, 32767
  %38 = and i16 %36, -32768
  %39 = or disjoint i16 %38, %37
  %40 = icmp ugt i64 %3, 4095
  %41 = or i16 %34, -32768
  %spec.select = select i1 %40, i16 %41, i16 %39
  store i16 %spec.select, ptr %35, align 4
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %42 = phi i64 [ %49, %.lr.ph ], [ %.ph, %.lr.ph.preheader ]
  %.014 = phi i32 [ %48, %.lr.ph ], [ %.014.ph, %.lr.ph.preheader ]
  %43 = getelementptr inbounds i8, ptr %1, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !5
  %45 = add i32 %.014, %4
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds [4096 x i8], ptr %8, i64 0, i64 %46
  store i8 %44, ptr %47, align 1, !tbaa !5
  %48 = add i32 %.014, 1
  %49 = zext i32 %48 to i64
  %50 = icmp ult i64 %49, %2
  br i1 %50, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

attributes #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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9, !10, !11}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !9, !10, !11}
!13 = distinct !{!13, !9, !10}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass