; 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: 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 @_ZN3qpl2ml11compression28convert_output_to_big_endianERNS1_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 i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i16, align 2
  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
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %9, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.isal_zstream, ptr %11, i32 0, i32 5
  %13 = load i32, ptr %12, align 4, !tbaa !16
  %14 = lshr i32 %13, 1
  store i32 %14, ptr %5, align 4, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.isal_zstream, ptr %17, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !24
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.isal_zstream, ptr %22, i32 0, i32 5
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %25 = zext i32 %24 to i64
  %26 = sub i64 0, %25
  %27 = getelementptr inbounds i8, ptr %19, i64 %26
  store ptr %27, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !23
  br label %28

28:                                               ; preds = %45, %2
  %29 = load i32, ptr %7, align 4, !tbaa !23
  %30 = load i32, ptr %5, align 4, !tbaa !23
  %31 = icmp ult i32 %29, %30
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %28
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !23
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds i16, ptr %34, i64 %36
  %38 = load i16, ptr %37, align 2, !tbaa !25
  %39 = invoke noundef zeroext i16 @_ZL12reverse_bitstj(i16 noundef zeroext %38, i32 noundef 16)
          to label %40 unwind label %71

40:                                               ; preds = %33
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !23
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds i16, ptr %41, i64 %43
  store i16 %39, ptr %44, align 2, !tbaa !25
  br label %45

45:                                               ; preds = %40
  %46 = load i32, ptr %7, align 4, !tbaa !23
  %47 = add i32 %46, 1
  store i32 %47, ptr %7, align 4, !tbaa !23
  br label %28, !llvm.loop !26

48:                                               ; preds = %32
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.qpl::ml::compression::huffman_only_state", ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.isal_zstream, ptr %51, i32 0, i32 5
  %53 = load i32, ptr %52, align 4, !tbaa !16
  %54 = urem i32 %53, 2
  %55 = icmp eq i32 %54, 1
  br i1 %55, label %56, label %70

56:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #4
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load i32, ptr %5, align 4, !tbaa !23
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds i16, ptr %57, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !28
  %62 = zext i8 %61 to i16
  store i16 %62, ptr %8, align 2, !tbaa !25
  %63 = load i16, ptr %8, align 2, !tbaa !25
  %64 = invoke noundef zeroext i16 @_ZL12reverse_bitstj(i16 noundef zeroext %63, i32 noundef 16)
          to label %65 unwind label %71

65:                                               ; preds = %56
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !23
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds i16, ptr %66, i64 %68
  store i16 %64, ptr %69, align 2, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #4
  br label %70

70:                                               ; preds = %65, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 0

71:                                               ; preds = %56, %33
  %72 = landingpad { ptr, i32 }
          catch ptr null
  %73 = extractvalue { ptr, i32 } %72, 0
  call void @__clang_call_terminate(ptr %73) #5
  unreachable
}

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

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 = { 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 #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, !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, !12, i64 28}
!17 = !{!"_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, !18, i64 56, !18, i64 58, !18, i64 60, !18, i64 62, !19, i64 64}
!18 = !{!"short", !7, i64 0}
!19 = !{!"_ZTS11isal_zstate", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !20, i64 20, !21, i64 24, !12, i64 64, !7, i64 68, !7, i64 69, !7, i64 70, !7, i64 71, !18, 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}
!20 = !{!"_ZTS17isal_zstate_state", !7, i64 0}
!21 = !{!"_ZTS7BitBuf2", !22, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!22 = !{!"long", !7, i64 0}
!23 = !{!12, !12, i64 0}
!24 = !{!17, !6, i64 16}
!25 = !{!18, !18, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!7, !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: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml11compression28convert_output_to_big_endianERNS1_18huffman_only_stateILNS0_16execution_path_tE2EEERNS1_19compression_state_tE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(56) %0, ptr nocapture noundef nonnull readnone align 1 dereferenceable(1) %1) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 28
  %6 = load i32, ptr %5, align 4, !tbaa !15
  %7 = lshr i32 %6, 1
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !22
  %10 = zext i32 %6 to i64
  %11 = sub nsw i64 0, %10
  %12 = getelementptr inbounds i8, ptr %9, i64 %11
  %.not17 = icmp ult i32 %6, 2
  br i1 %.not17, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %7 to i64
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load ptr, ptr %3, align 8, !tbaa !5
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.pre, i64 28
  %.pre19 = load i32, ptr %.phi.trans.insert, align 4, !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %13 = phi i32 [ %.pre19, %._crit_edge.loopexit ], [ %6, %2 ]
  %14 = and i32 %13, 1
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %24, label %18

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %15 = getelementptr inbounds i16, ptr %12, i64 %indvars.iv
  %16 = load i16, ptr %15, align 2, !tbaa !23
  %17 = tail call noundef zeroext i16 @_ZL12reverse_bitstj(i16 noundef zeroext %16, i32 noundef 16)
  store i16 %17, ptr %15, align 2, !tbaa !23
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !24

18:                                               ; preds = %._crit_edge
  %19 = zext nneg i32 %7 to i64
  %20 = getelementptr inbounds i16, ptr %12, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !26
  %22 = zext i8 %21 to i16
  %23 = tail call noundef zeroext i16 @_ZL12reverse_bitstj(i16 noundef zeroext %22, i32 noundef 16)
  store i16 %23, ptr %20, align 2, !tbaa !23
  br label %24

24:                                               ; preds = %18, %._crit_edge
  ret i32 0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i16 @_ZL12reverse_bitstj(i16 noundef zeroext, i32 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" }

!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, !8, i64 28}
!16 = !{!"_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, !17, i64 56, !17, i64 58, !17, i64 60, !17, i64 62, !18, i64 64}
!17 = !{!"short", !9, i64 0}
!18 = !{!"_ZTS11isal_zstate", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !8, i64 16, !19, i64 20, !20, i64 24, !8, i64 64, !9, i64 68, !9, i64 69, !9, i64 70, !9, i64 71, !17, 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}
!19 = !{!"_ZTS17isal_zstate_state", !9, i64 0}
!20 = !{!"_ZTS7BitBuf2", !21, i64 0, !8, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!21 = !{!"long", !9, i64 0}
!22 = !{!16, !11, i64 16}
!23 = !{!17, !17, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!9, !9, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass