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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

; 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 i32 @zinflate(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.z_stream_s, align 8
  %9 = alloca [16384 x i8], align 16
  %10 = alloca [16384 x i8], align 16
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 112, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 16384, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 16384, ptr %10) #4
  %12 = getelementptr inbounds %struct.z_stream_s, ptr %8, i32 0, i32 8
  store ptr null, ptr %12, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.z_stream_s, ptr %8, i32 0, i32 9
  store ptr null, ptr %13, align 8, !tbaa !13
  %14 = getelementptr inbounds %struct.z_stream_s, ptr %8, i32 0, i32 10
  store ptr null, ptr %14, align 8, !tbaa !14
  %15 = getelementptr inbounds %struct.z_stream_s, ptr %8, i32 0, i32 1
  store i32 0, ptr %15, align 8, !tbaa !15
  %16 = getelementptr inbounds %struct.z_stream_s, ptr %8, i32 0, i32 0
  store ptr null, ptr %16, align 8, !tbaa !16
  %17 = call i32 @inflateInit_(ptr noundef %8, ptr noundef @.str, i32 noundef 112)
  store i32 %17, ptr %6, align 4, !tbaa !17
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %2
  %20 = load i32, ptr %6, align 4, !tbaa !17
  store i32 %20, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %85

21:                                               ; preds = %2
  br label %22

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

31:                                               ; preds = %22
  %32 = call i32 @inflateEnd(ptr noundef %8)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %85

33:                                               ; preds = %22
  %34 = getelementptr inbounds %struct.z_stream_s, ptr %8, i32 0, i32 1
  %35 = load i32, ptr %34, align 8, !tbaa !15
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  br label %79

38:                                               ; preds = %33
  %39 = getelementptr inbounds [16384 x i8], ptr %9, i64 0, i64 0
  %40 = getelementptr inbounds %struct.z_stream_s, ptr %8, i32 0, i32 0
  store ptr %39, ptr %40, align 8, !tbaa !16
  br label %41

41:                                               ; preds = %70, %38
  %42 = getelementptr inbounds %struct.z_stream_s, ptr %8, i32 0, i32 4
  store i32 16384, ptr %42, align 8, !tbaa !18
  %43 = getelementptr inbounds [16384 x i8], ptr %10, i64 0, i64 0
  %44 = getelementptr inbounds %struct.z_stream_s, ptr %8, i32 0, i32 3
  store ptr %43, ptr %44, align 8, !tbaa !19
  %45 = call i32 @inflate(ptr noundef %8, i32 noundef 0)
  store i32 %45, ptr %6, align 4, !tbaa !17
  %46 = load i32, ptr %6, align 4, !tbaa !17
  switch i32 %46, label %51 [
    i32 2, label %47
    i32 -3, label %48
    i32 -4, label %48
  ]

47:                                               ; preds = %41
  store i32 -3, ptr %6, align 4, !tbaa !17
  br label %48

48:                                               ; preds = %47, %41, %41
  %49 = call i32 @inflateEnd(ptr noundef %8)
  %50 = load i32, ptr %6, align 4, !tbaa !17
  store i32 %50, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %85

51:                                               ; preds = %41
  %52 = getelementptr inbounds %struct.z_stream_s, ptr %8, i32 0, i32 4
  %53 = load i32, ptr %52, align 8, !tbaa !18
  %54 = sub i32 16384, %53
  store i32 %54, ptr %7, align 4, !tbaa !17
  %55 = getelementptr inbounds [16384 x i8], ptr %10, i64 0, i64 0
  %56 = load i32, ptr %7, align 4, !tbaa !17
  %57 = zext i32 %56 to i64
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = call i64 @fwrite(ptr noundef %55, i64 noundef 1, i64 noundef %57, ptr noundef %58)
  %60 = load i32, ptr %7, align 4, !tbaa !17
  %61 = zext i32 %60 to i64
  %62 = icmp ne i64 %59, %61
  br i1 %62, label %67, label %63

63:                                               ; preds = %51
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = call i32 @ferror(ptr noundef %64) #4
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %69

67:                                               ; preds = %63, %51
  %68 = call i32 @inflateEnd(ptr noundef %8)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %85

69:                                               ; preds = %63
  br label %70

70:                                               ; preds = %69
  %71 = getelementptr inbounds %struct.z_stream_s, ptr %8, i32 0, i32 4
  %72 = load i32, ptr %71, align 8, !tbaa !18
  %73 = icmp ne i32 %72, 0
  %74 = xor i1 %73, true
  br i1 %74, label %41, label %75, !llvm.loop !20

75:                                               ; preds = %70
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %6, align 4, !tbaa !17
  %78 = icmp ne i32 %77, 1
  br i1 %78, label %22, label %79, !llvm.loop !22

79:                                               ; preds = %76, %37
  %80 = call i32 @inflateEnd(ptr noundef %8)
  %81 = load i32, ptr %6, align 4, !tbaa !17
  %82 = icmp eq i32 %81, 1
  %83 = zext i1 %82 to i64
  %84 = select i1 %82, i32 0, i32 -3
  store i32 %84, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %85

85:                                               ; preds = %79, %67, %48, %31, %19
  call void @llvm.lifetime.end.p0(i64 16384, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 16384, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 112, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %86 = load i32, ptr %3, align 4
  ret i32 %86
}

declare i32 @inflateInit_(ptr noundef, ptr noundef, i32 noundef) #1

declare i32 @inflateEnd(ptr noundef) #1

declare i32 @inflate(ptr noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 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, !6, i64 64}
!10 = !{!"z_stream_s", !6, i64 0, !11, i64 8, !12, i64 16, !6, i64 24, !11, i64 32, !12, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !11, i64 88, !12, i64 96, !12, i64 104}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !6, i64 72}
!14 = !{!10, !6, i64 80}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !6, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !11, i64 32}
!19 = !{!10, !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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nofree nounwind memory(read)
declare noundef i32 @ferror(ptr nocapture 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 #1

; 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 i32 @zinflate(ptr nocapture noundef %0, ptr nocapture noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.z_stream_s, align 8
  %4 = alloca [16384 x i8], align 16
  %5 = alloca [16384 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 16384, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 16384, ptr nonnull %5) #6
  %6 = getelementptr inbounds i8, ptr %3, i64 64
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 0, ptr %7, align 8, !tbaa !5
  store ptr null, ptr %3, align 8, !tbaa !12
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %6, i8 0, i64 24, i1 false)
  %8 = call i32 @inflateInit_(ptr noundef nonnull %3, ptr noundef nonnull @.str, i32 noundef 112) #6
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %.preheader, label %30

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

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

15:                                               ; preds = %11
  %.not17 = icmp eq i32 %13, 0
  br i1 %.not17, label %.sink.split, label %16

16:                                               ; preds = %15
  store ptr %4, ptr %3, align 8, !tbaa !12
  br label %17

17:                                               ; preds = %26, %16
  store i32 16384, ptr %9, align 8, !tbaa !13
  store ptr %5, ptr %10, align 8, !tbaa !14
  %18 = call i32 @inflate(ptr noundef nonnull %3, i32 noundef 0) #6
  switch i32 %18, label %19 [
    i32 2, label %.sink.split
    i32 -3, label %.sink.split.loopexit37
    i32 -4, label %.sink.split.loopexit37
  ]

19:                                               ; preds = %17
  %20 = load i32, ptr %9, align 8, !tbaa !13
  %21 = sub i32 16384, %20
  %22 = zext i32 %21 to i64
  %23 = call i64 @fwrite(ptr noundef nonnull %5, i64 noundef 1, i64 noundef %22, ptr noundef %1)
  %.not18 = icmp eq i64 %23, %22
  br i1 %.not18, label %24, label %.sink.split

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

26:                                               ; preds = %24
  %27 = load i32, ptr %9, align 8, !tbaa !13
  %.not20 = icmp eq i32 %27, 0
  br i1 %.not20, label %17, label %28, !llvm.loop !15

28:                                               ; preds = %26
  %.not21 = icmp eq i32 %18, 1
  br i1 %.not21, label %.sink.split, label %11, !llvm.loop !17

.sink.split.loopexit37:                           ; preds = %17, %17
  br label %.sink.split

.sink.split:                                      ; preds = %15, %28, %11, %19, %24, %17, %.sink.split.loopexit37
  %.0.ph = phi i32 [ -3, %17 ], [ -1, %24 ], [ -1, %19 ], [ %18, %.sink.split.loopexit37 ], [ -1, %11 ], [ 0, %28 ], [ -3, %15 ]
  %29 = call i32 @inflateEnd(ptr noundef nonnull %3) #6
  br label %30

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

declare i32 @inflateInit_(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

declare i32 @inflateEnd(ptr noundef) local_unnamed_addr #4

declare i32 @inflate(ptr noundef, i32 noundef) local_unnamed_addr #4

; 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 = { "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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass