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

; Function Attrs: mustprogress uwtable
define dso_local i32 @qpl_deflate_huffman_table_create(i32 noundef %0, i32 noundef %1, ptr %2, ptr %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca %struct.allocator_t, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %struct.allocator_t, align 8
  %14 = alloca %struct.allocator_t, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca %struct.allocator_t, align 8
  %20 = getelementptr inbounds { ptr, ptr }, ptr %7, i32 0, i32 0
  store ptr %2, ptr %20, align 8
  %21 = getelementptr inbounds { ptr, ptr }, ptr %7, i32 0, i32 1
  store ptr %3, ptr %21, align 8
  store i32 %0, ptr %8, align 4, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %22 = load ptr, ptr %10, align 8, !tbaa !11
  %23 = call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIPP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef %22) #6
  store i32 %23, ptr %11, align 4, !tbaa !13
  %24 = load i32, ptr %11, align 4, !tbaa !13
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %5
  %27 = load i32, ptr %11, align 4, !tbaa !13
  store i32 %27, ptr %6, align 4
  store i32 1, ptr %12, align 4
  br label %29

28:                                               ; preds = %5
  store i32 0, ptr %12, align 4
  br label %29

29:                                               ; preds = %28, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  %30 = load i32, ptr %12, align 4
  switch i32 %30, label %75 [
    i32 0, label %31
    i32 1, label %73
  ]

31:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %14, ptr align 8 %7, i64 16, i1 false), !tbaa.struct !15
  %32 = getelementptr inbounds { ptr, ptr }, ptr %14, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8
  %34 = getelementptr inbounds { ptr, ptr }, ptr %14, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8
  %36 = call { ptr, ptr } @_ZN3qpl2ml11compression7detailsL13get_allocatorE11allocator_t(ptr %33, ptr %35)
  %37 = getelementptr inbounds { ptr, ptr }, ptr %13, i32 0, i32 0
  %38 = extractvalue { ptr, ptr } %36, 0
  store ptr %38, ptr %37, align 8
  %39 = getelementptr inbounds { ptr, ptr }, ptr %13, i32 0, i32 1
  %40 = extractvalue { ptr, ptr } %36, 1
  store ptr %40, ptr %39, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  store i64 72, ptr %15, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  %41 = getelementptr inbounds %struct.allocator_t, ptr %13, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = load i64, ptr %15, align 8, !tbaa !16
  %44 = call noundef ptr %42(i64 noundef %43)
  store ptr %44, ptr %16, align 8, !tbaa !11
  %45 = load ptr, ptr %16, align 8, !tbaa !11
  %46 = icmp ne ptr %45, null
  br i1 %46, label %48, label %47

47:                                               ; preds = %31
  store i32 106, ptr %6, align 4
  store i32 1, ptr %12, align 4
  br label %72

48:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #6
  %49 = load ptr, ptr %16, align 8, !tbaa !11
  call void @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EEC2Ev(ptr noundef nonnull align 8 dereferenceable(72) %49)
  store ptr %49, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #6
  %50 = load ptr, ptr %17, align 8, !tbaa !11
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = trunc i32 %51 to i8
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = trunc i32 %53 to i8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %19, ptr align 8 %7, i64 16, i1 false), !tbaa.struct !15
  %55 = getelementptr inbounds { ptr, ptr }, ptr %19, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8
  %57 = getelementptr inbounds { ptr, ptr }, ptr %19, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8
  %59 = call noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE6createENS1_20huffman_table_type_eENS0_16execution_path_tE11allocator_t(ptr noundef nonnull align 8 dereferenceable(72) %50, i8 noundef zeroext %52, i8 noundef zeroext %54, ptr %56, ptr %58)
  store i32 %59, ptr %18, align 4, !tbaa !13
  %60 = load i32, ptr %18, align 4, !tbaa !13
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %68

62:                                               ; preds = %48
  %63 = load ptr, ptr %17, align 8, !tbaa !11
  call void @_ZSt10destroy_atIN3qpl2ml11compression15huffman_table_tILNS2_23compression_algorithm_eE0EEEEvPT_(ptr noundef %63)
  %64 = getelementptr inbounds %struct.allocator_t, ptr %13, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !20
  %66 = load ptr, ptr %16, align 8, !tbaa !11
  call void %65(ptr noundef %66)
  %67 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr null, ptr %67, align 8, !tbaa !11
  store i32 106, ptr %6, align 4
  store i32 1, ptr %12, align 4
  br label %71

68:                                               ; preds = %48
  %69 = load ptr, ptr %17, align 8, !tbaa !11
  %70 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %69, ptr %70, align 8, !tbaa !11
  store i32 0, ptr %6, align 4
  store i32 1, ptr %12, align 4
  br label %71

71:                                               ; preds = %68, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  br label %72

72:                                               ; preds = %71, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #6
  br label %73

73:                                               ; preds = %72, %29
  %74 = load i32, ptr %6, align 4
  ret i32 %74

75:                                               ; preds = %29
  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_nullptrIPP17qpl_huffman_tableJEEEjT_DpT0_(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: inlinehint mustprogress nounwind uwtable
declare hidden { ptr, ptr } @_ZN3qpl2ml11compression7detailsL13get_allocatorE11allocator_t(ptr, ptr) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EEC2Ev(ptr noundef nonnull align 8 dereferenceable(72)) unnamed_addr #4 align 2

declare noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE6createENS1_20huffman_table_type_eENS0_16execution_path_tE11allocator_t(ptr noundef nonnull align 8 dereferenceable(72), i8 noundef zeroext, i8 noundef zeroext, ptr, ptr) #5

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

attributes #0 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { "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 #6 = { 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 = !{!"_ZTS24qpl_huffman_table_type_e", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTS10qpl_path_t", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{i64 0, i64 8, !11, i64 8, i64 8, !11}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !12, i64 0}
!19 = !{!"_ZTS11allocator_t", !12, i64 0, !12, i64 8}
!20 = !{!19, !12, 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: mustprogress uwtable
define dso_local noundef i32 @qpl_deflate_huffman_table_create(i32 noundef %0, i32 noundef %1, ptr %2, ptr %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = tail call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIPP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef %4) #4
  %.not.not = icmp eq i32 %6, 0
  br i1 %.not.not, label %7, label %18

7:                                                ; preds = %5
  %8 = tail call { ptr, ptr } @_ZN3qpl2ml11compression7detailsL13get_allocatorE11allocator_t(ptr %2, ptr %3)
  %9 = extractvalue { ptr, ptr } %8, 0
  %10 = extractvalue { ptr, ptr } %8, 1
  %11 = tail call noundef ptr %9(i64 noundef 72)
  %.not21 = icmp eq ptr %11, null
  br i1 %.not21, label %18, label %12

12:                                               ; preds = %7
  tail call void @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EEC2Ev(ptr noundef nonnull align 8 dereferenceable(72) %11)
  %13 = trunc i32 %0 to i8
  %14 = trunc i32 %1 to i8
  %15 = tail call noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE6createENS1_20huffman_table_type_eENS0_16execution_path_tE11allocator_t(ptr noundef nonnull align 8 dereferenceable(72) %11, i8 noundef zeroext %13, i8 noundef zeroext %14, ptr %2, ptr %3)
  %.not22 = icmp eq i32 %15, 0
  br i1 %.not22, label %17, label %16

16:                                               ; preds = %12
  tail call void @_ZSt10destroy_atIN3qpl2ml11compression15huffman_table_tILNS2_23compression_algorithm_eE0EEEEvPT_(ptr noundef nonnull %11)
  tail call void %10(ptr noundef nonnull %11)
  br label %17

17:                                               ; preds = %12, %16
  %storemerge = phi ptr [ null, %16 ], [ %11, %12 ]
  %.1 = phi i32 [ 106, %16 ], [ 0, %12 ]
  store ptr %storemerge, ptr %4, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %5, %17, %7
  %.3 = phi i32 [ %6, %5 ], [ %.1, %17 ], [ 106, %7 ]
  ret i32 %.3
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden { ptr, ptr } @_ZN3qpl2ml11compression7detailsL13get_allocatorE11allocator_t(ptr, ptr) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EEC2Ev(ptr noundef nonnull align 8 dereferenceable(72)) unnamed_addr #2 align 2

declare noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE6createENS1_20huffman_table_type_eENS0_16execution_path_tE11allocator_t(ptr noundef nonnull align 8 dereferenceable(72), i8 noundef zeroext, i8 noundef zeroext, ptr, ptr) local_unnamed_addr #3

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

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


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