; LLVM IR from intel/qpl :: sources/c_api/compression_operations (statistics)

; 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: mustprogress nounwind uwtable
define dso_local i32 @qpl_gather_deflate_statistics(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %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 i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  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 !11
  store i32 %4, ptr %11, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIPhJP13qpl_histogramEEEjT_DpT0_(ptr noundef %17, ptr noundef %18) #4
  store i32 %19, ptr %12, align 4, !tbaa !9
  %20 = load i32, ptr %12, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %5
  %23 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %23, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %25

24:                                               ; preds = %5
  store i32 0, ptr %13, align 4
  br label %25

25:                                               ; preds = %24, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %26 = load i32, ptr %13, align 4
  switch i32 %26, label %73 [
    i32 0, label %27
    i32 1, label %71
  ]

27:                                               ; preds = %25
  %28 = load i32, ptr %10, align 4, !tbaa !11
  %29 = icmp ne i32 %28, 3
  br i1 %29, label %30, label %34

30:                                               ; preds = %27
  %31 = load i32, ptr %10, align 4, !tbaa !11
  %32 = icmp ne i32 %31, 1
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  store i32 87, ptr %6, align 4
  br label %71

34:                                               ; preds = %30, %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %35, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  store ptr %39, ptr %16, align 8, !tbaa !5
  %40 = load i32, ptr %11, align 4, !tbaa !13
  switch i32 %40, label %69 [
    i32 0, label %41
    i32 1, label %56
    i32 2, label %62
  ]

41:                                               ; preds = %34
  %42 = load ptr, ptr %15, align 8, !tbaa !5
  %43 = load ptr, ptr %16, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = call noundef i32 @_ZN3qpl2ml11compression16update_histogramILNS0_16execution_path_tE1EPKhvEEjT0_S6_R13qpl_histogram22qpl_compression_levels(ptr noundef %42, ptr noundef %43, ptr noundef nonnull align 4 dereferenceable(1280) %44, i32 noundef 1) #4
  store i32 %45, ptr %14, align 4, !tbaa !9
  %46 = load i32, ptr %14, align 4, !tbaa !9
  %47 = icmp ne i32 0, %46
  br i1 %47, label %48, label %54

48:                                               ; preds = %41
  %49 = load ptr, ptr %15, align 8, !tbaa !5
  %50 = load ptr, ptr %16, align 8, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load i32, ptr %10, align 4, !tbaa !11
  %53 = call noundef i32 @_ZN3qpl2ml11compression16update_histogramILNS0_16execution_path_tE2EPKhvEEjT0_S6_R13qpl_histogram22qpl_compression_levels(ptr noundef %49, ptr noundef %50, ptr noundef nonnull align 4 dereferenceable(1280) %51, i32 noundef %52) #4
  store i32 %53, ptr %14, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %48, %41
  %55 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %55, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %70

56:                                               ; preds = %34
  %57 = load ptr, ptr %15, align 8, !tbaa !5
  %58 = load ptr, ptr %16, align 8, !tbaa !5
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = call noundef i32 @_ZN3qpl2ml11compression16update_histogramILNS0_16execution_path_tE1EPKhvEEjT0_S6_R13qpl_histogram22qpl_compression_levels(ptr noundef %57, ptr noundef %58, ptr noundef nonnull align 4 dereferenceable(1280) %59, i32 noundef 1) #4
  store i32 %60, ptr %14, align 4, !tbaa !9
  %61 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %61, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %70

62:                                               ; preds = %34
  %63 = load ptr, ptr %15, align 8, !tbaa !5
  %64 = load ptr, ptr %16, align 8, !tbaa !5
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = load i32, ptr %10, align 4, !tbaa !11
  %67 = call noundef i32 @_ZN3qpl2ml11compression16update_histogramILNS0_16execution_path_tE2EPKhvEEjT0_S6_R13qpl_histogram22qpl_compression_levels(ptr noundef %63, ptr noundef %64, ptr noundef nonnull align 4 dereferenceable(1280) %65, i32 noundef %66) #4
  store i32 %67, ptr %14, align 4, !tbaa !9
  %68 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %68, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %70

69:                                               ; preds = %34
  store i32 54, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %70

70:                                               ; preds = %69, %62, %56, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %71

71:                                               ; preds = %70, %33, %25
  %72 = load i32, ptr %6, align 4
  ret i32 %72

73:                                               ; preds = %25
  unreachable
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIPhJP13qpl_histogramEEEjT_DpT0_(ptr noundef, ptr noundef) #2

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

; Function Attrs: nounwind
declare noundef i32 @_ZN3qpl2ml11compression16update_histogramILNS0_16execution_path_tE1EPKhvEEjT0_S6_R13qpl_histogram22qpl_compression_levels(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(1280), i32 noundef) #3

; Function Attrs: nounwind
declare noundef i32 @_ZN3qpl2ml11compression16update_histogramILNS0_16execution_path_tE2EPKhvEEjT0_S6_R13qpl_histogram22qpl_compression_levels(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(1280), i32 noundef) #3

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 "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 #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTS22qpl_compression_levels", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_ZTS10qpl_path_t", !7, i64 0}


; 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 nounwind uwtable
define dso_local noundef i32 @qpl_gather_deflate_statistics(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = tail call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIPhJP13qpl_histogramEEEjT_DpT0_(ptr noundef %0, ptr noundef %2) #3
  %.not.not = icmp eq i32 %6, 0
  br i1 %.not.not, label %7, label %20

7:                                                ; preds = %5
  %8 = and i32 %3, -3
  %or.cond.not = icmp eq i32 %8, 1
  br i1 %or.cond.not, label %9, label %20

9:                                                ; preds = %7
  %10 = zext i32 %1 to i64
  %11 = getelementptr inbounds i8, ptr %0, i64 %10
  switch i32 %4, label %20 [
    i32 0, label %12
    i32 1, label %16
    i32 2, label %18
  ]

12:                                               ; preds = %9
  %13 = tail call noundef i32 @_ZN3qpl2ml11compression16update_histogramILNS0_16execution_path_tE1EPKhvEEjT0_S6_R13qpl_histogram22qpl_compression_levels(ptr noundef %0, ptr noundef %11, ptr noundef nonnull align 4 dereferenceable(1280) %2, i32 noundef 1) #3
  %.not32 = icmp eq i32 %13, 0
  br i1 %.not32, label %20, label %14

14:                                               ; preds = %12
  %15 = tail call noundef i32 @_ZN3qpl2ml11compression16update_histogramILNS0_16execution_path_tE2EPKhvEEjT0_S6_R13qpl_histogram22qpl_compression_levels(ptr noundef %0, ptr noundef %11, ptr noundef nonnull align 4 dereferenceable(1280) %2, i32 noundef %3) #3
  br label %20

16:                                               ; preds = %9
  %17 = tail call noundef i32 @_ZN3qpl2ml11compression16update_histogramILNS0_16execution_path_tE1EPKhvEEjT0_S6_R13qpl_histogram22qpl_compression_levels(ptr noundef %0, ptr noundef %11, ptr noundef nonnull align 4 dereferenceable(1280) %2, i32 noundef 1) #3
  br label %20

18:                                               ; preds = %9
  %19 = tail call noundef i32 @_ZN3qpl2ml11compression16update_histogramILNS0_16execution_path_tE2EPKhvEEjT0_S6_R13qpl_histogram22qpl_compression_levels(ptr noundef %0, ptr noundef %11, ptr noundef nonnull align 4 dereferenceable(1280) %2, i32 noundef %3) #3
  br label %20

20:                                               ; preds = %5, %16, %18, %14, %12, %9, %7
  %.2 = phi i32 [ %6, %5 ], [ 87, %7 ], [ %19, %18 ], [ %17, %16 ], [ %15, %14 ], [ 0, %12 ], [ 54, %9 ]
  ret i32 %.2
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIPhJP13qpl_histogramEEEjT_DpT0_(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare noundef i32 @_ZN3qpl2ml11compression16update_histogramILNS0_16execution_path_tE1EPKhvEEjT0_S6_R13qpl_histogram22qpl_compression_levels(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(1280), i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare noundef i32 @_ZN3qpl2ml11compression16update_histogramILNS0_16execution_path_tE2EPKhvEEjT0_S6_R13qpl_histogram22qpl_compression_levels(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(1280), i32 noundef) local_unnamed_addr #2

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


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass