; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.1/squashfs-tools (gzip_wrapper)

; 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 @gzip_compress(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %18, ptr %15, align 8, !tbaa !5
  %19 = load ptr, ptr %15, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %38

21:                                               ; preds = %6
  %22 = call noalias ptr @malloc(i64 noundef 112) #5
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %22, ptr %23, align 8, !tbaa !5
  store ptr %22, ptr %15, align 8, !tbaa !5
  %24 = icmp eq ptr %22, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  br label %71

26:                                               ; preds = %21
  %27 = load ptr, ptr %15, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.z_stream_s, ptr %27, i32 0, i32 8
  store ptr null, ptr %28, align 8, !tbaa !11
  %29 = load ptr, ptr %15, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.z_stream_s, ptr %29, i32 0, i32 9
  store ptr null, ptr %30, align 8, !tbaa !14
  %31 = load ptr, ptr %15, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.z_stream_s, ptr %31, i32 0, i32 10
  store ptr null, ptr %32, align 8, !tbaa !15
  %33 = load ptr, ptr %15, align 8, !tbaa !5
  %34 = call i32 @deflateInit_(ptr noundef %33, i32 noundef 9, ptr noundef @.str, i32 noundef 112)
  store i32 %34, ptr %14, align 4, !tbaa !9
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %26
  br label %71

37:                                               ; preds = %26
  br label %44

38:                                               ; preds = %6
  %39 = load ptr, ptr %15, align 8, !tbaa !5
  %40 = call i32 @deflateReset(ptr noundef %39)
  store i32 %40, ptr %14, align 4, !tbaa !9
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %38
  br label %71

43:                                               ; preds = %38
  br label %44

44:                                               ; preds = %43, %37
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = load ptr, ptr %15, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.z_stream_s, ptr %46, i32 0, i32 0
  store ptr %45, ptr %47, align 8, !tbaa !16
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = load ptr, ptr %15, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.z_stream_s, ptr %49, i32 0, i32 1
  store i32 %48, ptr %50, align 8, !tbaa !17
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %15, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.z_stream_s, ptr %52, i32 0, i32 3
  store ptr %51, ptr %53, align 8, !tbaa !18
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = load ptr, ptr %15, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.z_stream_s, ptr %55, i32 0, i32 4
  store i32 %54, ptr %56, align 8, !tbaa !19
  %57 = load ptr, ptr %15, align 8, !tbaa !5
  %58 = call i32 @deflate(ptr noundef %57, i32 noundef 4)
  store i32 %58, ptr %14, align 4, !tbaa !9
  %59 = load i32, ptr %14, align 4, !tbaa !9
  %60 = icmp eq i32 %59, 1
  br i1 %60, label %61, label %66

61:                                               ; preds = %44
  %62 = load ptr, ptr %15, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.z_stream_s, ptr %62, i32 0, i32 5
  %64 = load i64, ptr %63, align 8, !tbaa !20
  %65 = trunc i64 %64 to i32
  store i32 %65, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %74

66:                                               ; preds = %44
  %67 = load i32, ptr %14, align 4, !tbaa !9
  %68 = icmp eq i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %66
  store i32 0, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %74

70:                                               ; preds = %66
  br label %71

71:                                               ; preds = %70, %42, %36, %25
  %72 = load i32, ptr %14, align 4, !tbaa !9
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %72, ptr %73, align 4, !tbaa !9
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %74

74:                                               ; preds = %71, %69, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %75 = load i32, ptr %7, align 4
  ret i32 %75
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

declare i32 @deflateReset(ptr noundef) #3

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

; 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 = { nounwind allocsize(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 = { "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 }
attributes #5 = { nounwind allocsize(0) }

!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, !6, i64 0}
!17 = !{!12, !10, i64 8}
!18 = !{!12, !6, i64 24}
!19 = !{!12, !10, i64 32}
!20 = !{!12, !13, i64 40}


; 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"

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gzip_compress(ptr nocapture noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %15

9:                                                ; preds = %6
  %10 = tail call noalias dereferenceable_or_null(112) ptr @malloc(i64 noundef 112) #4
  store ptr %10, ptr %0, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %26, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %10, i64 64
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %13, i8 0, i64 24, i1 false)
  %14 = tail call i32 @deflateInit_(ptr noundef nonnull %10, i32 noundef 9, ptr noundef nonnull @.str, i32 noundef 112) #5
  %.not29 = icmp eq i32 %14, 0
  br i1 %.not29, label %17, label %26

15:                                               ; preds = %6
  %16 = tail call i32 @deflateReset(ptr noundef nonnull %7) #5
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %17, label %26

17:                                               ; preds = %15, %12
  %.0 = phi ptr [ %10, %12 ], [ %7, %15 ]
  store ptr %2, ptr %.0, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %.0, i64 8
  store i32 %3, ptr %18, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %.0, i64 24
  store ptr %1, ptr %19, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %.0, i64 32
  store i32 %4, ptr %20, align 8, !tbaa !15
  %21 = tail call i32 @deflate(ptr noundef nonnull %.0, i32 noundef 4) #5
  switch i32 %21, label %26 [
    i32 1, label %22
    i32 0, label %27
  ]

22:                                               ; preds = %17
  %23 = getelementptr inbounds i8, ptr %.0, i64 40
  %24 = load i64, ptr %23, align 8, !tbaa !16
  %25 = trunc i64 %24 to i32
  br label %27

26:                                               ; preds = %17, %15, %12, %9
  %.022 = phi i32 [ 0, %9 ], [ %14, %12 ], [ %16, %15 ], [ %21, %17 ]
  store i32 %.022, ptr %5, align 4, !tbaa !17
  br label %27

27:                                               ; preds = %17, %26, %22
  %.023 = phi i32 [ -1, %26 ], [ %25, %22 ], [ %21, %17 ]
  ret i32 %.023
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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

declare i32 @deflateReset(ptr noundef) local_unnamed_addr #2

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

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

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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { 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 0}
!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, !11, i64 8}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !11, i64 32}
!16 = !{!10, !12, i64 40}
!17 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass