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

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN3qpl2ml11compression7details22histogram_join_anotherER13qpl_histogramS4_(ptr noundef nonnull align 4 dereferenceable(1280) %0, ptr noundef nonnull align 4 dereferenceable(1280) %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  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) #2
  store i32 320, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %9, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %10, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %27, %2
  %12 = load i32, ptr %8, align 4, !tbaa !9
  %13 = icmp ult i32 %12, 320
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %11
  %16 = load ptr, ptr %7, 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 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %21, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = add i32 %25, %20
  store i32 %26, ptr %24, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %15
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = add i32 %28, 1
  store i32 %29, ptr %8, align 4, !tbaa !9
  br label %11, !llvm.loop !11

30:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

; 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 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 = { 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 = distinct !{!11, !12}
!12 = !{!"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 nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN3qpl2ml11compression7details22histogram_join_anotherER13qpl_histogramS4_(ptr nocapture noundef nonnull align 4 dereferenceable(1280) %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(1280) %1) local_unnamed_addr #0 {
vector.memcheck:
  %scevgep = getelementptr inbounds i8, ptr %0, i64 1280
  %scevgep9 = getelementptr inbounds i8, ptr %1, i64 1280
  %bound0 = icmp ugt ptr %scevgep9, %0
  %bound1 = icmp ugt ptr %scevgep, %1
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph, label %vector.body

vector.body:                                      ; preds = %vector.memcheck, %vector.body
  %index = phi i64 [ %index.next.1, %vector.body ], [ 0, %vector.memcheck ]
  %2 = getelementptr inbounds i32, ptr %1, i64 %index
  %3 = getelementptr inbounds i8, ptr %2, i64 16
  %wide.load = load <4 x i32>, ptr %2, align 4, !tbaa !5, !alias.scope !9
  %wide.load10 = load <4 x i32>, ptr %3, align 4, !tbaa !5, !alias.scope !9
  %4 = getelementptr inbounds i32, ptr %0, i64 %index
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  %wide.load11 = load <4 x i32>, ptr %4, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %wide.load12 = load <4 x i32>, ptr %5, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %6 = add <4 x i32> %wide.load11, %wide.load
  %7 = add <4 x i32> %wide.load12, %wide.load10
  store <4 x i32> %6, ptr %4, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  store <4 x i32> %7, ptr %5, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next = or disjoint i64 %index, 8
  %8 = getelementptr inbounds i32, ptr %1, i64 %index.next
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %wide.load.1 = load <4 x i32>, ptr %8, align 4, !tbaa !5, !alias.scope !9
  %wide.load10.1 = load <4 x i32>, ptr %9, align 4, !tbaa !5, !alias.scope !9
  %10 = getelementptr inbounds i32, ptr %0, i64 %index.next
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %wide.load11.1 = load <4 x i32>, ptr %10, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %wide.load12.1 = load <4 x i32>, ptr %11, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %12 = add <4 x i32> %wide.load11.1, %wide.load.1
  %13 = add <4 x i32> %wide.load12.1, %wide.load10.1
  store <4 x i32> %12, ptr %10, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  store <4 x i32> %13, ptr %11, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next.1 = add nuw nsw i64 %index, 16
  %14 = icmp eq i64 %index.next.1, 320
  br i1 %14, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body, %scalar.ph
  ret void

scalar.ph:                                        ; preds = %vector.memcheck, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ 0, %vector.memcheck ]
  %15 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = add i32 %18, %16
  store i32 %19, ptr %17, align 4, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %20 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = add i32 %23, %21
  store i32 %24, ptr %22, align 4, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %25 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next.1
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.1
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add i32 %28, %26
  store i32 %29, ptr %27, align 4, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %30 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next.2
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.2
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = add i32 %33, %31
  store i32 %34, ptr %32, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 320
  br i1 %exitcond.not.3, label %middle.block, label %scalar.ph, !llvm.loop !18
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass