; LLVM IR from artagnon/phoenixfs :: compress (zdeflate)

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

@.str = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @zdeflate(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct.z_stream_s, align 8
  %12 = alloca [16384 x i8], align 16
  %13 = alloca [16384 x i8], align 16
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 112, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 16384, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 16384, ptr %13) #4
  %15 = getelementptr inbounds %struct.z_stream_s, ptr %11, i32 0, i32 8
  store ptr null, ptr %15, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct.z_stream_s, ptr %11, i32 0, i32 9
  store ptr null, ptr %16, align 8, !tbaa !14
  %17 = getelementptr inbounds %struct.z_stream_s, ptr %11, i32 0, i32 10
  store ptr null, ptr %17, align 8, !tbaa !15
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = call i32 @deflateInit_(ptr noundef %11, i32 noundef %18, ptr noundef @.str, i32 noundef 112)
  store i32 %19, ptr %8, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %3
  %22 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %22, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %78

23:                                               ; preds = %3
  br label %24

24:                                               ; preds = %73, %23
  %25 = getelementptr inbounds [16384 x i8], ptr %12, i64 0, i64 0
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call i64 @fread(ptr noundef %25, i64 noundef 1, i64 noundef 16384, ptr noundef %26)
  %28 = trunc i64 %27 to i32
  %29 = getelementptr inbounds %struct.z_stream_s, ptr %11, i32 0, i32 1
  store i32 %28, ptr %29, align 8, !tbaa !16
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call i32 @ferror(ptr noundef %30) #4
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %24
  %34 = call i32 @deflateEnd(ptr noundef %11)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %78

35:                                               ; preds = %24
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call i32 @feof(ptr noundef %36) #4
  %38 = icmp ne i32 %37, 0
  %39 = zext i1 %38 to i64
  %40 = select i1 %38, i32 4, i32 0
  store i32 %40, ptr %9, align 4, !tbaa !9
  %41 = getelementptr inbounds [16384 x i8], ptr %12, i64 0, i64 0
  %42 = getelementptr inbounds %struct.z_stream_s, ptr %11, i32 0, i32 0
  store ptr %41, ptr %42, align 8, !tbaa !17
  br label %43

43:                                               ; preds = %67, %35
  %44 = getelementptr inbounds %struct.z_stream_s, ptr %11, i32 0, i32 4
  store i32 16384, ptr %44, align 8, !tbaa !18
  %45 = getelementptr inbounds [16384 x i8], ptr %13, i64 0, i64 0
  %46 = getelementptr inbounds %struct.z_stream_s, ptr %11, i32 0, i32 3
  store ptr %45, ptr %46, align 8, !tbaa !19
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = call i32 @deflate(ptr noundef %11, i32 noundef %47)
  store i32 %48, ptr %8, align 4, !tbaa !9
  %49 = getelementptr inbounds %struct.z_stream_s, ptr %11, i32 0, i32 4
  %50 = load i32, ptr %49, align 8, !tbaa !18
  %51 = sub i32 16384, %50
  store i32 %51, ptr %10, align 4, !tbaa !9
  %52 = getelementptr inbounds [16384 x i8], ptr %13, i64 0, i64 0
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = zext i32 %53 to i64
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = call i64 @fwrite(ptr noundef %52, i64 noundef 1, i64 noundef %54, ptr noundef %55)
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = zext i32 %57 to i64
  %59 = icmp ne i64 %56, %58
  br i1 %59, label %64, label %60

60:                                               ; preds = %43
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = call i32 @ferror(ptr noundef %61) #4
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %66

64:                                               ; preds = %60, %43
  %65 = call i32 @deflateEnd(ptr noundef %11)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %78

66:                                               ; preds = %60
  br label %67

67:                                               ; preds = %66
  %68 = getelementptr inbounds %struct.z_stream_s, ptr %11, i32 0, i32 4
  %69 = load i32, ptr %68, align 8, !tbaa !18
  %70 = icmp ne i32 %69, 0
  %71 = xor i1 %70, true
  br i1 %71, label %43, label %72, !llvm.loop !20

72:                                               ; preds = %67
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = icmp ne i32 %74, 4
  br i1 %75, label %24, label %76, !llvm.loop !22

76:                                               ; preds = %73
  %77 = call i32 @deflateEnd(ptr noundef %11)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %78

78:                                               ; preds = %76, %64, %33, %21
  call void @llvm.lifetime.end.p0(i64 16384, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 16384, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 112, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %79 = load i32, ptr %4, align 4
  ret i32 %79
}

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

declare i32 @deflateInit_(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind
declare i32 @ferror(ptr noundef) #3

declare i32 @deflateEnd(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @feof(ptr noundef) #3

declare i32 @deflate(ptr noundef, i32 noundef) #2

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr 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 = { nounwind "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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 64}
!12 = !{!"z_stream_s", !6, i64 0, !10, i64 8, !13, i64 16, !6, i64 24, !10, i64 32, !13, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !13, i64 96, !13, i64 104}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 72}
!15 = !{!12, !6, i64 80}
!16 = !{!12, !10, i64 8}
!17 = !{!12, !6, i64 0}
!18 = !{!12, !10, i64 32}
!19 = !{!12, !6, i64 24}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


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

@.str = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @zdeflate(ptr nocapture noundef %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.z_stream_s, align 8
  %5 = alloca [16384 x i8], align 16
  %6 = alloca [16384 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 16384, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 16384, ptr nonnull %6) #6
  %7 = getelementptr inbounds i8, ptr %4, i64 64
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %7, i8 0, i64 24, i1 false)
  %8 = call i32 @deflateInit_(ptr noundef nonnull %4, i32 noundef %2, ptr noundef nonnull @.str, i32 noundef 112) #6
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %.preheader, label %31

.preheader:                                       ; preds = %3
  %9 = getelementptr inbounds i8, ptr %4, i64 8
  %10 = getelementptr inbounds i8, ptr %4, i64 32
  %11 = getelementptr inbounds i8, ptr %4, i64 24
  br label %12

12:                                               ; preds = %.preheader, %29
  %13 = call i64 @fread(ptr noundef nonnull %5, i64 noundef 1, i64 noundef 16384, ptr noundef %0)
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %9, align 8, !tbaa !5
  %15 = call i32 @ferror(ptr noundef %0) #6
  %.not12 = icmp eq i32 %15, 0
  br i1 %.not12, label %16, label %.sink.split

16:                                               ; preds = %12
  %17 = call i32 @feof(ptr noundef %0) #6
  %.not13 = icmp eq i32 %17, 0
  %18 = select i1 %.not13, i32 0, i32 4
  store ptr %5, ptr %4, align 8, !tbaa !12
  br label %19

19:                                               ; preds = %27, %16
  store i32 16384, ptr %10, align 8, !tbaa !13
  store ptr %6, ptr %11, align 8, !tbaa !14
  %20 = call i32 @deflate(ptr noundef nonnull %4, i32 noundef %18) #6
  %21 = load i32, ptr %10, align 8, !tbaa !13
  %22 = sub i32 16384, %21
  %23 = zext i32 %22 to i64
  %24 = call i64 @fwrite(ptr noundef nonnull %6, i64 noundef 1, i64 noundef %23, ptr noundef %1)
  %.not14 = icmp eq i64 %24, %23
  br i1 %.not14, label %25, label %.sink.split

25:                                               ; preds = %19
  %26 = call i32 @ferror(ptr noundef %1) #6
  %.not15 = icmp eq i32 %26, 0
  br i1 %.not15, label %27, label %.sink.split

27:                                               ; preds = %25
  %28 = load i32, ptr %10, align 8, !tbaa !13
  %.not16 = icmp eq i32 %28, 0
  br i1 %.not16, label %19, label %29, !llvm.loop !15

29:                                               ; preds = %27
  br i1 %.not13, label %12, label %.sink.split, !llvm.loop !17

.sink.split:                                      ; preds = %29, %12, %19, %25
  %.0.ph = phi i32 [ -1, %25 ], [ -1, %19 ], [ -1, %12 ], [ 0, %29 ]
  %30 = call i32 @deflateEnd(ptr noundef nonnull %4) #6
  br label %31

31:                                               ; preds = %.sink.split, %3
  %.0 = phi i32 [ %8, %3 ], [ %.0.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 16384, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 16384, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %4) #6
  ret i32 %.0
}

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

declare i32 @deflateInit_(ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind memory(read)
declare noundef i32 @ferror(ptr nocapture noundef) local_unnamed_addr #4

declare i32 @deflateEnd(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @feof(ptr nocapture noundef) local_unnamed_addr #3

declare i32 @deflate(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #3

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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 = { "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 = { nofree nounwind "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 = { nofree nounwind memory(read) "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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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, !10, i64 8}
!6 = !{!"z_stream_s", !7, i64 0, !10, i64 8, !11, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !10, i64 88, !11, i64 96, !11, i64 104}
!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 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 32}
!14 = !{!6, !7, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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