; LLVM IR from intel/qpl :: sources/middle-layer/compression/dictionary (dictionary_utils)

; 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.qpl_dictionary = type { i8, i8, i64, i32, i32, i32, i32, i32 }

@_ZN3qpl2ml11compressionL24hardware_hash_table_sizeE = external hidden constant [3 x i32], align 4
@_ZN3qpl2ml11compressionL24software_hash_table_sizeE = external hidden constant [10 x i32], align 16

; 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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN3qpl2ml11compression31get_history_size_for_dictionaryE25hardware_dictionary_level(i8 noundef signext) #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml11compression16build_dictionaryER14qpl_dictionary26software_compression_level25hardware_dictionary_levelPKhm(ptr noundef nonnull align 8 dereferenceable(40) %0, i8 noundef signext %1, i8 noundef signext %2, ptr noundef %3, i64 noundef %4) #1 personality ptr @__gxx_personality_v0 {
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i8 %1, ptr %7, align 1, !tbaa !9
  store i8 %2, ptr %8, align 1, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i64 %4, ptr %10, align 8, !tbaa !13
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.qpl_dictionary, ptr %13, i32 0, i32 5
  store i32 0, ptr %14, align 8, !tbaa !15
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.qpl_dictionary, ptr %15, i32 0, i32 3
  store i32 0, ptr %16, align 8, !tbaa !18
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.qpl_dictionary, ptr %17, i32 0, i32 6
  store i32 0, ptr %18, align 4, !tbaa !19
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.qpl_dictionary, ptr %19, i32 0, i32 7
  store i32 0, ptr %20, align 8, !tbaa !20
  %21 = load i8, ptr %7, align 1, !tbaa !9
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.qpl_dictionary, ptr %22, i32 0, i32 0
  store i8 %21, ptr %23, align 8, !tbaa !21
  %24 = load i8, ptr %8, align 1, !tbaa !11
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.qpl_dictionary, ptr %25, i32 0, i32 1
  store i8 %24, ptr %26, align 1, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 40, ptr %11, align 4, !tbaa !23
  %27 = load i32, ptr %11, align 4, !tbaa !23
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.qpl_dictionary, ptr %28, i32 0, i32 5
  store i32 %27, ptr %29, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %30 = load i8, ptr %8, align 1, !tbaa !11
  %31 = call noundef i64 @_ZN3qpl2ml11compression31get_history_size_for_dictionaryE25hardware_dictionary_level(i8 noundef signext %30) #5
  store i64 %31, ptr %12, align 8, !tbaa !13
  %32 = load i64, ptr %10, align 8, !tbaa !13
  %33 = load i64, ptr %12, align 8, !tbaa !13
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %35, label %46

35:                                               ; preds = %5
  %36 = load i8, ptr %8, align 1, !tbaa !11
  %37 = icmp ne i8 -1, %36
  br i1 %37, label %38, label %45

38:                                               ; preds = %35
  %39 = load i64, ptr %12, align 8, !tbaa !13
  %40 = load i64, ptr %10, align 8, !tbaa !13
  %41 = sub i64 %39, %40
  %42 = trunc i64 %41 to i32
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.qpl_dictionary, ptr %43, i32 0, i32 3
  store i32 %42, ptr %44, align 8, !tbaa !18
  br label %45

45:                                               ; preds = %38, %35
  br label %53

46:                                               ; preds = %5
  %47 = load i64, ptr %10, align 8, !tbaa !13
  %48 = load i64, ptr %12, align 8, !tbaa !13
  %49 = sub i64 %47, %48
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i64 %49
  store ptr %51, ptr %9, align 8, !tbaa !5
  %52 = load i64, ptr %12, align 8, !tbaa !13
  store i64 %52, ptr %10, align 8, !tbaa !13
  br label %53

53:                                               ; preds = %46, %45
  %54 = load i64, ptr %10, align 8, !tbaa !13
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.qpl_dictionary, ptr %55, i32 0, i32 2
  store i64 %54, ptr %56, align 8, !tbaa !24
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = load i64, ptr %10, align 8, !tbaa !13
  %60 = getelementptr inbounds i8, ptr %58, i64 %59
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = call noundef ptr @_ZN3qpl2ml11compression19get_dictionary_dataER14qpl_dictionary(ptr noundef nonnull align 8 dereferenceable(40) %61) #5
  call void @_ZN3qpl7core_sw4util4copyIPKhPhEEvT_S6_T0_(ptr noundef %57, ptr noundef %60, ptr noundef %62) #5
  %63 = load i64, ptr %10, align 8, !tbaa !13
  %64 = trunc i64 %63 to i32
  %65 = load i32, ptr %11, align 4, !tbaa !23
  %66 = add i32 %65, %64
  store i32 %66, ptr %11, align 4, !tbaa !23
  %67 = load i8, ptr %8, align 1, !tbaa !11
  %68 = icmp ne i8 -1, %67
  br i1 %68, label %69, label %82

69:                                               ; preds = %53
  %70 = load i32, ptr %11, align 4, !tbaa !23
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.qpl_dictionary, ptr %71, i32 0, i32 6
  store i32 %70, ptr %72, align 4, !tbaa !19
  %73 = load i8, ptr %8, align 1, !tbaa !11
  %74 = sext i8 %73 to i32
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds [3 x i32], ptr @_ZN3qpl2ml11compressionL24hardware_hash_table_sizeE, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !23
  %78 = load i32, ptr %11, align 4, !tbaa !23
  %79 = add i32 %78, %77
  store i32 %79, ptr %11, align 4, !tbaa !23
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  invoke void @_ZN3qpl2ml11compressionL23init_hw_dict_hash_tableER14qpl_dictionary(ptr noundef nonnull align 8 dereferenceable(40) %80)
          to label %81 unwind label %97

81:                                               ; preds = %69
  br label %82

82:                                               ; preds = %81, %53
  %83 = load i8, ptr %7, align 1, !tbaa !9
  %84 = icmp ne i8 -1, %83
  br i1 %84, label %85, label %96

85:                                               ; preds = %82
  %86 = load i32, ptr %11, align 4, !tbaa !23
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.qpl_dictionary, ptr %87, i32 0, i32 7
  store i32 %86, ptr %88, align 8, !tbaa !20
  %89 = load i8, ptr %7, align 1, !tbaa !9
  %90 = sext i8 %89 to i32
  %91 = zext i32 %90 to i64
  %92 = getelementptr inbounds [10 x i32], ptr @_ZN3qpl2ml11compressionL24software_hash_table_sizeE, i64 0, i64 %91
  %93 = load i32, ptr %92, align 4, !tbaa !23
  %94 = load i32, ptr %11, align 4, !tbaa !23
  %95 = add i32 %94, %93
  store i32 %95, ptr %11, align 4, !tbaa !23
  br label %96

96:                                               ; preds = %85, %82
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  ret i32 0

97:                                               ; preds = %69
  %98 = landingpad { ptr, i32 }
          catch ptr null
  %99 = extractvalue { ptr, i32 } %98, 0
  call void @__clang_call_terminate(ptr %99) #6
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qpl7core_sw4util4copyIPKhPhEEvT_S6_T0_(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qpl2ml11compression19get_dictionary_dataER14qpl_dictionary(ptr noundef nonnull align 8 dereferenceable(40)) #1

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @_ZN3qpl2ml11compressionL23init_hw_dict_hash_tableER14qpl_dictionary(ptr noundef nonnull align 8 dereferenceable(40)) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { noinline noreturn nounwind uwtable "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 = { 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 #4 = { inlinehint mustprogress 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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"_ZTS26software_compression_level", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTS25hardware_dictionary_level", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !17, i64 24}
!16 = !{!"_ZTS14qpl_dictionary", !10, i64 0, !12, i64 1, !14, i64 8, !17, i64 16, !17, i64 20, !17, i64 24, !17, i64 28, !17, i64 32}
!17 = !{!"int", !7, i64 0}
!18 = !{!16, !17, i64 16}
!19 = !{!16, !17, i64 28}
!20 = !{!16, !17, i64 32}
!21 = !{!16, !10, i64 0}
!22 = !{!16, !12, i64 1}
!23 = !{!17, !17, i64 0}
!24 = !{!16, !14, i64 8}


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

@_ZN3qpl2ml11compressionL24hardware_hash_table_sizeE = external hidden local_unnamed_addr constant [3 x i32], align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN3qpl2ml11compression31get_history_size_for_dictionaryE25hardware_dictionary_level(i8 noundef signext) local_unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml11compression16build_dictionaryER14qpl_dictionary26software_compression_level25hardware_dictionary_levelPKhm(ptr noundef nonnull align 8 dereferenceable(40) %0, i8 noundef signext %1, i8 noundef signext %2, ptr noundef %3, i64 noundef %4) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 0, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 0, ptr %8, align 4, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 0, ptr %9, align 8, !tbaa !14
  store i8 %1, ptr %0, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 %2, ptr %10, align 1, !tbaa !16
  store i32 40, ptr %6, align 8, !tbaa !17
  %11 = tail call noundef i64 @_ZN3qpl2ml11compression31get_history_size_for_dictionaryE25hardware_dictionary_level(i8 noundef signext %2) #4
  %12 = icmp ugt i64 %11, %4
  br i1 %12, label %13, label %17

13:                                               ; preds = %5
  %.not = icmp eq i8 %2, -1
  br i1 %.not, label %20, label %14

14:                                               ; preds = %13
  %15 = sub i64 %11, %4
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %7, align 8, !tbaa !5
  br label %20

17:                                               ; preds = %5
  %18 = sub i64 %4, %11
  %19 = getelementptr inbounds i8, ptr %3, i64 %18
  br label %20

20:                                               ; preds = %13, %14, %17
  %.040 = phi i64 [ %4, %14 ], [ %4, %13 ], [ %11, %17 ]
  %.0 = phi ptr [ %3, %14 ], [ %3, %13 ], [ %19, %17 ]
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %.040, ptr %21, align 8, !tbaa !18
  %22 = getelementptr inbounds i8, ptr %.0, i64 %.040
  %23 = tail call noundef ptr @_ZN3qpl2ml11compression19get_dictionary_dataER14qpl_dictionary(ptr noundef nonnull align 8 dereferenceable(40) %0) #4
  tail call void @_ZN3qpl7core_sw4util4copyIPKhPhEEvT_S6_T0_(ptr noundef %.0, ptr noundef %22, ptr noundef %23) #4
  %24 = trunc i64 %.040 to i32
  %25 = add i32 %24, 40
  %.not46 = icmp eq i8 %2, -1
  br i1 %.not46, label %32, label %26

26:                                               ; preds = %20
  store i32 %25, ptr %8, align 4, !tbaa !13
  %27 = sext i8 %2 to i64
  %28 = and i64 %27, 4294967295
  %29 = getelementptr inbounds [3 x i32], ptr @_ZN3qpl2ml11compressionL24hardware_hash_table_sizeE, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !19
  %31 = add i32 %30, %25
  invoke void @_ZN3qpl2ml11compressionL23init_hw_dict_hash_tableER14qpl_dictionary(ptr noundef nonnull align 8 dereferenceable(40) %0)
          to label %32 unwind label %35

32:                                               ; preds = %26, %20
  %.039 = phi i32 [ %31, %26 ], [ %25, %20 ]
  %.not47 = icmp eq i8 %1, -1
  br i1 %.not47, label %34, label %33

33:                                               ; preds = %32
  store i32 %.039, ptr %9, align 8, !tbaa !14
  br label %34

34:                                               ; preds = %33, %32
  ret i32 0

35:                                               ; preds = %26
  %36 = landingpad { ptr, i32 }
          catch ptr null
  %37 = extractvalue { ptr, i32 } %36, 0
  tail call void @__clang_call_terminate(ptr %37) #5
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qpl7core_sw4util4copyIPKhPhEEvT_S6_T0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qpl2ml11compression19get_dictionary_dataER14qpl_dictionary(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @_ZN3qpl2ml11compressionL23init_hw_dict_hash_tableER14qpl_dictionary(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #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 = { noinline noreturn nounwind uwtable "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 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 = { inlinehint mustprogress 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 #4 = { nounwind }
attributes #5 = { noreturn 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, !12, i64 16}
!6 = !{!"_ZTS14qpl_dictionary", !7, i64 0, !10, i64 1, !11, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32}
!7 = !{!"_ZTS26software_compression_level", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS25hardware_dictionary_level", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !12, i64 28}
!14 = !{!6, !12, i64 32}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !10, i64 1}
!17 = !{!6, !12, i64 24}
!18 = !{!6, !11, i64 8}
!19 = !{!12, !12, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass