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

; 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::deflate_state" = type { %"class.qpl::ml::compression::compression_stream.base", ptr, ptr, %"class.qpl::ml::compression::huffman_table_icf", %struct.deflate_hash_table_t, %"class.qpl::ml::compression::index_table_t", i8, i8, ptr, i8, ptr, i32, i32, i32, i8, ptr, ptr }
%"class.qpl::ml::compression::compression_stream.base" = type <{ ptr, %"struct.qpl::ml::util::checksum_accumulator", i8, i8, %"struct.qpl::ml::compression::chunk_type", i32, i32 }>
%"struct.qpl::ml::util::checksum_accumulator" = type { i32, i32 }
%"struct.qpl::ml::compression::chunk_type" = type { i8, i8 }
%"class.qpl::ml::compression::huffman_table_icf" = type { ptr, i32, i32 }
%struct.deflate_hash_table_t = type { ptr, ptr, i32, i32, i32, i32, i32 }
%"class.qpl::ml::compression::index_table_t" = type <{ ptr, i32, i32, i32, [4 x i8] }>
%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 noundef i32 @_ZN3qpl2ml11compression13deflate_stateILNS0_16execution_path_tE2EE11write_bytesEPKhj(ptr noundef nonnull align 8 dereferenceable(192) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %8 = load ptr, ptr %5, align 8
  %9 = getelementptr inbounds %"class.qpl::ml::compression::deflate_state", ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.isal_zstream, ptr %10, i32 0, i32 4
  %12 = load i32, ptr %11, align 8, !tbaa !24
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = icmp ult i32 %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store i32 2, ptr %4, align 4
  br label %45

16:                                               ; preds = %3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %18, i64 %20
  %22 = getelementptr inbounds %"class.qpl::ml::compression::deflate_state", ptr %8, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct.isal_zstream, ptr %23, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !31
  call void @_ZN3qpl7core_sw4util4copyIPKhPhEEvT_S6_T0_(ptr noundef %17, ptr noundef %21, ptr noundef %25) #2
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = getelementptr inbounds %"class.qpl::ml::compression::deflate_state", ptr %8, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = getelementptr inbounds %struct.isal_zstream, ptr %28, i32 0, i32 4
  %30 = load i32, ptr %29, align 8, !tbaa !24
  %31 = sub i32 %30, %26
  store i32 %31, ptr %29, align 8, !tbaa !24
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = getelementptr inbounds %"class.qpl::ml::compression::deflate_state", ptr %8, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds %struct.isal_zstream, ptr %34, i32 0, i32 5
  %36 = load i32, ptr %35, align 4, !tbaa !32
  %37 = add i32 %36, %32
  store i32 %37, ptr %35, align 4, !tbaa !32
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = getelementptr inbounds %"class.qpl::ml::compression::deflate_state", ptr %8, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = getelementptr inbounds %struct.isal_zstream, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !31
  %43 = zext i32 %38 to i64
  %44 = getelementptr inbounds i8, ptr %42, i64 %43
  store ptr %44, ptr %41, align 8, !tbaa !31
  store i32 0, ptr %4, align 4
  br label %45

45:                                               ; preds = %16, %15
  %46 = load i32, ptr %4, align 4
  ret i32 %46
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qpl7core_sw4util4copyIPKhPhEEvT_S6_T0_(ptr noundef, ptr noundef, ptr noundef) #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 = { 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 = { 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, !6, i64 32}
!12 = !{!"_ZTSN3qpl2ml11compression13deflate_stateILNS0_16execution_path_tE2EEE", !13, i64 0, !6, i64 32, !6, i64 40, !19, i64 48, !20, i64 64, !21, i64 104, !22, i64 128, !23, i64 129, !6, i64 136, !18, i64 144, !6, i64 152, !10, i64 160, !10, i64 164, !10, i64 168, !18, i64 172, !6, i64 176, !6, i64 184}
!13 = !{!"_ZTSN3qpl2ml11compression18compression_streamE", !14, i64 8, !15, i64 16, !16, i64 17, !17, i64 18, !10, i64 20, !10, i64 24}
!14 = !{!"_ZTSN3qpl2ml4util20checksum_accumulatorE", !10, i64 0, !10, i64 4}
!15 = !{!"_ZTSN3qpl2ml11compression18compression_mode_tE", !7, i64 0}
!16 = !{!"_ZTSN3qpl2ml11compression17mini_block_size_tE", !7, i64 0}
!17 = !{!"_ZTSN3qpl2ml11compression10chunk_typeE", !18, i64 0, !18, i64 1}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"_ZTSN3qpl2ml11compression17huffman_table_icfE", !6, i64 0, !10, i64 8, !10, i64 12}
!20 = !{!"_ZTS20deflate_hash_table_t", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32}
!21 = !{!"_ZTSN3qpl2ml11compression13index_table_tE", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!22 = !{!"_ZTSN3qpl2ml11compression19compression_level_tE", !7, i64 0}
!23 = !{!"_ZTSN3qpl2ml11compression20dictionary_support_tE", !7, i64 0}
!24 = !{!25, !10, i64 24}
!25 = !{!"_ZTS12isal_zstream", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !10, i64 24, !10, i64 28, !6, i64 32, !10, i64 40, !10, i64 44, !6, i64 48, !26, i64 56, !26, i64 58, !26, i64 60, !26, i64 62, !27, i64 64}
!26 = !{!"short", !7, i64 0}
!27 = !{!"_ZTS11isal_zstate", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !28, i64 20, !29, i64 24, !10, i64 64, !7, i64 68, !7, i64 69, !7, i64 70, !7, i64 71, !26, i64 72, !10, i64 76, !7, i64 80, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !7, i64 112, !7, i64 65936}
!28 = !{!"_ZTS17isal_zstate_state", !7, i64 0}
!29 = !{!"_ZTS7BitBuf2", !30, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!30 = !{!"long", !7, i64 0}
!31 = !{!25, !6, i64 16}
!32 = !{!25, !10, i64 28}


; 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 noundef range(i32 0, 3) i32 @_ZN3qpl2ml11compression13deflate_stateILNS0_16execution_path_tE2EE11write_bytesEPKhj(ptr nocapture noundef nonnull readonly align 8 dereferenceable(192) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 24
  %7 = load i32, ptr %6, align 8, !tbaa !22
  %8 = icmp ult i32 %7, %2
  br i1 %8, label %24, label %9

9:                                                ; preds = %3
  %10 = zext i32 %2 to i64
  %11 = getelementptr inbounds i8, ptr %1, i64 %10
  %12 = getelementptr inbounds i8, ptr %5, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !29
  tail call void @_ZN3qpl7core_sw4util4copyIPKhPhEEvT_S6_T0_(ptr noundef %1, ptr noundef %11, ptr noundef %13) #2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 24
  %16 = load i32, ptr %15, align 8, !tbaa !22
  %17 = sub i32 %16, %2
  store i32 %17, ptr %15, align 8, !tbaa !22
  %18 = getelementptr inbounds i8, ptr %14, i64 28
  %19 = load i32, ptr %18, align 4, !tbaa !30
  %20 = add i32 %19, %2
  store i32 %20, ptr %18, align 4, !tbaa !30
  %21 = getelementptr inbounds i8, ptr %14, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !29
  %23 = getelementptr inbounds i8, ptr %22, i64 %10
  store ptr %23, ptr %21, align 8, !tbaa !29
  br label %24

24:                                               ; preds = %3, %9
  %.0 = phi i32 [ 0, %9 ], [ 2, %3 ]
  ret i32 %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qpl7core_sw4util4copyIPKhPhEEvT_S6_T0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 = { 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 = { 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, !16, i64 32}
!6 = !{!"_ZTSN3qpl2ml11compression13deflate_stateILNS0_16execution_path_tE2EEE", !7, i64 0, !16, i64 32, !16, i64 40, !17, i64 48, !18, i64 64, !19, i64 104, !20, i64 128, !21, i64 129, !16, i64 136, !15, i64 144, !16, i64 152, !9, i64 160, !9, i64 164, !9, i64 168, !15, i64 172, !16, i64 176, !16, i64 184}
!7 = !{!"_ZTSN3qpl2ml11compression18compression_streamE", !8, i64 8, !12, i64 16, !13, i64 17, !14, i64 18, !9, i64 20, !9, i64 24}
!8 = !{!"_ZTSN3qpl2ml4util20checksum_accumulatorE", !9, i64 0, !9, i64 4}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTSN3qpl2ml11compression18compression_mode_tE", !10, i64 0}
!13 = !{!"_ZTSN3qpl2ml11compression17mini_block_size_tE", !10, i64 0}
!14 = !{!"_ZTSN3qpl2ml11compression10chunk_typeE", !15, i64 0, !15, i64 1}
!15 = !{!"bool", !10, i64 0}
!16 = !{!"any pointer", !10, i64 0}
!17 = !{!"_ZTSN3qpl2ml11compression17huffman_table_icfE", !16, i64 0, !9, i64 8, !9, i64 12}
!18 = !{!"_ZTS20deflate_hash_table_t", !16, i64 0, !16, i64 8, !9, i64 16, !9, i64 20, !9, i64 24, !9, i64 28, !9, i64 32}
!19 = !{!"_ZTSN3qpl2ml11compression13index_table_tE", !16, i64 0, !9, i64 8, !9, i64 12, !9, i64 16}
!20 = !{!"_ZTSN3qpl2ml11compression19compression_level_tE", !10, i64 0}
!21 = !{!"_ZTSN3qpl2ml11compression20dictionary_support_tE", !10, i64 0}
!22 = !{!23, !9, i64 24}
!23 = !{!"_ZTS12isal_zstream", !16, i64 0, !9, i64 8, !9, i64 12, !16, i64 16, !9, i64 24, !9, i64 28, !16, i64 32, !9, i64 40, !9, i64 44, !16, i64 48, !24, i64 56, !24, i64 58, !24, i64 60, !24, i64 62, !25, i64 64}
!24 = !{!"short", !10, i64 0}
!25 = !{!"_ZTS11isal_zstate", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !26, i64 20, !27, i64 24, !9, i64 64, !10, i64 68, !10, i64 69, !10, i64 70, !10, i64 71, !24, i64 72, !9, i64 76, !10, i64 80, !9, i64 96, !9, i64 100, !9, i64 104, !9, i64 108, !10, i64 112, !10, i64 65936}
!26 = !{!"_ZTS17isal_zstate_state", !10, i64 0}
!27 = !{!"_ZTS7BitBuf2", !28, i64 0, !9, i64 8, !16, i64 16, !16, i64 24, !16, i64 32}
!28 = !{!"long", !10, i64 0}
!29 = !{!23, !16, i64 16}
!30 = !{!23, !9, i64 28}


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