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

; 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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml11compression9rl_encodeEPtjPmP7rl_code(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i16, align 2
  %11 = alloca i16, align 2
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  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 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds i16, ptr %14, i64 0
  %16 = load i16, ptr %15, align 2, !tbaa !11
  store i16 %16, ptr %10, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  store i16 0, ptr %11, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %17, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 1, ptr %13, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %44, %4
  %19 = load i32, ptr %13, align 4, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = icmp ult i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %47

23:                                               ; preds = %18
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %13, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i16, ptr %24, i64 %26
  %28 = load i16, ptr %27, align 2, !tbaa !11
  store i16 %28, ptr %11, align 2, !tbaa !11
  %29 = load i16, ptr %11, align 2, !tbaa !11
  %30 = zext i16 %29 to i32
  %31 = load i16, ptr %10, align 2, !tbaa !11
  %32 = zext i16 %31 to i32
  %33 = icmp eq i32 %30, %32
  br i1 %33, label %34, label %37

34:                                               ; preds = %23
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = add i32 %35, 1
  store i32 %36, ptr %9, align 4, !tbaa !9
  br label %44

37:                                               ; preds = %23
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = load i16, ptr %10, align 2, !tbaa !11
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = call noundef ptr @_ZN3qpl2ml11compressionL8write_rlEP7rl_codetjPm(ptr noundef %38, i16 noundef zeroext %39, i32 noundef %40, ptr noundef %41) #3
  store ptr %42, ptr %12, align 8, !tbaa !5
  %43 = load i16, ptr %11, align 2, !tbaa !11
  store i16 %43, ptr %10, align 2, !tbaa !11
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %37, %34
  %45 = load i32, ptr %13, align 4, !tbaa !9
  %46 = add i32 %45, 1
  store i32 %46, ptr %13, align 4, !tbaa !9
  br label %18, !llvm.loop !13

47:                                               ; preds = %22
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = load i16, ptr %10, align 2, !tbaa !11
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = call noundef ptr @_ZN3qpl2ml11compressionL8write_rlEP7rl_codetjPm(ptr noundef %48, i16 noundef zeroext %49, i32 noundef %50, ptr noundef %51) #3
  store ptr %52, ptr %12, align 8, !tbaa !5
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = ptrtoint ptr %53 to i64
  %56 = ptrtoint ptr %54 to i64
  %57 = sub i64 %55, %56
  %58 = sdiv exact i64 %57, 2
  %59 = trunc i64 %58 to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i32 %59
}

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

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


; 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 i32 @_ZN3qpl2ml11compression9rl_encodeEPtjPmP7rl_code(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = load i16, ptr %0, align 2, !tbaa !5
  %6 = icmp ugt i32 %1, 1
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %wide.trip.count = zext i32 %1 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %20, %4
  %.023.lcssa = phi i32 [ 1, %4 ], [ %.124, %20 ]
  %.021.lcssa = phi i16 [ %5, %4 ], [ %.122, %20 ]
  %.020.lcssa = phi ptr [ %3, %4 ], [ %.1, %20 ]
  %7 = tail call noundef ptr @_ZN3qpl2ml11compressionL8write_rlEP7rl_codetjPm(ptr noundef %.020.lcssa, i16 noundef zeroext %.021.lcssa, i32 noundef %.023.lcssa, ptr noundef %2) #2
  %8 = ptrtoint ptr %7 to i64
  %9 = ptrtoint ptr %3 to i64
  %10 = sub i64 %8, %9
  %11 = lshr exact i64 %10, 1
  %12 = trunc i64 %11 to i32
  ret i32 %12

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %20 ]
  %.02027 = phi ptr [ %3, %.lr.ph.preheader ], [ %.1, %20 ]
  %.02126 = phi i16 [ %5, %.lr.ph.preheader ], [ %.122, %20 ]
  %.02325 = phi i32 [ 1, %.lr.ph.preheader ], [ %.124, %20 ]
  %13 = getelementptr inbounds i16, ptr %0, i64 %indvars.iv
  %14 = load i16, ptr %13, align 2, !tbaa !5
  %15 = icmp eq i16 %14, %.02126
  br i1 %15, label %16, label %18

16:                                               ; preds = %.lr.ph
  %17 = add i32 %.02325, 1
  br label %20

18:                                               ; preds = %.lr.ph
  %19 = tail call noundef ptr @_ZN3qpl2ml11compressionL8write_rlEP7rl_codetjPm(ptr noundef %.02027, i16 noundef zeroext %.02126, i32 noundef %.02325, ptr noundef %2) #2
  br label %20

20:                                               ; preds = %18, %16
  %.124 = phi i32 [ %17, %16 ], [ 1, %18 ]
  %.122 = phi i16 [ %.02126, %16 ], [ %14, %18 ]
  %.1 = phi ptr [ %.02027, %16 ], [ %19, %18 ]
  %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, label %.lr.ph, !llvm.loop !9
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN3qpl2ml11compressionL8write_rlEP7rl_codetjPm(ptr noundef, i16 noundef zeroext, i32 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, !6, i64 0}
!6 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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