; LLVM IR from intel/qpl :: sources/c_api/serialization (huffman_table_serialization)

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

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

21:                                               ; preds = %4
  %22 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %22, ptr %5, align 4
  store i32 1, ptr %10, align 4
  br label %24

23:                                               ; preds = %4
  store i32 0, ptr %10, align 4
  br label %24

24:                                               ; preds = %23, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %25 = load i32, ptr %10, align 4
  switch i32 %25, label %70 [
    i32 0, label %26
    i32 1, label %68
  ]

26:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIPmJEEEjT_DpT0_(ptr noundef %27) #4
  store i32 %28, ptr %11, align 4, !tbaa !9
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %33

31:                                               ; preds = %26
  %32 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %32, ptr %5, align 4
  store i32 1, ptr %10, align 4
  br label %34

33:                                               ; preds = %26
  store i32 0, ptr %10, align 4
  br label %34

34:                                               ; preds = %33, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %35 = load i32, ptr %10, align 4
  switch i32 %35, label %70 [
    i32 0, label %36
    i32 1, label %68
  ]

36:                                               ; preds = %34
  %37 = getelementptr inbounds %struct.serialization_options_t, ptr %6, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = icmp ne i32 %38, 1
  br i1 %39, label %40, label %41

40:                                               ; preds = %36
  store i32 52, ptr %5, align 4
  br label %68

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %42, ptr %12, align 8, !tbaa !5
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.qpl::ml::compression::huffman_table_meta_t", ptr %43, i32 0, i32 2
  %45 = load i8, ptr %44, align 4, !tbaa !15
  %46 = icmp ne i8 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %41
  store i32 52, ptr %5, align 4
  store i32 1, ptr %10, align 4
  br label %67

48:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store i64 0, ptr %13, align 8, !tbaa !21
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  call void @_ZN3qpl2ml13serialization13get_meta_sizeERKNS0_11compression20huffman_table_meta_tEPm(ptr noundef nonnull align 4 dereferenceable(16) %49, ptr noundef %13)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !21
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.qpl::ml::compression::huffman_table_meta_t", ptr %50, i32 0, i32 4
  %52 = load i8, ptr %51, align 2, !tbaa !22
  switch i8 %52, label %59 [
    i8 1, label %53
    i8 2, label %56
  ]

53:                                               ; preds = %48
  %54 = load i64, ptr %14, align 8, !tbaa !21
  %55 = add i64 %54, 3904
  store i64 %55, ptr %14, align 8, !tbaa !21
  br label %62

56:                                               ; preds = %48
  %57 = load i64, ptr %14, align 8, !tbaa !21
  %58 = add i64 %57, 27584
  store i64 %58, ptr %14, align 8, !tbaa !21
  br label %62

59:                                               ; preds = %48
  %60 = load i64, ptr %14, align 8, !tbaa !21
  %61 = add i64 %60, 31488
  store i64 %61, ptr %14, align 8, !tbaa !21
  br label %62

62:                                               ; preds = %59, %56, %53
  %63 = load i64, ptr %13, align 8, !tbaa !21
  %64 = load i64, ptr %14, align 8, !tbaa !21
  %65 = add i64 %63, %64
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %65, ptr %66, align 8, !tbaa !21
  store i32 0, ptr %5, align 4
  store i32 1, ptr %10, 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 %67

67:                                               ; preds = %62, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %68

68:                                               ; preds = %67, %40, %34, %24
  %69 = load i32, ptr %5, align 4
  ret i32 %69

70:                                               ; preds = %34, %24
  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_nullptrIP17qpl_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 noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIPmJEEEjT_DpT0_(ptr noundef) #2

declare void @_ZN3qpl2ml13serialization13get_meta_sizeERKNS0_11compression20huffman_table_meta_tEPm(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef) #3

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 = { "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 0}
!12 = !{!"_ZTS23serialization_options_t", !13, i64 0, !14, i64 8}
!13 = !{!"_ZTS26qpl_serialization_format_e", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !17, i64 8}
!16 = !{!"_ZTSN3qpl2ml11compression20huffman_table_meta_tE", !7, i64 0, !10, i64 4, !17, i64 8, !18, i64 9, !19, i64 10, !20, i64 11, !10, i64 12}
!17 = !{!"_ZTSN3qpl2ml11compression23compression_algorithm_eE", !7, i64 0}
!18 = !{!"_ZTSN3qpl2ml11compression15table_version_eE", !7, i64 0}
!19 = !{!"_ZTSN3qpl2ml11compression20huffman_table_type_eE", !7, i64 0}
!20 = !{!"_ZTSN3qpl2ml16execution_path_tE", !7, i64 0}
!21 = !{!14, !14, i64 0}
!22 = !{!16, !19, i64 10}


; 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_huffman_table_get_serialized_size(ptr noundef %0, i32 %1, i64 %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca i64, align 8
  %6 = tail call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef %0) #4
  %.not.not = icmp eq i32 %6, 0
  br i1 %.not.not, label %7, label %18

7:                                                ; preds = %4
  %8 = tail call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIPmJEEEjT_DpT0_(ptr noundef %3) #4
  %.not21.not = icmp eq i32 %8, 0
  br i1 %.not21.not, label %9, label %18

9:                                                ; preds = %7
  %.not22 = icmp eq i32 %1, 1
  br i1 %.not22, label %10, label %18

10:                                               ; preds = %9
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i8, ptr %11, align 4, !tbaa !5
  %.not23 = icmp eq i8 %12, 0
  br i1 %.not23, label %13, label %18

13:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store i64 0, ptr %5, align 8, !tbaa !14
  call void @_ZN3qpl2ml13serialization13get_meta_sizeERKNS0_11compression20huffman_table_meta_tEPm(ptr noundef nonnull align 4 dereferenceable(16) %0, ptr noundef nonnull %5)
  %14 = getelementptr inbounds i8, ptr %0, i64 10
  %15 = load i8, ptr %14, align 2, !tbaa !16
  %switch.selectcmp = icmp eq i8 %15, 2
  %switch.select = select i1 %switch.selectcmp, i64 27584, i64 31488
  %switch.selectcmp24 = icmp eq i8 %15, 1
  %switch.select25 = select i1 %switch.selectcmp24, i64 3904, i64 %switch.select
  %16 = load i64, ptr %5, align 8, !tbaa !14
  %17 = add i64 %switch.select25, %16
  store i64 %17, ptr %3, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br label %18

18:                                               ; preds = %7, %4, %13, %10, %9
  %.3 = phi i32 [ %6, %4 ], [ %8, %7 ], [ 52, %9 ], [ 0, %13 ], [ 52, %10 ]
  ret i32 %.3
}

; Function Attrs: mustprogress 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_nullptrIP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIPmJEEEjT_DpT0_(ptr noundef) local_unnamed_addr #2

declare void @_ZN3qpl2ml13serialization13get_meta_sizeERKNS0_11compression20huffman_table_meta_tEPm(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef) local_unnamed_addr #3

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 = { mustprogress 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 = { "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, !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}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!6, !12, i64 10}


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