; LLVM IR from Farama-Foundation/stable-retro :: cores/32x/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"

%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 [6 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @compress2(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.z_stream_s, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 112, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.z_stream_s, ptr %12, i32 0, i32 0
  store ptr %15, ptr %16, align 8, !tbaa !13
  %17 = load i64, ptr %10, align 8, !tbaa !9
  %18 = trunc i64 %17 to i32
  %19 = getelementptr inbounds %struct.z_stream_s, ptr %12, i32 0, i32 1
  store i32 %18, ptr %19, align 8, !tbaa !15
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.z_stream_s, ptr %12, i32 0, i32 3
  store ptr %20, ptr %21, align 8, !tbaa !16
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = trunc i64 %23 to i32
  %25 = getelementptr inbounds %struct.z_stream_s, ptr %12, i32 0, i32 4
  store i32 %24, ptr %25, align 8, !tbaa !17
  %26 = getelementptr inbounds %struct.z_stream_s, ptr %12, i32 0, i32 4
  %27 = load i32, ptr %26, align 8, !tbaa !17
  %28 = zext i32 %27 to i64
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = icmp ne i64 %28, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %5
  store i32 -5, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %62

33:                                               ; preds = %5
  %34 = getelementptr inbounds %struct.z_stream_s, ptr %12, i32 0, i32 8
  store ptr null, ptr %34, align 8, !tbaa !18
  %35 = getelementptr inbounds %struct.z_stream_s, ptr %12, i32 0, i32 9
  store ptr null, ptr %35, align 8, !tbaa !19
  %36 = getelementptr inbounds %struct.z_stream_s, ptr %12, i32 0, i32 10
  store ptr null, ptr %36, align 8, !tbaa !20
  %37 = load i32, ptr %11, align 4, !tbaa !11
  %38 = call i32 @deflateInit_(ptr noundef %12, i32 noundef %37, ptr noundef @.str, i32 noundef 112)
  store i32 %38, ptr %13, align 4, !tbaa !11
  %39 = load i32, ptr %13, align 4, !tbaa !11
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %33
  %42 = load i32, ptr %13, align 4, !tbaa !11
  store i32 %42, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %62

43:                                               ; preds = %33
  %44 = call i32 @deflate(ptr noundef %12, i32 noundef 4)
  store i32 %44, ptr %13, align 4, !tbaa !11
  %45 = load i32, ptr %13, align 4, !tbaa !11
  %46 = icmp ne i32 %45, 1
  br i1 %46, label %47, label %56

47:                                               ; preds = %43
  %48 = call i32 @deflateEnd(ptr noundef %12)
  %49 = load i32, ptr %13, align 4, !tbaa !11
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %47
  br label %54

52:                                               ; preds = %47
  %53 = load i32, ptr %13, align 4, !tbaa !11
  br label %54

54:                                               ; preds = %52, %51
  %55 = phi i32 [ -5, %51 ], [ %53, %52 ]
  store i32 %55, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %62

56:                                               ; preds = %43
  %57 = getelementptr inbounds %struct.z_stream_s, ptr %12, i32 0, i32 5
  %58 = load i64, ptr %57, align 8, !tbaa !21
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %58, ptr %59, align 8, !tbaa !9
  %60 = call i32 @deflateEnd(ptr noundef %12)
  store i32 %60, ptr %13, align 4, !tbaa !11
  %61 = load i32, ptr %13, align 4, !tbaa !11
  store i32 %61, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %62

62:                                               ; preds = %56, %54, %41, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 112, ptr %12) #3
  %63 = load i32, ptr %6, align 4
  ret i32 %63
}

; 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 i32 @deflate(ptr noundef, i32 noundef) #2

declare i32 @deflateEnd(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 }

!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 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"z_stream_s", !6, i64 0, !12, i64 8, !10, i64 16, !6, i64 24, !12, i64 32, !10, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !12, i64 88, !10, i64 96, !10, i64 104}
!15 = !{!14, !12, i64 8}
!16 = !{!14, !6, i64 24}
!17 = !{!14, !12, i64 32}
!18 = !{!14, !6, i64 64}
!19 = !{!14, !6, i64 72}
!20 = !{!14, !6, i64 80}
!21 = !{!14, !10, 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"

%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 [6 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @compress2(ptr noundef %0, ptr nocapture noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = alloca %struct.z_stream_s, align 8
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %6) #4
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = trunc i64 %3 to i32
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %7, ptr %8, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %6, i64 24
  store ptr %0, ptr %9, align 8, !tbaa !13
  %10 = load i64, ptr %1, align 8, !tbaa !14
  %11 = trunc i64 %10 to i32
  %12 = getelementptr inbounds i8, ptr %6, i64 32
  store i32 %11, ptr %12, align 8, !tbaa !15
  %.not = icmp ult i64 %10, 4294967296
  br i1 %.not, label %13, label %26

13:                                               ; preds = %5
  %14 = getelementptr inbounds i8, ptr %6, i64 64
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %14, i8 0, i64 24, i1 false)
  %15 = call i32 @deflateInit_(ptr noundef nonnull %6, i32 noundef %4, ptr noundef nonnull @.str, i32 noundef 112) #4
  %.not15 = icmp eq i32 %15, 0
  br i1 %.not15, label %16, label %26

16:                                               ; preds = %13
  %17 = call i32 @deflate(ptr noundef nonnull %6, i32 noundef 4) #4
  %.not16 = icmp eq i32 %17, 1
  br i1 %.not16, label %22, label %18

18:                                               ; preds = %16
  %19 = call i32 @deflateEnd(ptr noundef nonnull %6) #4
  %20 = icmp eq i32 %17, 0
  %21 = select i1 %20, i32 -5, i32 %17
  br label %26

22:                                               ; preds = %16
  %23 = getelementptr inbounds i8, ptr %6, i64 40
  %24 = load i64, ptr %23, align 8, !tbaa !16
  store i64 %24, ptr %1, align 8, !tbaa !14
  %25 = call i32 @deflateEnd(ptr noundef nonnull %6) #4
  br label %26

26:                                               ; preds = %13, %5, %22, %18
  %.0 = phi i32 [ %21, %18 ], [ %25, %22 ], [ -5, %5 ], [ %15, %13 ]
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %6) #4
  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

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

declare i32 @deflateEnd(ptr noundef) local_unnamed_addr #2

; 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) #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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!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, !10, i64 8}
!13 = !{!6, !7, i64 24}
!14 = !{!11, !11, i64 0}
!15 = !{!6, !10, i64 32}
!16 = !{!6, !11, i64 40}


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