; LLVM IR from intel/qpl :: sources/c_api/compression_operations (own_deflate_job)

; 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.own_deflate_job = type { ptr, ptr, ptr, ptr, ptr, %struct.bit_writer_t, i32, i32, i32, i32, i32 }
%struct.bit_writer_t = type { i64, i32, ptr, ptr, ptr, i32 }
%struct.deflate_histogram_t = type { [286 x i32], [30 x i32], %struct.deflate_hash_table_t }
%struct.deflate_hash_table_t = type { ptr, ptr, i32, i32, i32, i32, i32 }

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

22:                                               ; preds = %63, %6
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.own_deflate_job, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = load ptr, ptr %13, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 -4
  %28 = icmp ult ptr %25, %27
  br i1 %28, label %29, label %35

29:                                               ; preds = %22
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = call zeroext i8 %30(ptr noundef %31)
  %33 = zext i8 %32 to i32
  %34 = icmp ne i32 %33, 0
  br label %35

35:                                               ; preds = %29, %22
  %36 = phi i1 [ false, %22 ], [ %34, %29 ]
  br i1 %36, label %37, label %64

37:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 24, ptr %15) #2
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.own_deflate_job, ptr %39, i32 0, i32 3
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = getelementptr inbounds %struct.deflate_histogram_t, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.own_deflate_job, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i64 -4
  call void %38(ptr dead_on_unwind writable sret(%struct.deflate_match_t) align 8 %15, ptr noundef %42, ptr noundef %43, ptr noundef %46, ptr noundef %48)
  %49 = getelementptr inbounds %struct.deflate_match_t, ptr %15, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !17
  %51 = icmp uge i32 %50, 4
  br i1 %51, label %52, label %56

52:                                               ; preds = %37
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  call void %53(ptr noundef %54, ptr noundef byval(%struct.deflate_match_t) align 8 %15, ptr noundef %55)
  br label %63

56:                                               ; preds = %37
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.own_deflate_job, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  %62 = getelementptr inbounds i8, ptr %61, i64 1
  call void %57(ptr noundef %58, ptr noundef %62, i1 noundef zeroext false)
  br label %63

63:                                               ; preds = %56, %52
  call void @llvm.lifetime.end.p0(i64 24, ptr %15) #2
  br label %22, !llvm.loop !19

64:                                               ; preds = %35
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = call zeroext i8 %65(ptr noundef %66)
  %68 = icmp ne i8 %67, 0
  br i1 %68, label %69, label %73

69:                                               ; preds = %64
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = load ptr, ptr %13, align 8, !tbaa !5
  call void %70(ptr noundef %71, ptr noundef %72, i1 noundef zeroext true)
  br label %73

73:                                               ; preds = %69, %64
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  call void %74(ptr noundef %75)
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #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 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !13, i64 88, !13, i64 92, !13, i64 96, !13, i64 100, !13, i64 104}
!11 = !{!"", !12, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40}
!12 = !{!"long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !6, i64 0}
!15 = !{!10, !6, i64 8}
!16 = !{!10, !6, i64 24}
!17 = !{!18, !13, i64 0}
!18 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !6, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"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 @own_deflate_job_perform(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr nocapture noundef readonly %5) local_unnamed_addr #0 {
  %7 = alloca %struct.deflate_match_t, align 8
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = load ptr, ptr %0, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = getelementptr inbounds i8, ptr %9, i64 -4
  %13 = load ptr, ptr %11, align 8, !tbaa !14
  %14 = icmp ult ptr %13, %12
  br i1 %14, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %6
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  br label %16

16:                                               ; preds = %.lr.ph, %28
  %17 = call zeroext i8 %4(ptr noundef nonnull %0) #2
  %.not = icmp eq i8 %17, 0
  br i1 %.not, label %.critedge, label %18

18:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #2
  %19 = load ptr, ptr %15, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %19, i64 1264
  %21 = load ptr, ptr %11, align 8, !tbaa !14
  call void %1(ptr dead_on_unwind nonnull writable sret(%struct.deflate_match_t) align 8 %7, ptr noundef nonnull %20, ptr noundef %10, ptr noundef %21, ptr noundef nonnull %12) #2
  %22 = load i32, ptr %7, align 8, !tbaa !16
  %23 = icmp ugt i32 %22, 3
  br i1 %23, label %24, label %25

24:                                               ; preds = %18
  call void %3(ptr noundef nonnull %0, ptr noundef nonnull byval(%struct.deflate_match_t) align 8 %7, ptr noundef %2) #2
  br label %28

25:                                               ; preds = %18
  %26 = load ptr, ptr %11, align 8, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %26, i64 1
  call void %2(ptr noundef nonnull %0, ptr noundef nonnull %27, i1 noundef zeroext false) #2
  br label %28

28:                                               ; preds = %25, %24
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #2
  %29 = load ptr, ptr %11, align 8, !tbaa !14
  %30 = icmp ult ptr %29, %12
  br i1 %30, label %16, label %.critedge, !llvm.loop !18

.critedge:                                        ; preds = %16, %28, %6
  %31 = call zeroext i8 %4(ptr noundef nonnull %0) #2
  %.not24 = icmp eq i8 %31, 0
  br i1 %.not24, label %33, label %32

32:                                               ; preds = %.critedge
  call void %2(ptr noundef nonnull %0, ptr noundef %9, i1 noundef zeroext true) #2
  br label %33

33:                                               ; preds = %32, %.critedge
  call void %5(ptr noundef nonnull %0) #2
  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: 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 = { 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 16}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !12, i64 88, !12, i64 92, !12, i64 96, !12, i64 100, !12, i64 104}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !12, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !12, i64 40}
!11 = !{!"long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !7, i64 24}
!16 = !{!17, !12, i64 0}
!17 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !7, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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