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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qpl2ml11compression12update_stateERNS1_18huffman_only_stateILNS0_16execution_path_tE2EEEPhS6_S6_(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.isal_zstream, ptr %12, i32 0, i32 14
  store ptr %13, ptr %9, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = ptrtoint ptr %14 to i64
  %17 = ptrtoint ptr %15 to i64
  %18 = sub i64 %16, %17
  %19 = icmp sgt i64 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %4
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.isal_zstate, ptr %21, i32 0, i32 11
  store i8 1, ptr %22, align 1, !tbaa !16
  br label %23

23:                                               ; preds = %20, %4
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.isal_zstream, ptr %27, i32 0, i32 0
  store ptr %24, ptr %28, align 8, !tbaa !22
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = invoke noundef i64 @_ZSt8distanceIPhENSt15iterator_traitsIT_E15difference_typeES2_S2_(ptr noundef %29, ptr noundef %30)
          to label %32 unwind label %50

32:                                               ; preds = %23
  %33 = trunc i64 %31 to i32
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.isal_zstream, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 4, !tbaa !24
  %39 = add i32 %38, %33
  store i32 %39, ptr %37, align 4, !tbaa !24
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = invoke noundef i64 @_ZSt8distanceIPhENSt15iterator_traitsIT_E15difference_typeES2_S2_(ptr noundef %40, ptr noundef %41)
          to label %43 unwind label %50

43:                                               ; preds = %32
  %44 = trunc i64 %42 to i32
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.isal_zstream, ptr %47, i32 0, i32 1
  store i32 %44, ptr %48, align 8, !tbaa !25
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN3qpl2ml11compression18huffman_only_stateILNS0_16execution_path_tE2EE15dump_bit_bufferEv(ptr noundef nonnull align 8 dereferenceable(56) %49) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret void

50:                                               ; preds = %32, %23
  %51 = landingpad { ptr, i32 }
          catch ptr null
  %52 = extractvalue { ptr, i32 } %51, 0
  call void @__clang_call_terminate(ptr %52) #6
  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 uwtable
declare dso_local noundef i64 @_ZSt8distanceIPhENSt15iterator_traitsIT_E15difference_typeES2_S2_(ptr noundef, ptr noundef) #2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: nounwind
declare void @_ZN3qpl2ml11compression18huffman_only_stateILNS0_16execution_path_tE2EE15dump_bit_bufferEv(ptr noundef nonnull align 8 dereferenceable(56)) #4

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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 #4 = { nounwind "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 = !{!17, !7, i64 71}
!17 = !{!"_ZTS11isal_zstate", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !18, i64 20, !19, i64 24, !12, i64 64, !7, i64 68, !7, i64 69, !7, i64 70, !7, i64 71, !21, 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}
!18 = !{!"_ZTS17isal_zstate_state", !7, i64 0}
!19 = !{!"_ZTS7BitBuf2", !20, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!20 = !{!"long", !7, i64 0}
!21 = !{!"short", !7, i64 0}
!22 = !{!23, !6, i64 0}
!23 = !{!"_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, !21, i64 56, !21, i64 58, !21, i64 60, !21, i64 62, !17, i64 64}
!24 = !{!23, !12, i64 12}
!25 = !{!23, !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 nounwind uwtable
define dso_local void @_ZN3qpl2ml11compression12update_stateERNS1_18huffman_only_stateILNS0_16execution_path_tE2EEEPhS6_S6_(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = ptrtoint ptr %2 to i64
  %7 = ptrtoint ptr %1 to i64
  %8 = sub i64 %6, %7
  %9 = icmp sgt i64 %8, 0
  %.pre = load ptr, ptr %5, align 8, !tbaa !5
  br i1 %9, label %10, label %12

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %.pre, i64 135
  store i8 1, ptr %11, align 1, !tbaa !15
  br label %12

12:                                               ; preds = %10, %4
  store ptr %2, ptr %.pre, align 8, !tbaa !21
  %13 = invoke noundef i64 @_ZSt8distanceIPhENSt15iterator_traitsIT_E15difference_typeES2_S2_(ptr noundef %1, ptr noundef %2)
          to label %14 unwind label %25

14:                                               ; preds = %12
  %15 = trunc i64 %13 to i32
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 12
  %18 = load i32, ptr %17, align 4, !tbaa !23
  %19 = add i32 %18, %15
  store i32 %19, ptr %17, align 4, !tbaa !23
  %20 = invoke noundef i64 @_ZSt8distanceIPhENSt15iterator_traitsIT_E15difference_typeES2_S2_(ptr noundef %2, ptr noundef %3)
          to label %21 unwind label %25

21:                                               ; preds = %14
  %22 = trunc i64 %20 to i32
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  store i32 %22, ptr %24, align 8, !tbaa !24
  tail call void @_ZN3qpl2ml11compression18huffman_only_stateILNS0_16execution_path_tE2EE15dump_bit_bufferEv(ptr noundef nonnull align 8 dereferenceable(56) %0) #4
  ret void

25:                                               ; preds = %14, %12
  %26 = landingpad { ptr, i32 }
          catch ptr null
  %27 = extractvalue { ptr, i32 } %26, 0
  tail call void @__clang_call_terminate(ptr %27) #5
  unreachable
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_ZSt8distanceIPhENSt15iterator_traitsIT_E15difference_typeES2_S2_(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: nounwind
declare void @_ZN3qpl2ml11compression18huffman_only_stateILNS0_16execution_path_tE2EE15dump_bit_bufferEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #3

attributes #0 = { 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 = { inlinehint 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 = { 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 #3 = { nounwind "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, !11, i64 8}
!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 = !{!16, !9, i64 71}
!16 = !{!"_ZTS11isal_zstate", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !8, i64 16, !17, i64 20, !18, i64 24, !8, i64 64, !9, i64 68, !9, i64 69, !9, i64 70, !9, i64 71, !20, 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}
!17 = !{!"_ZTS17isal_zstate_state", !9, i64 0}
!18 = !{!"_ZTS7BitBuf2", !19, i64 0, !8, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!19 = !{!"long", !9, i64 0}
!20 = !{!"short", !9, i64 0}
!21 = !{!22, !11, i64 0}
!22 = !{!"_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, !20, i64 56, !20, i64 58, !20, i64 60, !20, i64 62, !16, i64 64}
!23 = !{!22, !8, i64 12}
!24 = !{!22, !8, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass