; LLVM IR from ebiggers/libdeflate :: lib (deflate_compress)

; 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_output_bitstream = type { i64, i32, ptr, ptr, i8 }
%struct.libdeflate_compressor = type { ptr, ptr, i32, i64, i32, i32, %struct.deflate_freqs, %struct.block_split_stats, %struct.deflate_codes, %struct.deflate_codes, %union.anon, [4 x i8], %union.anon.1 }
%struct.deflate_freqs = type { [288 x i32], [32 x i32] }
%struct.block_split_stats = type { [10 x i32], [10 x i32], i32, i32 }
%struct.deflate_codes = type { %struct.deflate_codewords, %struct.deflate_lens }
%struct.deflate_codewords = type { [288 x i32], [32 x i32] }
%struct.deflate_lens = type { [288 x i8], [32 x i8] }
%union.anon = type { %struct.anon }
%struct.anon = type { [19 x i32], [19 x i32], [19 x i8], [320 x i32], i32, i32, i32, i32 }
%union.anon.1 = type { %struct.anon.4 }
%struct.anon.4 = type { %struct.bt_matchfinder, [1500513 x %struct.lz_match], [305000 x %struct.deflate_optimum_node], %struct.deflate_costs, %struct.deflate_costs, [32769 x i8], [10 x i32], i32, [259 x i32], [259 x i32], i32, i32, i32, i32, [12 x i8] }
%struct.bt_matchfinder = type { [65536 x [2 x i16]], [65536 x i16], [65536 x i16] }
%struct.lz_match = type { i16, i16 }
%struct.deflate_optimum_node = type { i32, i32 }
%struct.deflate_costs = type { [256 x i32], [259 x i32], [32 x i32] }

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @libdeflate_deflate_compress(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) #1 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca %struct.deflate_output_bitstream, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %12) #3
  %14 = load i64, ptr %9, align 8, !tbaa !9
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.libdeflate_compressor, ptr %15, i32 0, i32 3
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = icmp ule i64 %14, %17
  %19 = xor i1 %18, true
  %20 = xor i1 %19, true
  %21 = zext i1 %20 to i32
  %22 = sext i32 %21 to i64
  %23 = call i64 @llvm.expect.i64(i64 %22, i64 0)
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %31

25:                                               ; preds = %5
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = call i64 @deflate_compress_none(ptr noundef %26, i64 noundef %27, ptr noundef %28, i64 noundef %29)
  store i64 %30, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %80

31:                                               ; preds = %5
  %32 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 0
  store i64 0, ptr %32, align 8, !tbaa !19
  %33 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 1
  store i32 0, ptr %33, align 8, !tbaa !22
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 2
  store ptr %34, ptr %35, align 8, !tbaa !23
  %36 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !23
  %38 = load i64, ptr %11, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %37, i64 %38
  %40 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 3
  store ptr %39, ptr %40, align 8, !tbaa !24
  %41 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 4
  store i8 0, ptr %41, align 8, !tbaa !25
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.libdeflate_compressor, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 32, !tbaa !26
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i64, ptr %9, align 8, !tbaa !9
  call void %44(ptr noundef %45, ptr noundef %46, i64 noundef %47, ptr noundef %12)
  %48 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 4
  %49 = load i8, ptr %48, align 8, !tbaa !25, !range !27, !noundef !28
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %52

51:                                               ; preds = %31
  store i64 0, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %80

52:                                               ; preds = %31
  %53 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !22
  %55 = icmp ule i32 %54, 7
  %56 = zext i1 %55 to i32
  %57 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 1
  %58 = load i32, ptr %57, align 8, !tbaa !22
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %73

60:                                               ; preds = %52
  %61 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !23
  %63 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !24
  %65 = icmp ult ptr %62, %64
  %66 = zext i1 %65 to i32
  %67 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 0
  %68 = load i64, ptr %67, align 8, !tbaa !19
  %69 = trunc i64 %68 to i8
  %70 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !23
  %72 = getelementptr inbounds i8, ptr %71, i32 1
  store ptr %72, ptr %70, align 8, !tbaa !23
  store i8 %69, ptr %71, align 1, !tbaa !29
  br label %73

73:                                               ; preds = %60, %52
  %74 = getelementptr inbounds %struct.deflate_output_bitstream, ptr %12, i32 0, i32 2
  %75 = load ptr, ptr %74, align 8, !tbaa !23
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = ptrtoint ptr %75 to i64
  %78 = ptrtoint ptr %76 to i64
  %79 = sub i64 %77, %78
  store i64 %79, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %80

80:                                               ; preds = %73, %51, %25
  call void @llvm.lifetime.end.p0(i64 40, ptr %12) #3
  %81 = load i64, ptr %6, align 8
  ret i64 %81
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #2

; Function Attrs: nounwind uwtable
declare hidden i64 @deflate_compress_none(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"libdeflate_compressor", !6, i64 0, !6, i64 8, !13, i64 16, !10, i64 24, !13, i64 32, !13, i64 36, !14, i64 40, !15, i64 1320, !16, i64 1408, !16, i64 3008, !7, i64 4608, !7, i64 6080}
!13 = !{!"int", !7, i64 0}
!14 = !{!"deflate_freqs", !7, i64 0, !7, i64 1152}
!15 = !{!"block_split_stats", !7, i64 0, !7, i64 40, !13, i64 80, !13, i64 84}
!16 = !{!"deflate_codes", !17, i64 0, !18, i64 1280}
!17 = !{!"deflate_codewords", !7, i64 0, !7, i64 1152}
!18 = !{!"deflate_lens", !7, i64 0, !7, i64 288}
!19 = !{!20, !10, i64 0}
!20 = !{!"deflate_output_bitstream", !10, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !21, i64 32}
!21 = !{!"_Bool", !7, i64 0}
!22 = !{!20, !13, i64 8}
!23 = !{!20, !6, i64 16}
!24 = !{!20, !6, i64 24}
!25 = !{!20, !21, i64 32}
!26 = !{!12, !6, i64 0}
!27 = !{i8 0, i8 2}
!28 = !{}
!29 = !{!7, !7, i64 0}


; 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_output_bitstream = type { i64, i32, ptr, ptr, i8 }

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @libdeflate_deflate_compress(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) local_unnamed_addr #1 {
  %6 = alloca %struct.deflate_output_bitstream, align 8
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %6) #2
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %.not = icmp ult i64 %8, %2
  br i1 %.not, label %11, label %9, !prof !17

9:                                                ; preds = %5
  %10 = tail call i64 @deflate_compress_none(ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4)
  br label %32

11:                                               ; preds = %5
  store i64 0, ptr %6, align 8, !tbaa !18
  %12 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 0, ptr %12, align 8, !tbaa !21
  %13 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr %3, ptr %13, align 8, !tbaa !22
  %14 = getelementptr inbounds i8, ptr %3, i64 %4
  %15 = getelementptr inbounds i8, ptr %6, i64 24
  store ptr %14, ptr %15, align 8, !tbaa !23
  %16 = getelementptr inbounds i8, ptr %6, i64 32
  store i8 0, ptr %16, align 8, !tbaa !24
  %17 = load ptr, ptr %0, align 32, !tbaa !25
  call void %17(ptr noundef nonnull %0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull %6) #2
  %18 = load i8, ptr %16, align 8, !tbaa !24, !range !26, !noundef !27
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %32, label %20

20:                                               ; preds = %11
  %21 = load i32, ptr %12, align 8, !tbaa !21
  %.not14 = icmp eq i32 %21, 0
  br i1 %.not14, label %27, label %22

22:                                               ; preds = %20
  %23 = load ptr, ptr %13, align 8, !tbaa !22
  %24 = load i64, ptr %6, align 8, !tbaa !18
  %25 = trunc i64 %24 to i8
  %26 = getelementptr inbounds i8, ptr %23, i64 1
  store ptr %26, ptr %13, align 8, !tbaa !22
  store i8 %25, ptr %23, align 1, !tbaa !28
  br label %27

27:                                               ; preds = %22, %20
  %28 = load ptr, ptr %13, align 8, !tbaa !22
  %29 = ptrtoint ptr %28 to i64
  %30 = ptrtoint ptr %3 to i64
  %31 = sub i64 %29, %30
  br label %32

32:                                               ; preds = %11, %27, %9
  %.0 = phi i64 [ %10, %9 ], [ %31, %27 ], [ 0, %11 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %6) #2
  ret i64 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i64 @deflate_compress_none(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !11, i64 24}
!6 = !{!"libdeflate_compressor", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !10, i64 32, !10, i64 36, !12, i64 40, !13, i64 1320, !14, i64 1408, !14, i64 3008, !8, i64 4608, !8, i64 6080}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"deflate_freqs", !8, i64 0, !8, i64 1152}
!13 = !{!"block_split_stats", !8, i64 0, !8, i64 40, !10, i64 80, !10, i64 84}
!14 = !{!"deflate_codes", !15, i64 0, !16, i64 1280}
!15 = !{!"deflate_codewords", !8, i64 0, !8, i64 1152}
!16 = !{!"deflate_lens", !8, i64 0, !8, i64 288}
!17 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!18 = !{!19, !11, i64 0}
!19 = !{!"deflate_output_bitstream", !11, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !20, i64 32}
!20 = !{!"_Bool", !8, i64 0}
!21 = !{!19, !10, i64 8}
!22 = !{!19, !7, i64 16}
!23 = !{!19, !7, i64 24}
!24 = !{!19, !20, i64 32}
!25 = !{!6, !7, i64 0}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass