; 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.allocator_t = type { ptr, ptr }
%"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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt10destroy_atIN3qpl2ml11compression15huffman_table_tILNS2_23compression_algorithm_eE0EEEEvPT_(ptr noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt10destroy_atIN3qpl2ml11compression15huffman_table_tILNS2_23compression_algorithm_eE2EEEEvPT_(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local i32 @qpl_huffman_table_destroy(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.allocator_t, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.allocator_t, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef %11) #4
  store i32 %12, ptr %4, align 4, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %1
  %16 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %16, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %18

17:                                               ; preds = %1
  store i32 0, ptr %5, align 4
  br label %18

18:                                               ; preds = %17, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %19 = load i32, ptr %5, align 4
  switch i32 %19, label %59 [
    i32 0, label %20
    i32 1, label %57
  ]

20:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %21, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.qpl::ml::compression::huffman_table_meta_t", ptr %22, i32 0, i32 2
  %24 = load i8, ptr %23, align 4, !tbaa !11
  %25 = icmp eq i8 %24, 0
  br i1 %25, label %26, label %38

26:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %27, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call { ptr, ptr } @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE22get_internal_allocatorEv(ptr noundef nonnull align 8 dereferenceable(72) %28) #4
  %30 = getelementptr inbounds { ptr, ptr }, ptr %8, i32 0, i32 0
  %31 = extractvalue { ptr, ptr } %29, 0
  store ptr %31, ptr %30, align 8
  %32 = getelementptr inbounds { ptr, ptr }, ptr %8, i32 0, i32 1
  %33 = extractvalue { ptr, ptr } %29, 1
  store ptr %33, ptr %32, align 8
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZSt10destroy_atIN3qpl2ml11compression15huffman_table_tILNS2_23compression_algorithm_eE0EEEEvPT_(ptr noundef %34)
  %35 = getelementptr inbounds %struct.allocator_t, ptr %8, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  call void %36(ptr noundef %37)
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %56

38:                                               ; preds = %20
  %39 = load ptr, ptr %6, 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 %55

43:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %44, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = call { ptr, ptr } @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE2EE22get_internal_allocatorEv(ptr noundef nonnull align 8 dereferenceable(72) %45) #4
  %47 = getelementptr inbounds { ptr, ptr }, ptr %10, i32 0, i32 0
  %48 = extractvalue { ptr, ptr } %46, 0
  store ptr %48, ptr %47, align 8
  %49 = getelementptr inbounds { ptr, ptr }, ptr %10, i32 0, i32 1
  %50 = extractvalue { ptr, ptr } %46, 1
  store ptr %50, ptr %49, align 8
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  call void @_ZSt10destroy_atIN3qpl2ml11compression15huffman_table_tILNS2_23compression_algorithm_eE2EEEEvPT_(ptr noundef %51)
  %52 = getelementptr inbounds %struct.allocator_t, ptr %10, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  call void %53(ptr noundef %54)
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %55

55:                                               ; preds = %43, %38
  br label %56

56:                                               ; preds = %55, %26
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %57

57:                                               ; preds = %56, %18
  %58 = load i32, ptr %2, align 4
  ret i32 %58

59:                                               ; preds = %18
  unreachable
}

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

; Function Attrs: nounwind
declare { ptr, ptr } @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE22get_internal_allocatorEv(ptr noundef nonnull align 8 dereferenceable(72)) #3

; Function Attrs: nounwind
declare { ptr, ptr } @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE2EE22get_internal_allocatorEv(ptr noundef nonnull align 8 dereferenceable(72)) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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}
!17 = !{!18, !6, i64 8}
!18 = !{!"_ZTS11allocator_t", !6, i64 0, !6, 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"

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt10destroy_atIN3qpl2ml11compression15huffman_table_tILNS2_23compression_algorithm_eE0EEEEvPT_(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt10destroy_atIN3qpl2ml11compression15huffman_table_tILNS2_23compression_algorithm_eE2EEEEvPT_(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @qpl_huffman_table_destroy(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef %0) #3
  %.not.not = icmp eq i32 %2, 0
  br i1 %.not.not, label %3, label %10

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

6:                                                ; preds = %3
  %7 = tail call { ptr, ptr } @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE22get_internal_allocatorEv(ptr noundef nonnull align 8 dereferenceable(72) %0) #3
  tail call void @_ZSt10destroy_atIN3qpl2ml11compression15huffman_table_tILNS2_23compression_algorithm_eE0EEEEvPT_(ptr noundef nonnull %0)
  br label %.sink.split

8:                                                ; preds = %3
  %9 = tail call { ptr, ptr } @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE2EE22get_internal_allocatorEv(ptr noundef nonnull align 8 dereferenceable(72) %0) #3
  tail call void @_ZSt10destroy_atIN3qpl2ml11compression15huffman_table_tILNS2_23compression_algorithm_eE2EEEEvPT_(ptr noundef nonnull %0)
  br label %.sink.split

.sink.split:                                      ; preds = %8, %6
  %.pn = phi { ptr, ptr } [ %7, %6 ], [ %9, %8 ]
  %.sink = extractvalue { ptr, ptr } %.pn, 1
  tail call void %.sink(ptr noundef nonnull %0)
  br label %10

10:                                               ; preds = %.sink.split, %1, %3
  ret i32 %2
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef) local_unnamed_addr #0

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

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

attributes #0 = { 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 #1 = { 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 #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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass