; LLVM IR from intel/qpl :: sources/middle-layer/compression/deflate/utils (huffman_table_utils)

; 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.std::array" = type { [30 x i32] }
%struct.huff_code = type { %union.anon.0 }
%union.anon.0 = type { %struct.anon }
%struct.anon = type { i32 }
%struct.anon.1 = type { i16, i8, i8 }

@_ZN3qpl2ml11compressionL24distance_code_extra_bitsE = external hidden constant %"struct.std::array", align 4

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i16 @_ZL12reverse_bitstj(i16 noundef zeroext, i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml11compression19set_dist_huff_codesEP9huff_codePj(ptr noundef %0, ptr noundef %1) #3 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca [16 x i32], align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 30, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 64, ptr %11) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds i32, ptr %12, i64 0
  store i32 0, ptr %13, align 4, !tbaa !9
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %31, %2
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp ule i32 %15, 15
  br i1 %16, label %17, label %34

17:                                               ; preds = %14
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = sub i32 %20, 1
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %19, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = add i32 %18, %24
  %26 = shl i32 %25, 1
  store i32 %26, ptr %5, align 4, !tbaa !9
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds [16 x i32], ptr %11, i64 0, i64 %29
  store i32 %27, ptr %30, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %17
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = add i32 %32, 1
  store i32 %33, ptr %7, align 4, !tbaa !9
  br label %14, !llvm.loop !11

34:                                               ; preds = %14
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %82, %34
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = icmp ult i32 %36, 30
  br i1 %37, label %38, label %85

38:                                               ; preds = %35
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds %struct.huff_code, ptr %39, i64 %41
  %43 = getelementptr inbounds %struct.huff_code, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.anon.1, ptr %43, i32 0, i32 2
  %45 = load i8, ptr %44, align 1, !tbaa !13
  %46 = zext i8 %45 to i32
  store i32 %46, ptr %6, align 4, !tbaa !9
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %81

49:                                               ; preds = %38
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds [16 x i32], ptr %11, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = trunc i32 %53 to i16
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = invoke noundef zeroext i16 @_ZL12reverse_bitstj(i16 noundef zeroext %54, i32 noundef %55)
          to label %57 unwind label %87

57:                                               ; preds = %49
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds %struct.huff_code, ptr %58, i64 %60
  %62 = getelementptr inbounds %struct.huff_code, ptr %61, i32 0, i32 0
  %63 = getelementptr inbounds %struct.anon.1, ptr %62, i32 0, i32 0
  store i16 %56, ptr %63, align 4, !tbaa !13
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIjLm30EEixEm(ptr noundef nonnull align 4 dereferenceable(120) @_ZN3qpl2ml11compressionL24distance_code_extra_bitsE, i64 noundef %65) #4
  %67 = load i32, ptr %66, align 4, !tbaa !9
  %68 = trunc i32 %67 to i8
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = zext i32 %70 to i64
  %72 = getelementptr inbounds %struct.huff_code, ptr %69, i64 %71
  %73 = getelementptr inbounds %struct.huff_code, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds %struct.anon.1, ptr %73, i32 0, i32 1
  store i8 %68, ptr %74, align 2, !tbaa !13
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = zext i32 %75 to i64
  %77 = getelementptr inbounds [16 x i32], ptr %11, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !9
  %79 = add i32 %78, 1
  store i32 %79, ptr %77, align 4, !tbaa !9
  %80 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %80, ptr %9, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %57, %38
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %8, align 4, !tbaa !9
  %84 = add i32 %83, 1
  store i32 %84, ptr %8, align 4, !tbaa !9
  br label %35, !llvm.loop !14

85:                                               ; preds = %35
  %86 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 64, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %86

87:                                               ; preds = %49
  %88 = landingpad { ptr, i32 }
          catch ptr null
  %89 = extractvalue { ptr, i32 } %88, 0
  call void @__clang_call_terminate(ptr %89) #5
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIjLm30EEixEm(ptr noundef nonnull align 4 dereferenceable(120), i64 noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noinline noreturn nounwind uwtable "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 = { 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 #4 = { nounwind }
attributes #5 = { noreturn 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}


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

%"struct.std::array" = type { [30 x i32] }
%struct.huff_code = type { %union.anon.0 }
%union.anon.0 = type { %struct.anon }
%struct.anon = type { i32 }

@_ZN3qpl2ml11compressionL24distance_code_extra_bitsE = external hidden constant %"struct.std::array", align 4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i16 @_ZL12reverse_bitstj(i16 noundef zeroext, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml11compression19set_dist_huff_codesEP9huff_codePj(ptr nocapture noundef %0, ptr nocapture noundef %1) local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
.preheader.preheader:
  %2 = alloca [16 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 0, ptr %3, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = shl i32 %5, 1
  %7 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 %6, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = add i32 %9, %6
  %11 = shl i32 %10, 1
  %12 = getelementptr inbounds i8, ptr %2, i64 12
  store i32 %11, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %1, i64 12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = add i32 %14, %11
  %16 = shl i32 %15, 1
  %17 = getelementptr inbounds i8, ptr %2, i64 16
  store i32 %16, ptr %17, align 16, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %1, i64 16
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add i32 %19, %16
  %21 = shl i32 %20, 1
  %22 = getelementptr inbounds i8, ptr %2, i64 20
  store i32 %21, ptr %22, align 4, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %1, i64 20
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add i32 %24, %21
  %26 = shl i32 %25, 1
  %27 = getelementptr inbounds i8, ptr %2, i64 24
  store i32 %26, ptr %27, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %1, i64 24
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add i32 %29, %26
  %31 = shl i32 %30, 1
  %32 = getelementptr inbounds i8, ptr %2, i64 28
  store i32 %31, ptr %32, align 4, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %1, i64 28
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add i32 %34, %31
  %36 = shl i32 %35, 1
  %37 = getelementptr inbounds i8, ptr %2, i64 32
  store i32 %36, ptr %37, align 16, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %1, i64 32
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = add i32 %39, %36
  %41 = shl i32 %40, 1
  %42 = getelementptr inbounds i8, ptr %2, i64 36
  store i32 %41, ptr %42, align 4, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %1, i64 36
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = add i32 %44, %41
  %46 = shl i32 %45, 1
  %47 = getelementptr inbounds i8, ptr %2, i64 40
  store i32 %46, ptr %47, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %1, i64 40
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = add i32 %49, %46
  %51 = shl i32 %50, 1
  %52 = getelementptr inbounds i8, ptr %2, i64 44
  store i32 %51, ptr %52, align 4, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %1, i64 44
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = add i32 %54, %51
  %56 = shl i32 %55, 1
  %57 = getelementptr inbounds i8, ptr %2, i64 48
  store i32 %56, ptr %57, align 16, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %1, i64 48
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = add i32 %59, %56
  %61 = shl i32 %60, 1
  %62 = getelementptr inbounds i8, ptr %2, i64 52
  store i32 %61, ptr %62, align 4, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %1, i64 52
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = add i32 %64, %61
  %66 = shl i32 %65, 1
  %67 = getelementptr inbounds i8, ptr %2, i64 56
  store i32 %66, ptr %67, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %1, i64 56
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = add i32 %69, %66
  %71 = shl i32 %70, 1
  %72 = getelementptr inbounds i8, ptr %2, i64 60
  store i32 %71, ptr %72, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %89
  %indvars.iv = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next, %89 ]
  %.02229 = phi i32 [ 0, %.preheader.preheader ], [ %.1, %89 ]
  %73 = getelementptr inbounds %struct.huff_code, ptr %0, i64 %indvars.iv
  %74 = getelementptr inbounds i8, ptr %73, i64 3
  %75 = load i8, ptr %74, align 1, !tbaa !9
  %.not = icmp eq i8 %75, 0
  br i1 %.not, label %89, label %76

76:                                               ; preds = %.preheader
  %77 = zext i8 %75 to i32
  %78 = zext i8 %75 to i64
  %79 = getelementptr inbounds [16 x i32], ptr %2, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = trunc i32 %80 to i16
  %82 = tail call noundef zeroext i16 @_ZL12reverse_bitstj(i16 noundef zeroext %81, i32 noundef %77)
  store i16 %82, ptr %73, align 4, !tbaa !9
  %83 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIjLm30EEixEm(ptr noundef nonnull align 4 dereferenceable(120) @_ZN3qpl2ml11compressionL24distance_code_extra_bitsE, i64 noundef %indvars.iv) #3
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = trunc i32 %84 to i8
  %86 = getelementptr inbounds i8, ptr %73, i64 2
  store i8 %85, ptr %86, align 2, !tbaa !9
  %87 = add i32 %80, 1
  store i32 %87, ptr %79, align 4, !tbaa !5
  %88 = trunc nuw nsw i64 %indvars.iv to i32
  br label %89

89:                                               ; preds = %.preheader, %76
  %.1 = phi i32 [ %88, %76 ], [ %.02229, %.preheader ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 30
  br i1 %exitcond.not, label %90, label %.preheader, !llvm.loop !10

90:                                               ; preds = %89
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #3
  ret i32 %.1
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIjLm30EEixEm(ptr noundef nonnull align 4 dereferenceable(120), i64 noundef) local_unnamed_addr #2 align 2

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass