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

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

; 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
define dso_local noundef i32 @_ZN3qpl2ml11compression27get_dictionary_size_in_aecsER14qpl_dictionary(ptr noundef nonnull align 8 dereferenceable(40) %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.qpl_dictionary, ptr %7, i32 0, i32 1
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = icmp eq i8 -1, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  br label %31

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.qpl_dictionary, ptr %13, i32 0, i32 1
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds [3 x i32], ptr @_ZN3qpl2ml11compressionL24hardware_hash_table_sizeE, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !15
  store i32 %19, ptr %4, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.qpl_dictionary, ptr %20, i32 0, i32 1
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds [3 x i32], ptr @_ZN3qpl2ml11compressionL29hardware_dictionary_text_sizeE, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !15
  store i32 %26, ptr %5, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %27 = load i32, ptr %4, align 4, !tbaa !15
  %28 = load i32, ptr %5, align 4, !tbaa !15
  %29 = add i32 %27, %28
  store i32 %29, ptr %6, align 4, !tbaa !15
  %30 = load i32, ptr %6, align 4, !tbaa !15
  store i32 %30, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %31

31:                                               ; preds = %12, %11
  %32 = load i32, ptr %2, align 4
  ret i32 %32
}

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 = { 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, !12, i64 1}
!10 = !{!"_ZTS14qpl_dictionary", !11, i64 0, !12, i64 1, !13, i64 8, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32}
!11 = !{!"_ZTS26software_compression_level", !7, i64 0}
!12 = !{!"_ZTS25hardware_dictionary_level", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, 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"

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef i32 @_ZN3qpl2ml11compression27get_dictionary_size_in_aecsER14qpl_dictionary(ptr nocapture noundef nonnull readonly align 8 dereferenceable(40) %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 1
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %4 = icmp eq i8 %3, -1
  br i1 %4, label %13, label %5

5:                                                ; preds = %1
  %6 = sext i8 %3 to i64
  %7 = and i64 %6, 4294967295
  %8 = getelementptr inbounds [3 x i32], ptr @_ZN3qpl2ml11compressionL24hardware_hash_table_sizeE, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !13
  %10 = getelementptr inbounds [3 x i32], ptr @_ZN3qpl2ml11compressionL29hardware_dictionary_text_sizeE, i64 0, i64 %7
  %11 = load i32, ptr %10, align 4, !tbaa !13
  %12 = add i32 %11, %9
  br label %13

13:                                               ; preds = %1, %5
  %.0 = phi i32 [ %12, %5 ], [ 0, %1 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !10, i64 1}
!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 = !{!12, !12, i64 0}


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