; LLVM IR from intel/qpl :: sources/core-sw/src/compression (deflate_slow_matcher)

; 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.deflate_match_t = type { i32, i32, i32, i32, ptr }
%struct.deflate_hash_table_t = type { ptr, ptr, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @get_lazy_best_match(ptr dead_on_unwind noalias writable sret(%struct.deflate_match_t) align 8 %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %struct.deflate_match_t, align 8
  %12 = alloca %struct.deflate_match_t, align 8
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  store ptr %4, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 1
  store ptr %14, ptr %10, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  call void @get_best_match(ptr dead_on_unwind writable sret(%struct.deflate_match_t) align 8 %0, ptr noundef %15, ptr noundef %16, ptr noundef %17, ptr noundef %18)
  call void @llvm.lifetime.start.p0(i64 24, ptr %11) #4
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  call void @get_best_match(ptr dead_on_unwind writable sret(%struct.deflate_match_t) align 8 %11, ptr noundef %19, ptr noundef %20, ptr noundef %21, ptr noundef %22)
  br label %23

23:                                               ; preds = %42, %5
  %24 = getelementptr inbounds %struct.deflate_match_t, ptr %0, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.deflate_match_t, ptr %11, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !9
  %28 = icmp ult i32 %25, %27
  br i1 %28, label %29, label %40

29:                                               ; preds = %23
  %30 = getelementptr inbounds %struct.deflate_match_t, ptr %0, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !9
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.deflate_hash_table_t, ptr %32, i32 0, i32 6
  %34 = load i32, ptr %33, align 8, !tbaa !12
  %35 = icmp ult i32 %31, %34
  br i1 %35, label %36, label %40

36:                                               ; preds = %29
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = icmp ult ptr %37, %38
  br label %40

40:                                               ; preds = %36, %29, %23
  %41 = phi i1 [ false, %29 ], [ false, %23 ], [ %39, %36 ]
  br i1 %41, label %42, label %49

42:                                               ; preds = %40
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i32 1
  store ptr %44, ptr %10, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %11, i64 24, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #4
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  call void @get_best_match(ptr dead_on_unwind writable sret(%struct.deflate_match_t) align 8 %12, ptr noundef %45, ptr noundef %46, ptr noundef %47, ptr noundef %48)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %12, i64 24, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 24, ptr %12) #4
  br label %23, !llvm.loop !16

49:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 24, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  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: inlinehint nounwind uwtable
declare hidden void @get_best_match(ptr dead_on_unwind noalias writable sret(%struct.deflate_match_t) align 8, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

attributes #0 = { 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 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 32}
!13 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32}
!14 = !{i64 0, i64 4, !15, i64 4, i64 4, !15, i64 8, i64 4, !15, i64 12, i64 4, !15, i64 16, i64 8, !5}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%struct.deflate_match_t = type { i32, i32, i32, i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @get_lazy_best_match(ptr dead_on_unwind noalias writable sret(%struct.deflate_match_t) align 8 %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca %struct.deflate_match_t, align 8
  %7 = alloca %struct.deflate_match_t, align 8
  %8 = getelementptr inbounds i8, ptr %3, i64 1
  tail call void @get_best_match(ptr dead_on_unwind writable sret(%struct.deflate_match_t) align 8 %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #4
  call void @get_best_match(ptr dead_on_unwind nonnull writable sret(%struct.deflate_match_t) align 8 %6, ptr noundef %1, ptr noundef %2, ptr noundef nonnull %8, ptr noundef %4)
  %9 = load i32, ptr %0, align 8, !tbaa !5
  %10 = load i32, ptr %6, align 8, !tbaa !5
  %11 = icmp ult i32 %9, %10
  br i1 %11, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %5
  %12 = getelementptr inbounds i8, ptr %1, i64 32
  br label %13

13:                                               ; preds = %.lr.ph, %18
  %14 = phi i32 [ %9, %.lr.ph ], [ %20, %18 ]
  %.019 = phi ptr [ %8, %.lr.ph ], [ %19, %18 ]
  %15 = load i32, ptr %12, align 8, !tbaa !11
  %16 = icmp ult i32 %14, %15
  %17 = icmp ult ptr %.019, %4
  %or.cond = select i1 %16, i1 %17, i1 false
  br i1 %or.cond, label %18, label %.critedge

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %.019, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %6, i64 24, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #4
  call void @get_best_match(ptr dead_on_unwind nonnull writable sret(%struct.deflate_match_t) align 8 %7, ptr noundef nonnull %1, ptr noundef %2, ptr noundef nonnull %19, ptr noundef nonnull %4)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 8 dereferenceable(24) %7, i64 24, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #4
  %20 = load i32, ptr %0, align 8, !tbaa !5
  %21 = load i32, ptr %6, align 8, !tbaa !5
  %22 = icmp ult i32 %20, %21
  br i1 %22, label %13, label %.critedge, !llvm.loop !16

.critedge:                                        ; preds = %18, %13, %5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #4
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @get_best_match(ptr dead_on_unwind noalias writable sret(%struct.deflate_match_t) align 8, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

attributes #0 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !7, i64 32}
!12 = !{!"", !10, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32}
!13 = !{i64 0, i64 4, !14, i64 4, i64 4, !14, i64 8, i64 4, !14, i64 12, i64 4, !14, i64 16, i64 8, !15}
!14 = !{!7, !7, i64 0}
!15 = !{!10, !10, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass