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

; 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::ml::compression::huffman_table_meta_t" = type { [4 x i8], i32, i8, i8, i8, i8, i32 }

; 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 i32 @qpl_huffman_table_init_with_other(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 20, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIP17qpl_huffman_tableJS4_EEEjT_DpT0_(ptr noundef %15, ptr noundef %16) #4
  store i32 %17, ptr %7, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %2
  %21 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %21, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %23

22:                                               ; preds = %2
  store i32 0, ptr %8, align 4
  br label %23

23:                                               ; preds = %22, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %24 = load i32, ptr %8, align 4
  switch i32 %24, label %51 [
    i32 0, label %25
  ]

25:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %26, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %27, ptr %10, align 8, !tbaa !5
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.qpl::ml::compression::huffman_table_meta_t", ptr %28, i32 0, i32 2
  %30 = load i8, ptr %29, align 4, !tbaa !11
  %31 = icmp eq i8 %30, 0
  br i1 %31, label %32, label %38

32:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %33, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %34, ptr %12, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = call noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE4initERKS4_(ptr noundef nonnull align 8 dereferenceable(72) %35, ptr noundef nonnull align 8 dereferenceable(72) %36) #4
  store i32 %37, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %50

38:                                               ; preds = %25
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.qpl::ml::compression::huffman_table_meta_t", ptr %39, i32 0, i32 2
  %41 = load i8, ptr %40, align 4, !tbaa !11
  %42 = icmp eq i8 %41, 2
  br i1 %42, label %43, label %49

43:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %44, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %45, ptr %14, align 8, !tbaa !5
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = load ptr, ptr %14, align 8, !tbaa !5
  %48 = call noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE2EE4initERKS4_(ptr noundef nonnull align 8 dereferenceable(72) %46, ptr noundef nonnull align 8 dereferenceable(72) %47) #4
  store i32 %48, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %50

49:                                               ; preds = %38
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %50

50:                                               ; preds = %49, %43, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %51

51:                                               ; preds = %50, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %52 = load i32, ptr %3, align 4
  ret i32 %52
}

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

; Function Attrs: nounwind
declare noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE4initERKS4_(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef nonnull align 8 dereferenceable(72)) #3

; Function Attrs: nounwind
declare noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE2EE4initERKS4_(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef nonnull align 8 dereferenceable(72)) #3

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 = { 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, !13, i64 8}
!12 = !{!"_ZTSN3qpl2ml11compression20huffman_table_meta_tE", !7, i64 0, !10, i64 4, !13, i64 8, !14, i64 9, !15, i64 10, !16, i64 11, !10, i64 12}
!13 = !{!"_ZTSN3qpl2ml11compression23compression_algorithm_eE", !7, i64 0}
!14 = !{!"_ZTSN3qpl2ml11compression15table_version_eE", !7, i64 0}
!15 = !{!"_ZTSN3qpl2ml11compression20huffman_table_type_eE", !7, i64 0}
!16 = !{!"_ZTSN3qpl2ml16execution_path_tE", !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_huffman_table_init_with_other(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIP17qpl_huffman_tableJS4_EEEjT_DpT0_(ptr noundef %0, ptr noundef %1) #3
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %11

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i8, ptr %5, align 4, !tbaa !5
  switch i8 %6, label %11 [
    i8 0, label %7
    i8 2, label %9
  ]

7:                                                ; preds = %4
  %8 = tail call noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE4initERKS4_(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef nonnull align 8 dereferenceable(72) %1) #3
  br label %11

9:                                                ; preds = %4
  %10 = tail call noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE2EE4initERKS4_(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef nonnull align 8 dereferenceable(72) %1) #3
  br label %11

11:                                               ; preds = %7, %9, %4, %2
  %.2 = phi i32 [ %3, %2 ], [ %8, %7 ], [ %10, %9 ], [ 0, %4 ]
  ret i32 %.2
}

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

; Function Attrs: nounwind
declare noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE4initERKS4_(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #2

; Function Attrs: nounwind
declare noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE2EE4initERKS4_(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef nonnull align 8 dereferenceable(72)) 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)"}
!5 = !{!6, !10, i64 8}
!6 = !{!"_ZTSN3qpl2ml11compression20huffman_table_meta_tE", !7, i64 0, !9, i64 4, !10, i64 8, !11, i64 9, !12, i64 10, !13, i64 11, !9, i64 12}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"_ZTSN3qpl2ml11compression23compression_algorithm_eE", !7, i64 0}
!11 = !{!"_ZTSN3qpl2ml11compression15table_version_eE", !7, i64 0}
!12 = !{!"_ZTSN3qpl2ml11compression20huffman_table_type_eE", !7, i64 0}
!13 = !{!"_ZTSN3qpl2ml16execution_path_tE", !7, i64 0}


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