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

%struct.heap_tree = type { %union.anon }
%union.anon = type { [859 x i64] }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml11compression11init_heap32EP9heap_treePjj(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 6872, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %40, %3
  %11 = load i32, ptr %8, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp ult i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %43

15:                                               ; preds = %10
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds i32, ptr %16, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %39

22:                                               ; preds = %15
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr %23, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = shl i64 %28, 16
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = or i64 %29, %31
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.heap_tree, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = add i32 %35, 1
  store i32 %36, ptr %7, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds [859 x i64], ptr %34, i64 0, i64 %37
  store i64 %32, ptr %38, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %22, %15
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = add i32 %41, 1
  store i32 %42, ptr %8, align 4, !tbaa !9
  br label %10, !llvm.loop !12

43:                                               ; preds = %14
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = icmp ult i32 %44, 2
  br i1 %45, label %46, label %71

46:                                               ; preds = %43
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %56

49:                                               ; preds = %46
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.heap_tree, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds [859 x i64], ptr %51, i64 0, i64 1
  store i64 65536, ptr %52, align 8, !tbaa !11
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.heap_tree, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds [859 x i64], ptr %54, i64 0, i64 2
  store i64 65537, ptr %55, align 8, !tbaa !11
  store i32 2, ptr %7, align 4, !tbaa !9
  br label %70

56:                                               ; preds = %46
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds i32, ptr %57, i64 0
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = icmp eq i32 %59, 0
  br i1 %60, label %61, label %65

61:                                               ; preds = %56
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.heap_tree, ptr %62, i32 0, i32 0
  %64 = getelementptr inbounds [859 x i64], ptr %63, i64 0, i64 2
  store i64 65536, ptr %64, align 8, !tbaa !11
  br label %69

65:                                               ; preds = %56
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.heap_tree, ptr %66, i32 0, i32 0
  %68 = getelementptr inbounds [859 x i64], ptr %67, i64 0, i64 2
  store i64 65537, ptr %68, align 8, !tbaa !11
  br label %69

69:                                               ; preds = %65, %61
  store i32 2, ptr %7, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %69, %49
  br label %71

71:                                               ; preds = %70, %43
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.heap_tree, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds [859 x i64], ptr %73, i64 0, i64 0
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = zext i32 %75 to i64
  invoke void @qpl_build_heap(ptr noundef %74, i64 noundef %76)
          to label %77 unwind label %79

77:                                               ; preds = %71
  %78 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret i32 %78

79:                                               ; preds = %71
  %80 = landingpad { ptr, i32 }
          catch ptr null
  %81 = extractvalue { ptr, i32 } %80, 0
  call void @__clang_call_terminate(ptr %81) #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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

declare void @qpl_build_heap(ptr noundef, i64 noundef) #3

declare i32 @__gxx_personality_v0(...)

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

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 = { 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 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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 range(i32 2, 0) i32 @_ZN3qpl2ml11compression11init_heap32EP9heap_treePjj(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(6872) %0, i8 0, i64 6872, i1 false)
  %.not24 = icmp eq i32 %2, 0
  br i1 %.not24, label %.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %4 = icmp eq i32 %2, 1
  br i1 %4, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

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

._crit_edge.unr-lcssa:                            ; preds = %33, %.lr.ph.preheader
  %.1.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %.1.1, %33 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %33 ]
  %.02022.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %.1.1, %33 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa
  %5 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.unr
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not.epil = icmp eq i32 %6, 0
  br i1 %.not.epil, label %._crit_edge, label %7

7:                                                ; preds = %.lr.ph.epil
  %8 = zext i32 %6 to i64
  %9 = shl nuw nsw i64 %8, 16
  %10 = or i64 %9, %indvars.iv.unr
  %11 = add i32 %.02022.unr, 1
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds [859 x i64], ptr %0, i64 0, i64 %12
  store i64 %10, ptr %13, align 8, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %7, %._crit_edge.unr-lcssa
  %.1.lcssa = phi i32 [ %.1.lcssa.ph, %._crit_edge.unr-lcssa ], [ %11, %7 ], [ %.02022.unr, %.lr.ph.epil ]
  %14 = icmp ult i32 %.1.lcssa, 2
  br i1 %14, label %34, label %44

.lr.ph:                                           ; preds = %33, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %33 ]
  %.02022 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %.1.1, %33 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %33 ]
  %15 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %.lr.ph.1, label %17

17:                                               ; preds = %.lr.ph
  %18 = zext i32 %16 to i64
  %19 = shl nuw nsw i64 %18, 16
  %20 = or i64 %19, %indvars.iv
  %21 = add i32 %.02022, 1
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds [859 x i64], ptr %0, i64 0, i64 %22
  store i64 %20, ptr %23, align 8, !tbaa !9
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %17
  %.1 = phi i32 [ %21, %17 ], [ %.02022, %.lr.ph ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %24 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %25, 0
  br i1 %.not.1, label %33, label %26

26:                                               ; preds = %.lr.ph.1
  %27 = zext i32 %25 to i64
  %28 = shl nuw nsw i64 %27, 16
  %29 = or i64 %28, %indvars.iv.next
  %30 = add i32 %.1, 1
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds [859 x i64], ptr %0, i64 0, i64 %31
  store i64 %29, ptr %32, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %26, %.lr.ph.1
  %.1.1 = phi i32 [ %30, %26 ], [ %.1, %.lr.ph.1 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !10

34:                                               ; preds = %._crit_edge
  %35 = icmp eq i32 %.1.lcssa, 0
  br i1 %35, label %.thread, label %38

.thread:                                          ; preds = %3, %34
  %36 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 65536, ptr %36, align 8, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 65537, ptr %37, align 8, !tbaa !9
  br label %44

38:                                               ; preds = %34
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 0
  %41 = getelementptr inbounds i8, ptr %0, i64 16
  br i1 %40, label %42, label %43

42:                                               ; preds = %38
  store i64 65536, ptr %41, align 8, !tbaa !9
  br label %44

43:                                               ; preds = %38
  store i64 65537, ptr %41, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %42, %43, %.thread, %._crit_edge
  %.2 = phi i32 [ 2, %.thread ], [ %.1.lcssa, %._crit_edge ], [ 2, %43 ], [ 2, %42 ]
  %45 = zext i32 %.2 to i64
  invoke void @qpl_build_heap(ptr noundef %0, i64 noundef %45)
          to label %46 unwind label %47

46:                                               ; preds = %44
  ret i32 %.2

47:                                               ; preds = %44
  %48 = landingpad { ptr, i32 }
          catch ptr null
  %49 = extractvalue { ptr, i32 } %48, 0
  tail call void @__clang_call_terminate(ptr %49) #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) #1

declare void @qpl_build_heap(ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { "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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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