; LLVM IR from intel/qpl :: sources/middle-layer/compression/huffman_only (huffman_only_units)

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

%"class.qpl::ml::compression::huffman_only_state" = type { %"struct.qpl::ml::util::checksum_accumulator", ptr, ptr, ptr, i8, i32, i8, i8, i8, i8, ptr }
%"struct.qpl::ml::util::checksum_accumulator" = type { i32, i32 }
%struct.isal_zstream = type { ptr, i32, i32, ptr, i32, i32, ptr, i32, i32, ptr, i16, i16, i16, i16, %struct.isal_zstate }
%struct.isal_zstate = type { i32, i32, i32, i32, i32, i32, %struct.BitBuf2, i32, i8, i8, i8, i8, i16, i32, [16 x i8], i32, i32, i32, i32, [65824 x i8], [8192 x i16] }
%struct.BitBuf2 = type { i64, i32, ptr, ptr, ptr }
%struct.isal_huff_histogram = type { [286 x i64], [30 x i64], [8192 x i16] }

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml11compression33huffman_only_create_huffman_tableERNS1_18huffman_only_stateILNS0_16execution_path_tE2EEERNS1_19compression_state_tE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 1 dereferenceable(1) %1) #2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  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 8, ptr %5) #5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.isal_zstream, ptr %10, i32 0, i32 14
  store ptr %11, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %12, i32 0, i32 7
  %14 = load i8, ptr %13, align 1, !tbaa !16
  %15 = zext i8 %14 to i32
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %61

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.isal_zstate, ptr %18, i32 0, i32 19
  %20 = getelementptr inbounds [65824 x i8], ptr %19, i64 0, i64 0
  store ptr %20, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.isal_zstate, ptr %21, i32 0, i32 19
  %23 = getelementptr inbounds [65824 x i8], ptr %22, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %23, i8 0, i64 18912, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !17
  br label %24

24:                                               ; preds = %49, %17
  %25 = load i32, ptr %7, align 4, !tbaa !17
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.isal_zstream, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 8, !tbaa !18
  %31 = icmp ult i32 %25, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %52

33:                                               ; preds = %24
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.isal_huff_histogram, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.isal_zstream, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !25
  %41 = load i32, ptr %7, align 4, !tbaa !17
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !26
  %45 = zext i8 %44 to i64
  %46 = getelementptr inbounds [286 x i64], ptr %35, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !27
  %48 = add i64 %47, 1
  store i64 %48, ptr %46, align 8, !tbaa !27
  br label %49

49:                                               ; preds = %33
  %50 = load i32, ptr %7, align 4, !tbaa !17
  %51 = add i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !17
  br label %24, !llvm.loop !28

52:                                               ; preds = %32
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.isal_zstream, ptr %55, i32 0, i32 6
  %57 = load ptr, ptr %56, align 8, !tbaa !30
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = invoke i32 @qpl_isal_create_hufftables(ptr noundef %57, ptr noundef %58)
          to label %60 unwind label %63

60:                                               ; preds = %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %61

61:                                               ; preds = %60, %2
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  store i8 3, ptr %62, align 1, !tbaa !31
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret i32 0

63:                                               ; preds = %52
  %64 = landingpad { ptr, i32 }
          catch ptr null
  %65 = extractvalue { ptr, i32 } %64, 0
  call void @__clang_call_terminate(ptr %65) #6
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare i32 @qpl_isal_create_hufftables(ptr noundef, ptr noundef) #4

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 = { 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: write) }
attributes #4 = { "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 = { nounwind }
attributes #6 = { 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, !6, i64 8}
!10 = !{!"_ZTSN3qpl2ml11compression18huffman_only_stateILNS0_16execution_path_tE2EEE", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !12, i64 36, !14, i64 40, !15, i64 41, !7, i64 42, !14, i64 43, !6, i64 48}
!11 = !{!"_ZTSN3qpl2ml4util20checksum_accumulatorE", !12, i64 0, !12, i64 4}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTSN3qpl2ml11compression12endianness_tE", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"_ZTSN3qpl2ml11compression18compression_mode_tE", !7, i64 0}
!16 = !{!10, !15, i64 41}
!17 = !{!12, !12, i64 0}
!18 = !{!19, !12, i64 8}
!19 = !{!"_ZTS12isal_zstream", !6, i64 0, !12, i64 8, !12, i64 12, !6, i64 16, !12, i64 24, !12, i64 28, !6, i64 32, !12, i64 40, !12, i64 44, !6, i64 48, !20, i64 56, !20, i64 58, !20, i64 60, !20, i64 62, !21, i64 64}
!20 = !{!"short", !7, i64 0}
!21 = !{!"_ZTS11isal_zstate", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !22, i64 20, !23, i64 24, !12, i64 64, !7, i64 68, !7, i64 69, !7, i64 70, !7, i64 71, !20, i64 72, !12, i64 76, !7, i64 80, !12, i64 96, !12, i64 100, !12, i64 104, !12, i64 108, !7, i64 112, !7, i64 65936}
!22 = !{!"_ZTS17isal_zstate_state", !7, i64 0}
!23 = !{!"_ZTS7BitBuf2", !24, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!24 = !{!"long", !7, i64 0}
!25 = !{!19, !6, i64 0}
!26 = !{!7, !7, i64 0}
!27 = !{!24, !24, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = !{!19, !6, i64 32}
!31 = !{!32, !32, i64 0}
!32 = !{!"_ZTSN3qpl2ml11compression19compression_state_tE", !7, i64 0}


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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml11compression33huffman_only_create_huffman_tableERNS1_18huffman_only_stateILNS0_16execution_path_tE2EEERNS1_19compression_state_tE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(56) %0, ptr nocapture noundef nonnull writeonly align 1 dereferenceable(1) %1) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 41
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = icmp eq i8 %4, 0
  br i1 %5, label %6, label %49

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %8, i64 176
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(18912) %9, i8 0, i64 18912, i1 false)
  %10 = load ptr, ptr %7, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !16
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %13 = load ptr, ptr %10, align 8, !tbaa !23
  %wide.trip.count = zext i32 %12 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %14 = icmp ult i32 %12, 4
  br i1 %14, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %24

._crit_edge.loopexit.unr-lcssa:                   ; preds = %24, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %24 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %15 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv.epil
  %16 = load i8, ptr %15, align 1, !tbaa !24
  %17 = zext i8 %16 to i64
  %18 = getelementptr inbounds [286 x i64], ptr %9, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !25
  %20 = add i64 %19, 1
  store i64 %20, ptr %18, align 8, !tbaa !25
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !26

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %6
  %21 = getelementptr inbounds i8, ptr %10, i64 32
  %22 = load ptr, ptr %21, align 8, !tbaa !28
  %23 = invoke i32 @qpl_isal_create_hufftables(ptr noundef %22, ptr noundef nonnull %9)
          to label %49 unwind label %50

24:                                               ; preds = %24, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %24 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %24 ]
  %25 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv
  %26 = load i8, ptr %25, align 1, !tbaa !24
  %27 = zext i8 %26 to i64
  %28 = getelementptr inbounds [286 x i64], ptr %9, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !25
  %30 = add i64 %29, 1
  store i64 %30, ptr %28, align 8, !tbaa !25
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %31 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv.next
  %32 = load i8, ptr %31, align 1, !tbaa !24
  %33 = zext i8 %32 to i64
  %34 = getelementptr inbounds [286 x i64], ptr %9, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !25
  %36 = add i64 %35, 1
  store i64 %36, ptr %34, align 8, !tbaa !25
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %37 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv.next.1
  %38 = load i8, ptr %37, align 1, !tbaa !24
  %39 = zext i8 %38 to i64
  %40 = getelementptr inbounds [286 x i64], ptr %9, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !25
  %42 = add i64 %41, 1
  store i64 %42, ptr %40, align 8, !tbaa !25
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %43 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv.next.2
  %44 = load i8, ptr %43, align 1, !tbaa !24
  %45 = zext i8 %44 to i64
  %46 = getelementptr inbounds [286 x i64], ptr %9, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !25
  %48 = add i64 %47, 1
  store i64 %48, ptr %46, align 8, !tbaa !25
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %24, !llvm.loop !29

49:                                               ; preds = %._crit_edge, %2
  store i8 3, ptr %1, align 1, !tbaa !31
  ret i32 0

50:                                               ; preds = %._crit_edge
  %51 = landingpad { ptr, i32 }
          catch ptr null
  %52 = extractvalue { ptr, i32 } %51, 0
  tail call void @__clang_call_terminate(ptr %52) #4
  unreachable
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @qpl_isal_create_hufftables(ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { 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 #1 = { 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 nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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, !14, i64 41}
!6 = !{!"_ZTSN3qpl2ml11compression18huffman_only_stateILNS0_16execution_path_tE2EEE", !7, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !8, i64 36, !13, i64 40, !14, i64 41, !9, i64 42, !13, i64 43, !11, i64 48}
!7 = !{!"_ZTSN3qpl2ml4util20checksum_accumulatorE", !8, i64 0, !8, i64 4}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"_ZTSN3qpl2ml11compression12endianness_tE", !9, i64 0}
!13 = !{!"bool", !9, i64 0}
!14 = !{!"_ZTSN3qpl2ml11compression18compression_mode_tE", !9, i64 0}
!15 = !{!6, !11, i64 8}
!16 = !{!17, !8, i64 8}
!17 = !{!"_ZTS12isal_zstream", !11, i64 0, !8, i64 8, !8, i64 12, !11, i64 16, !8, i64 24, !8, i64 28, !11, i64 32, !8, i64 40, !8, i64 44, !11, i64 48, !18, i64 56, !18, i64 58, !18, i64 60, !18, i64 62, !19, i64 64}
!18 = !{!"short", !9, i64 0}
!19 = !{!"_ZTS11isal_zstate", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !8, i64 16, !20, i64 20, !21, i64 24, !8, i64 64, !9, i64 68, !9, i64 69, !9, i64 70, !9, i64 71, !18, i64 72, !8, i64 76, !9, i64 80, !8, i64 96, !8, i64 100, !8, i64 104, !8, i64 108, !9, i64 112, !9, i64 65936}
!20 = !{!"_ZTS17isal_zstate_state", !9, i64 0}
!21 = !{!"_ZTS7BitBuf2", !22, i64 0, !8, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!22 = !{!"long", !9, i64 0}
!23 = !{!17, !11, i64 0}
!24 = !{!9, !9, i64 0}
!25 = !{!22, !22, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.unroll.disable"}
!28 = !{!17, !11, i64 32}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}
!31 = !{!32, !32, i64 0}
!32 = !{!"_ZTSN3qpl2ml11compression19compression_state_tE", !9, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass