; 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.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
declare dso_local void @own_deflate_job_switch_to_next(ptr noundef, i32 noundef) #0

; 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

; Function Attrs: nounwind uwtable
define dso_local void @own_deflate_job_process_literals_no_instructions(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = zext i1 %2 to i8
  store i8 %10, ptr %6, align 1, !tbaa !9
  %11 = load i8, ptr %6, align 1, !tbaa !9, !range !11, !noundef !12
  %12 = trunc i8 %11 to i1
  %13 = zext i1 %12 to i32
  %14 = icmp eq i32 1, %13
  br i1 %14, label %15, label %86

15:                                               ; preds = %3
  br label %16

16:                                               ; preds = %42, %15
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.own_deflate_job, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = icmp ult ptr %19, %20
  br i1 %21, label %22, label %85

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.own_deflate_job, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = ptrtoint ptr %23 to i64
  %28 = ptrtoint ptr %26 to i64
  %29 = sub i64 %27, %28
  %30 = trunc i64 %29 to i32
  %31 = icmp ult i32 4, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %22
  br label %42

33:                                               ; preds = %22
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.own_deflate_job, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  %38 = ptrtoint ptr %34 to i64
  %39 = ptrtoint ptr %37 to i64
  %40 = sub i64 %38, %39
  %41 = trunc i64 %40 to i32
  br label %42

42:                                               ; preds = %33, %32
  %43 = phi i32 [ 4, %32 ], [ %41, %33 ]
  store i32 %43, ptr %7, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %44 = load ptr, ptr %4, 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 !13
  %47 = load i32, ptr %7, align 4, !tbaa !18
  %48 = zext i32 %47 to i64
  %49 = call i32 @qpl_crc32_gzip_refl(i32 noundef 0, ptr noundef %46, i64 noundef %48)
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.own_deflate_job, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !19
  %53 = getelementptr inbounds %struct.deflate_histogram_t, ptr %52, i32 0, i32 2
  %54 = getelementptr inbounds %struct.deflate_hash_table_t, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !20
  %56 = and i32 %49, %55
  store i32 %56, ptr %8, align 4, !tbaa !18
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.own_deflate_job, ptr %57, i32 0, i32 3
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  %60 = getelementptr inbounds %struct.deflate_histogram_t, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.own_deflate_job, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !13
  %64 = load i8, ptr %63, align 1, !tbaa !23
  %65 = zext i8 %64 to i64
  %66 = getelementptr inbounds [286 x i32], ptr %60, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !18
  %68 = add i32 %67, 1
  store i32 %68, ptr %66, align 4, !tbaa !18
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.own_deflate_job, ptr %69, i32 0, i32 3
  %71 = load ptr, ptr %70, align 8, !tbaa !19
  %72 = getelementptr inbounds %struct.deflate_histogram_t, ptr %71, i32 0, i32 2
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.own_deflate_job, ptr %73, i32 0, i32 1
  %75 = load ptr, ptr %74, align 8, !tbaa !13
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.own_deflate_job, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !24
  %79 = ptrtoint ptr %75 to i64
  %80 = ptrtoint ptr %78 to i64
  %81 = sub i64 %79, %80
  %82 = trunc i64 %81 to i32
  %83 = load i32, ptr %8, align 4, !tbaa !18
  call void @own_deflate_hash_table_update(ptr noundef %72, i32 noundef %82, i32 noundef %83)
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  call void @own_deflate_job_switch_to_next(ptr noundef %84, i32 noundef 1)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %16, !llvm.loop !25

85:                                               ; preds = %16
  br label %134

86:                                               ; preds = %3
  br label %87

87:                                               ; preds = %93, %86
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.own_deflate_job, ptr %88, i32 0, i32 1
  %90 = load ptr, ptr %89, align 8, !tbaa !13
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = icmp ult ptr %90, %91
  br i1 %92, label %93, label %133

93:                                               ; preds = %87
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.own_deflate_job, ptr %94, i32 0, i32 1
  %96 = load ptr, ptr %95, align 8, !tbaa !13
  %97 = call i32 @qpl_crc32_gzip_refl(i32 noundef 0, ptr noundef %96, i64 noundef 4)
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.own_deflate_job, ptr %98, i32 0, i32 3
  %100 = load ptr, ptr %99, align 8, !tbaa !19
  %101 = getelementptr inbounds %struct.deflate_histogram_t, ptr %100, i32 0, i32 2
  %102 = getelementptr inbounds %struct.deflate_hash_table_t, ptr %101, i32 0, i32 2
  %103 = load i32, ptr %102, align 8, !tbaa !20
  %104 = and i32 %97, %103
  store i32 %104, ptr %9, align 4, !tbaa !18
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.own_deflate_job, ptr %105, i32 0, i32 3
  %107 = load ptr, ptr %106, align 8, !tbaa !19
  %108 = getelementptr inbounds %struct.deflate_histogram_t, ptr %107, i32 0, i32 0
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.own_deflate_job, ptr %109, i32 0, i32 1
  %111 = load ptr, ptr %110, align 8, !tbaa !13
  %112 = load i8, ptr %111, align 1, !tbaa !23
  %113 = zext i8 %112 to i64
  %114 = getelementptr inbounds [286 x i32], ptr %108, i64 0, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !18
  %116 = add i32 %115, 1
  store i32 %116, ptr %114, align 4, !tbaa !18
  %117 = load ptr, ptr %4, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.own_deflate_job, ptr %117, i32 0, i32 3
  %119 = load ptr, ptr %118, align 8, !tbaa !19
  %120 = getelementptr inbounds %struct.deflate_histogram_t, ptr %119, i32 0, i32 2
  %121 = load ptr, ptr %4, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.own_deflate_job, ptr %121, i32 0, i32 1
  %123 = load ptr, ptr %122, align 8, !tbaa !13
  %124 = load ptr, ptr %4, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.own_deflate_job, ptr %124, i32 0, i32 0
  %126 = load ptr, ptr %125, align 8, !tbaa !24
  %127 = ptrtoint ptr %123 to i64
  %128 = ptrtoint ptr %126 to i64
  %129 = sub i64 %127, %128
  %130 = trunc i64 %129 to i32
  %131 = load i32, ptr %9, align 4, !tbaa !18
  call void @own_deflate_hash_table_update(ptr noundef %120, i32 noundef %130, i32 noundef %131)
  %132 = load ptr, ptr %4, align 8, !tbaa !5
  call void @own_deflate_job_switch_to_next(ptr noundef %132, i32 noundef 1)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %87, !llvm.loop !27

133:                                              ; preds = %87
  br label %134

134:                                              ; preds = %133, %85
  ret void
}

declare i32 @qpl_crc32_gzip_refl(i32 noundef, ptr noundef, i64 noundef) #2

declare void @own_deflate_hash_table_update(ptr noundef, i32 noundef, i32 noundef) #2

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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !6, i64 8}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !15, i64 40, !17, i64 88, !17, i64 92, !17, i64 96, !17, i64 100, !17, i64 104}
!15 = !{!"", !16, i64 0, !17, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !17, i64 40}
!16 = !{!"long", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!17, !17, i64 0}
!19 = !{!14, !6, i64 24}
!20 = !{!21, !17, i64 1280}
!21 = !{!"", !7, i64 0, !7, i64 1144, !22, i64 1264}
!22 = !{!"", !6, i64 0, !6, i64 8, !17, i64 16, !17, i64 20, !17, i64 24, !17, i64 28, !17, i64 32}
!23 = !{!7, !7, i64 0}
!24 = !{!14, !6, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !26}


; 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: nounwind uwtable
declare dso_local void @own_deflate_job_switch_to_next(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @own_deflate_job_process_literals_no_instructions(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp ult ptr %5, %1
  br i1 %2, label %.preheader, label %.preheader30

.preheader30:                                     ; preds = %3
  br i1 %6, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader30
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  br label %37

.preheader:                                       ; preds = %3
  br i1 %6, label %.lr.ph32, label %.loopexit

.lr.ph32:                                         ; preds = %.preheader
  %8 = ptrtoint ptr %1 to i64
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  br label %10

10:                                               ; preds = %.lr.ph32, %10
  %11 = phi ptr [ %5, %.lr.ph32 ], [ %35, %10 ]
  %12 = ptrtoint ptr %11 to i64
  %13 = sub i64 %8, %12
  %14 = trunc i64 %13 to i32
  %15 = icmp ugt i32 %14, 4
  %16 = and i64 %13, 7
  %17 = select i1 %15, i64 4, i64 %16
  %18 = tail call i32 @qpl_crc32_gzip_refl(i32 noundef 0, ptr noundef %11, i64 noundef %17) #2
  %19 = load ptr, ptr %9, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %19, i64 1280
  %21 = load i32, ptr %20, align 8, !tbaa !14
  %22 = and i32 %21, %18
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i8, ptr %23, align 1, !tbaa !17
  %25 = zext i8 %24 to i64
  %26 = getelementptr inbounds [286 x i32], ptr %19, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !18
  %28 = add i32 %27, 1
  store i32 %28, ptr %26, align 4, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %19, i64 1264
  %30 = load ptr, ptr %0, align 8, !tbaa !19
  %31 = ptrtoint ptr %23 to i64
  %32 = ptrtoint ptr %30 to i64
  %33 = sub i64 %31, %32
  %34 = trunc i64 %33 to i32
  tail call void @own_deflate_hash_table_update(ptr noundef nonnull %29, i32 noundef %34, i32 noundef %22) #2
  tail call void @own_deflate_job_switch_to_next(ptr noundef nonnull %0, i32 noundef 1)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = icmp ult ptr %35, %1
  br i1 %36, label %10, label %.loopexit, !llvm.loop !20

37:                                               ; preds = %.lr.ph, %37
  %38 = phi ptr [ %5, %.lr.ph ], [ %56, %37 ]
  %39 = tail call i32 @qpl_crc32_gzip_refl(i32 noundef 0, ptr noundef %38, i64 noundef 4) #2
  %40 = load ptr, ptr %7, align 8, !tbaa !13
  %41 = getelementptr inbounds i8, ptr %40, i64 1280
  %42 = load i32, ptr %41, align 8, !tbaa !14
  %43 = and i32 %42, %39
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load i8, ptr %44, align 1, !tbaa !17
  %46 = zext i8 %45 to i64
  %47 = getelementptr inbounds [286 x i32], ptr %40, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !18
  %49 = add i32 %48, 1
  store i32 %49, ptr %47, align 4, !tbaa !18
  %50 = getelementptr inbounds i8, ptr %40, i64 1264
  %51 = load ptr, ptr %0, align 8, !tbaa !19
  %52 = ptrtoint ptr %44 to i64
  %53 = ptrtoint ptr %51 to i64
  %54 = sub i64 %52, %53
  %55 = trunc i64 %54 to i32
  tail call void @own_deflate_hash_table_update(ptr noundef nonnull %50, i32 noundef %55, i32 noundef %43) #2
  tail call void @own_deflate_job_switch_to_next(ptr noundef nonnull %0, i32 noundef 1)
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = icmp ult ptr %56, %1
  br i1 %57, label %37, label %.loopexit, !llvm.loop !22

.loopexit:                                        ; preds = %37, %10, %.preheader30, %.preheader
  ret void
}

declare i32 @qpl_crc32_gzip_refl(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @own_deflate_hash_table_update(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #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 = { "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, !7, i64 8}
!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 24}
!14 = !{!15, !12, i64 1280}
!15 = !{!"", !8, i64 0, !8, i64 1144, !16, i64 1264}
!16 = !{!"", !7, i64 0, !7, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32}
!17 = !{!8, !8, i64 0}
!18 = !{!12, !12, i64 0}
!19 = !{!6, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


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