; LLVM IR from Farama-Foundation/stable-retro :: cores/32x/zlib (uncompr)

; 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 @uncompress(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca %struct.z_stream_s, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 112, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.z_stream_s, ptr %10, i32 0, i32 0
  store ptr %13, ptr %14, align 8, !tbaa !11
  %15 = load i64, ptr %9, align 8, !tbaa !9
  %16 = trunc i64 %15 to i32
  %17 = getelementptr inbounds %struct.z_stream_s, ptr %10, i32 0, i32 1
  store i32 %16, ptr %17, align 8, !tbaa !14
  %18 = getelementptr inbounds %struct.z_stream_s, ptr %10, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = zext i32 %19 to i64
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = icmp ne i64 %20, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %4
  store i32 -5, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %70

24:                                               ; preds = %4
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.z_stream_s, ptr %10, i32 0, i32 3
  store ptr %25, ptr %26, align 8, !tbaa !15
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = trunc i64 %28 to i32
  %30 = getelementptr inbounds %struct.z_stream_s, ptr %10, i32 0, i32 4
  store i32 %29, ptr %30, align 8, !tbaa !16
  %31 = getelementptr inbounds %struct.z_stream_s, ptr %10, i32 0, i32 4
  %32 = load i32, ptr %31, align 8, !tbaa !16
  %33 = zext i32 %32 to i64
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = icmp ne i64 %33, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %24
  store i32 -5, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %70

38:                                               ; preds = %24
  %39 = getelementptr inbounds %struct.z_stream_s, ptr %10, i32 0, i32 8
  store ptr null, ptr %39, align 8, !tbaa !17
  %40 = getelementptr inbounds %struct.z_stream_s, ptr %10, i32 0, i32 9
  store ptr null, ptr %40, align 8, !tbaa !18
  %41 = call i32 @inflateInit_(ptr noundef %10, ptr noundef @.str, i32 noundef 112)
  store i32 %41, ptr %11, align 4, !tbaa !19
  %42 = load i32, ptr %11, align 4, !tbaa !19
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %38
  %45 = load i32, ptr %11, align 4, !tbaa !19
  store i32 %45, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %70

46:                                               ; preds = %38
  %47 = call i32 @inflate(ptr noundef %10, i32 noundef 4)
  store i32 %47, ptr %11, align 4, !tbaa !19
  %48 = load i32, ptr %11, align 4, !tbaa !19
  %49 = icmp ne i32 %48, 1
  br i1 %49, label %50, label %64

50:                                               ; preds = %46
  %51 = call i32 @inflateEnd(ptr noundef %10)
  %52 = load i32, ptr %11, align 4, !tbaa !19
  %53 = icmp eq i32 %52, 2
  br i1 %53, label %61, label %54

54:                                               ; preds = %50
  %55 = load i32, ptr %11, align 4, !tbaa !19
  %56 = icmp eq i32 %55, -5
  br i1 %56, label %57, label %62

57:                                               ; preds = %54
  %58 = getelementptr inbounds %struct.z_stream_s, ptr %10, i32 0, i32 1
  %59 = load i32, ptr %58, align 8, !tbaa !14
  %60 = icmp eq i32 %59, 0
  br i1 %60, label %61, label %62

61:                                               ; preds = %57, %50
  store i32 -3, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %70

62:                                               ; preds = %57, %54
  %63 = load i32, ptr %11, align 4, !tbaa !19
  store i32 %63, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %70

64:                                               ; preds = %46
  %65 = getelementptr inbounds %struct.z_stream_s, ptr %10, i32 0, i32 5
  %66 = load i64, ptr %65, align 8, !tbaa !20
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %66, ptr %67, align 8, !tbaa !9
  %68 = call i32 @inflateEnd(ptr noundef %10)
  store i32 %68, ptr %11, align 4, !tbaa !19
  %69 = load i32, ptr %11, align 4, !tbaa !19
  store i32 %69, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %70

70:                                               ; preds = %64, %62, %61, %44, %37, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 112, ptr %10) #3
  %71 = load i32, ptr %5, align 4
  ret i32 %71
}

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

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

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

declare i32 @inflateEnd(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, !6, i64 0}
!12 = !{!"z_stream_s", !6, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !10, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !13, i64 88, !10, i64 96, !10, i64 104}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!12, !6, i64 24}
!16 = !{!12, !13, i64 32}
!17 = !{!12, !6, i64 64}
!18 = !{!12, !6, i64 72}
!19 = !{!13, !13, i64 0}
!20 = !{!12, !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 @uncompress(ptr noundef %0, ptr nocapture noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.z_stream_s, align 8
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %5) #4
  store ptr %2, ptr %5, align 8, !tbaa !5
  %6 = trunc i64 %3 to i32
  %7 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %6, ptr %7, align 8, !tbaa !12
  %.not = icmp ult i64 %3, 4294967296
  br i1 %.not, label %8, label %29

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %5, 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 %5, i64 32
  store i32 %11, ptr %12, align 8, !tbaa !15
  %.not18 = icmp ult i64 %10, 4294967296
  br i1 %.not18, label %13, label %29

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

16:                                               ; preds = %13
  %17 = call i32 @inflate(ptr noundef nonnull %5, i32 noundef 4) #4
  %.not20 = icmp eq i32 %17, 1
  br i1 %.not20, label %25, label %18

18:                                               ; preds = %16
  %19 = call i32 @inflateEnd(ptr noundef nonnull %5) #4
  %20 = icmp eq i32 %17, 2
  br i1 %20, label %29, label %21

21:                                               ; preds = %18
  %22 = icmp eq i32 %17, -5
  %23 = load i32, ptr %7, align 8
  %24 = icmp eq i32 %23, 0
  %or.cond = select i1 %22, i1 %24, i1 false
  %spec.select = select i1 %or.cond, i32 -3, i32 %17
  br label %29

25:                                               ; preds = %16
  %26 = getelementptr inbounds i8, ptr %5, i64 40
  %27 = load i64, ptr %26, align 8, !tbaa !16
  store i64 %27, ptr %1, align 8, !tbaa !14
  %28 = call i32 @inflateEnd(ptr noundef nonnull %5) #4
  br label %29

29:                                               ; preds = %21, %18, %13, %8, %4, %25
  %.0 = phi i32 [ %28, %25 ], [ -5, %4 ], [ -5, %8 ], [ %15, %13 ], [ -3, %18 ], [ %spec.select, %21 ]
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %5) #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 @inflateInit_(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

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