; LLVM IR from ebiggers/libdeflate :: lib (zlib_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"

; Function Attrs: nounwind uwtable
define dso_local i64 @libdeflate_zlib_compress(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) #0 {
  %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 ptr, align 8
  %13 = alloca i16, align 2
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i64, align 8
  %17 = 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 8, ptr %12) #4
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %18, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %19 = load i64, ptr %11, align 8, !tbaa !9
  %20 = icmp ule i64 %19, 6
  br i1 %20, label %21, label %22

21:                                               ; preds = %5
  store i64 0, ptr %6, align 8
  store i32 1, ptr %17, align 4
  br label %83

22:                                               ; preds = %5
  store i16 30720, ptr %13, align 2, !tbaa !11
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = call i32 @libdeflate_get_compression_level(ptr noundef %23)
  store i32 %24, ptr %14, align 4, !tbaa !13
  %25 = load i32, ptr %14, align 4, !tbaa !13
  %26 = icmp ult i32 %25, 2
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  store i32 0, ptr %15, align 4, !tbaa !13
  br label %39

28:                                               ; preds = %22
  %29 = load i32, ptr %14, align 4, !tbaa !13
  %30 = icmp ult i32 %29, 6
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  store i32 1, ptr %15, align 4, !tbaa !13
  br label %38

32:                                               ; preds = %28
  %33 = load i32, ptr %14, align 4, !tbaa !13
  %34 = icmp ult i32 %33, 8
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  store i32 2, ptr %15, align 4, !tbaa !13
  br label %37

36:                                               ; preds = %32
  store i32 3, ptr %15, align 4, !tbaa !13
  br label %37

37:                                               ; preds = %36, %35
  br label %38

38:                                               ; preds = %37, %31
  br label %39

39:                                               ; preds = %38, %27
  %40 = load i32, ptr %15, align 4, !tbaa !13
  %41 = shl i32 %40, 6
  %42 = load i16, ptr %13, align 2, !tbaa !11
  %43 = zext i16 %42 to i32
  %44 = or i32 %43, %41
  %45 = trunc i32 %44 to i16
  store i16 %45, ptr %13, align 2, !tbaa !11
  %46 = load i16, ptr %13, align 2, !tbaa !11
  %47 = zext i16 %46 to i32
  %48 = srem i32 %47, 31
  %49 = sub nsw i32 31, %48
  %50 = load i16, ptr %13, align 2, !tbaa !11
  %51 = zext i16 %50 to i32
  %52 = or i32 %51, %49
  %53 = trunc i32 %52 to i16
  store i16 %53, ptr %13, align 2, !tbaa !11
  %54 = load i16, ptr %13, align 2, !tbaa !11
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  call void @put_unaligned_be16(i16 noundef zeroext %54, ptr noundef %55)
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 2
  store ptr %57, ptr %12, align 8, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load i64, ptr %9, align 8, !tbaa !9
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = load i64, ptr %11, align 8, !tbaa !9
  %63 = sub i64 %62, 6
  %64 = call i64 @libdeflate_deflate_compress(ptr noundef %58, ptr noundef %59, i64 noundef %60, ptr noundef %61, i64 noundef %63)
  store i64 %64, ptr %16, align 8, !tbaa !9
  %65 = load i64, ptr %16, align 8, !tbaa !9
  %66 = icmp eq i64 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %39
  store i64 0, ptr %6, align 8
  store i32 1, ptr %17, align 4
  br label %83

68:                                               ; preds = %39
  %69 = load i64, ptr %16, align 8, !tbaa !9
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 %69
  store ptr %71, ptr %12, align 8, !tbaa !5
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load i64, ptr %9, align 8, !tbaa !9
  %74 = call i32 @libdeflate_adler32(i32 noundef 1, ptr noundef %72, i64 noundef %73)
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  call void @put_unaligned_be32(i32 noundef %74, ptr noundef %75)
  %76 = load ptr, ptr %12, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i64 4
  store ptr %77, ptr %12, align 8, !tbaa !5
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = ptrtoint ptr %78 to i64
  %81 = ptrtoint ptr %79 to i64
  %82 = sub i64 %80, %81
  store i64 %82, ptr %6, align 8
  store i32 1, ptr %17, align 4
  br label %83

83:                                               ; preds = %68, %67, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %84 = load i64, ptr %6, align 8
  ret i64 %84
}

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

declare i32 @libdeflate_get_compression_level(ptr noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @put_unaligned_be16(i16 noundef zeroext, ptr noundef) #3

declare i64 @libdeflate_deflate_compress(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @put_unaligned_be32(i32 noundef, ptr noundef) #3

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

; 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 = { "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 = { alwaysinline 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 #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !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"

; Function Attrs: nounwind uwtable
define dso_local i64 @libdeflate_zlib_compress(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = icmp ult i64 %4, 7
  br i1 %6, label %30, label %7

7:                                                ; preds = %5
  %8 = tail call i32 @libdeflate_get_compression_level(ptr noundef %0) #3
  %9 = icmp ult i32 %8, 2
  br i1 %9, label %15, label %10

10:                                               ; preds = %7
  %11 = icmp ult i32 %8, 6
  br i1 %11, label %15, label %12

12:                                               ; preds = %10
  %13 = icmp ult i32 %8, 8
  %14 = select i1 %13, i16 30848, i16 30912
  br label %15

15:                                               ; preds = %12, %10, %7
  %.027 = phi i16 [ 30720, %7 ], [ 30784, %10 ], [ %14, %12 ]
  %16 = urem i16 %.027, 31
  %17 = or disjoint i16 %16, %.027
  %18 = xor i16 %17, 31
  tail call void @put_unaligned_be16(i16 noundef zeroext %18, ptr noundef %3)
  %19 = getelementptr inbounds i8, ptr %3, i64 2
  %20 = add i64 %4, -6
  %21 = tail call i64 @libdeflate_deflate_compress(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull %19, i64 noundef %20) #3
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %30, label %23

23:                                               ; preds = %15
  %24 = getelementptr inbounds i8, ptr %19, i64 %21
  %25 = tail call i32 @libdeflate_adler32(i32 noundef 1, ptr noundef %1, i64 noundef %2) #3
  tail call void @put_unaligned_be32(i32 noundef %25, ptr noundef nonnull %24)
  %26 = getelementptr inbounds i8, ptr %24, i64 4
  %27 = ptrtoint ptr %26 to i64
  %28 = ptrtoint ptr %3 to i64
  %29 = sub i64 %27, %28
  br label %30

30:                                               ; preds = %15, %5, %23
  %.0 = phi i64 [ %29, %23 ], [ 0, %5 ], [ 0, %15 ]
  ret i64 %.0
}

declare i32 @libdeflate_get_compression_level(ptr noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @put_unaligned_be16(i16 noundef zeroext, ptr noundef) local_unnamed_addr #2

declare i64 @libdeflate_deflate_compress(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @put_unaligned_be32(i32 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @libdeflate_adler32(i32 noundef, ptr noundef, i64 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 = { alwaysinline 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 = { 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)"}


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