; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; 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 hidden { ptr, ptr } @_ZN3qpl2ml11compression7detailsL13get_allocatorE11allocator_t(ptr, ptr) #1

; 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) #2

; Function Attrs: mustprogress uwtable
define dso_local i32 @qpl_huffman_only_table_create(i32 noundef %0, i32 noundef %1, ptr %2, ptr %3, ptr noundef %4) #3 {
  %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 %76 [
    i32 0, label %31
    i32 1, label %74
  ]

31:                                               ; preds = %29
  %32 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr null, ptr %32, align 8, !tbaa !11
  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
  %33 = getelementptr inbounds { ptr, ptr }, ptr %14, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8
  %35 = getelementptr inbounds { ptr, ptr }, ptr %14, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8
  %37 = call { ptr, ptr } @_ZN3qpl2ml11compression7detailsL13get_allocatorE11allocator_t(ptr %34, ptr %36)
  %38 = getelementptr inbounds { ptr, ptr }, ptr %13, i32 0, i32 0
  %39 = extractvalue { ptr, ptr } %37, 0
  store ptr %39, ptr %38, align 8
  %40 = getelementptr inbounds { ptr, ptr }, ptr %13, i32 0, i32 1
  %41 = extractvalue { ptr, ptr } %37, 1
  store ptr %41, ptr %40, 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
  %42 = getelementptr inbounds %struct.allocator_t, ptr %13, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !18
  %44 = load i64, ptr %15, align 8, !tbaa !16
  %45 = call noundef ptr %43(i64 noundef %44)
  store ptr %45, ptr %16, align 8, !tbaa !11
  %46 = load ptr, ptr %16, align 8, !tbaa !11
  %47 = icmp ne ptr %46, null
  br i1 %47, label %49, label %48

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

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

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

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

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

73:                                               ; preds = %72, %48
  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 %74

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

76:                                               ; preds = %29
  unreachable
}

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

declare noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE2EE6createENS1_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_eE2EEEEvPT_(ptr noundef) #1

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { 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: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIPP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @qpl_huffman_only_table_create(i32 noundef %0, i32 noundef %1, ptr %2, ptr %3, ptr noundef %4) local_unnamed_addr #1 {
  %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
  store ptr null, ptr %4, align 8, !tbaa !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)
  %.not22 = icmp eq ptr %11, null
  br i1 %.not22, label %18, label %12

12:                                               ; preds = %7
  tail call void @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE2EEC2Ev(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_eE2EE6createENS1_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)
  %.not23 = icmp eq i32 %15, 0
  br i1 %.not23, label %17, label %16

16:                                               ; preds = %12
  tail call void @_ZSt10destroy_atIN3qpl2ml11compression15huffman_table_tILNS2_23compression_algorithm_eE2EEEEvPT_(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: mustprogress nounwind uwtable
declare dso_local void @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE2EEC2Ev(ptr noundef nonnull align 8 dereferenceable(72)) unnamed_addr #2 align 2

declare noundef i32 @_ZN3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE2EE6createENS1_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_eE2EEEEvPT_(ptr noundef) local_unnamed_addr #0

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 = { 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