; LLVM IR from intel/qpl :: sources/core-iaa/sources/descriptors (hw_decompress_descriptor)

; 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_decompress_analytics_descriptor = type { i32, i32, ptr, ptr, ptr, i32, i16, i16, ptr, i32, i32, i32, i32 }
%struct.hw_iaa_aecs_analytic = type { %struct.hw_iaa_aecs_filter, [36 x i32], %struct.hw_iaa_aecs_decompress }
%struct.hw_iaa_aecs_filter = type { i32, i32, i32, i32, i32, i32 }
%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 }

; 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 void @hw_iaa_descriptor_init_inflate_header(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %13, ptr %9, align 8, !tbaa !5
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.hw_decompress_analytics_descriptor, ptr %14, i32 0, i32 0
  store i32 0, ptr %15, align 1, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %16 = load i32, ptr %8, align 4, !tbaa !10
  %17 = and i32 %16, 16
  %18 = icmp ne i32 %17, 0
  %19 = zext i1 %18 to i64
  %20 = select i1 %18, i32 65536, i32 0
  store i32 %20, ptr %10, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %21 = load i32, ptr %8, align 4, !tbaa !10
  %22 = and i32 %21, 1
  %23 = icmp ne i32 %22, 0
  %24 = zext i1 %23 to i64
  %25 = select i1 %23, i32 4194304, i32 0
  store i32 %25, ptr %11, align 4, !tbaa !10
  %26 = load i32, ptr %10, align 4, !tbaa !10
  %27 = or i32 1107558400, %26
  %28 = load i32, ptr %11, align 4, !tbaa !10
  %29 = or i32 %27, %28
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.hw_decompress_analytics_descriptor, ptr %30, i32 0, i32 1
  store i32 %29, ptr %31, align 1, !tbaa !15
  %32 = load i8, ptr %7, align 1, !tbaa !9
  %33 = zext i8 %32 to i32
  %34 = and i32 7, %33
  %35 = and i32 %34, 7
  %36 = shl i32 %35, 6
  %37 = or i32 513, %36
  %38 = trunc i32 %37 to i16
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.hw_decompress_analytics_descriptor, ptr %39, i32 0, i32 7
  store i16 %38, ptr %40, align 1, !tbaa !16
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.hw_decompress_analytics_descriptor, ptr %42, i32 0, i32 8
  store ptr %41, ptr %43, align 1, !tbaa !17
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.hw_decompress_analytics_descriptor, ptr %44, i32 0, i32 10
  store i32 1248, ptr %45, align 1, !tbaa !18
  %46 = load i32, ptr %8, align 4, !tbaa !10
  %47 = and i32 %46, 16
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %64

49:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.hw_decompress_analytics_descriptor, ptr %50, i32 0, i32 8
  %52 = load ptr, ptr %51, align 1, !tbaa !17
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.hw_decompress_analytics_descriptor, ptr %53, i32 0, i32 10
  %55 = load i32, ptr %54, align 1, !tbaa !18
  %56 = load i32, ptr %8, align 4, !tbaa !10
  %57 = and i32 %56, 1
  %58 = mul i32 %55, %57
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %52, i64 %59
  store ptr %60, ptr %12, align 8, !tbaa !5
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.hw_iaa_aecs_analytic, ptr %61, i32 0, i32 2
  %63 = getelementptr inbounds %struct.hw_iaa_aecs_decompress, ptr %62, i32 0, i32 15
  store i16 1, ptr %63, align 4, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %64

64:                                               ; preds = %49, %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret void
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !14, i64 36, !14, i64 38, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !11, i64 4}
!16 = !{!13, !14, i64 38}
!17 = !{!13, !6, i64 40}
!18 = !{!13, !11, i64 52}
!19 = !{!20, !14, i64 1076}
!20 = !{!"", !21, i64 0, !7, i64 24, !22, i64 168}
!21 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!22 = !{!"", !7, i64 0, !11, i64 8, !11, i64 12, !7, i64 16, !7, i64 272, !11, i64 304, !7, i64 308, !7, i64 309, !14, i64 310, !7, i64 312, !7, i64 332, !7, i64 352, !7, i64 372, !7, i64 392, !7, i64 640, !14, i64 908, !14, i64 910, !7, i64 912, !23, i64 1084, !14, i64 1086, !7, i64 1088, !7, i64 5184}
!23 = !{!"", !14, i64 0, !14, i64 1}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @hw_iaa_descriptor_init_inflate_header(ptr nocapture noundef writeonly %0, ptr noundef %1, i8 noundef zeroext %2, i32 noundef %3) local_unnamed_addr #0 {
  store i32 0, ptr %0, align 1, !tbaa !5
  %5 = and i32 %3, 16
  %.not = icmp eq i32 %5, 0
  %6 = shl nuw nsw i32 %5, 12
  %7 = and i32 %3, 1
  %8 = shl nuw nsw i32 %7, 22
  %9 = or disjoint i32 %6, %8
  %10 = or disjoint i32 %9, 1107558400
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %10, ptr %11, align 1, !tbaa !12
  %12 = and i8 %2, 7
  %13 = zext nneg i8 %12 to i16
  %14 = shl nuw nsw i16 %13, 6
  %15 = or disjoint i16 %14, 513
  %16 = getelementptr inbounds i8, ptr %0, i64 38
  store i16 %15, ptr %16, align 1, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %1, ptr %17, align 1, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 1248, ptr %18, align 1, !tbaa !15
  br i1 %.not, label %24, label %19

19:                                               ; preds = %4
  %20 = mul nuw nsw i32 %7, 1248
  %21 = zext nneg i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %1, i64 %21
  %23 = getelementptr inbounds i8, ptr %22, i64 1076
  store i16 1, ptr %23, align 4, !tbaa !16
  br label %24

24:                                               ; preds = %19, %4
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !11, i64 36, !11, i64 38, !10, i64 40, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !11, i64 38}
!14 = !{!6, !10, i64 40}
!15 = !{!6, !7, i64 52}
!16 = !{!17, !11, i64 1076}
!17 = !{!"", !18, i64 0, !8, i64 24, !19, i64 168}
!18 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!19 = !{!"", !8, i64 0, !7, i64 8, !7, i64 12, !8, i64 16, !8, i64 272, !7, i64 304, !8, i64 308, !8, i64 309, !11, i64 310, !8, i64 312, !8, i64 332, !8, i64 352, !8, i64 372, !8, i64 392, !8, i64 640, !11, i64 908, !11, i64 910, !8, i64 912, !20, i64 1084, !11, i64 1086, !8, i64 1088, !8, i64 5184}
!20 = !{!"", !11, i64 0, !11, i64 1}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass