; LLVM IR from Farama-Foundation/stable-retro :: cores/gba/src/third-party/zlib/contrib/puff (puff)

; 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.state = type { ptr, i64, i64, ptr, i64, i64, i32, i32, [1 x %struct.__jmp_buf_tag] }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

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

31:                                               ; preds = %4
  store i32 2, ptr %12, align 4, !tbaa !21
  br label %66

32:                                               ; preds = %4
  br label %33

33:                                               ; preds = %61, %32
  %34 = call i32 @bits(ptr noundef %9, i32 noundef 1)
  store i32 %34, ptr %10, align 4, !tbaa !21
  %35 = call i32 @bits(ptr noundef %9, i32 noundef 2)
  store i32 %35, ptr %11, align 4, !tbaa !21
  %36 = load i32, ptr %11, align 4, !tbaa !21
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %33
  %39 = call i32 @stored(ptr noundef %9)
  br label %55

40:                                               ; preds = %33
  %41 = load i32, ptr %11, align 4, !tbaa !21
  %42 = icmp eq i32 %41, 1
  br i1 %42, label %43, label %45

43:                                               ; preds = %40
  %44 = call i32 @fixed(ptr noundef %9)
  br label %53

45:                                               ; preds = %40
  %46 = load i32, ptr %11, align 4, !tbaa !21
  %47 = icmp eq i32 %46, 2
  br i1 %47, label %48, label %50

48:                                               ; preds = %45
  %49 = call i32 @dynamic(ptr noundef %9)
  br label %51

50:                                               ; preds = %45
  br label %51

51:                                               ; preds = %50, %48
  %52 = phi i32 [ %49, %48 ], [ -1, %50 ]
  br label %53

53:                                               ; preds = %51, %43
  %54 = phi i32 [ %44, %43 ], [ %52, %51 ]
  br label %55

55:                                               ; preds = %53, %38
  %56 = phi i32 [ %39, %38 ], [ %54, %53 ]
  store i32 %56, ptr %12, align 4, !tbaa !21
  %57 = load i32, ptr %12, align 4, !tbaa !21
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %55
  br label %65

60:                                               ; preds = %55
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %10, align 4, !tbaa !21
  %63 = icmp ne i32 %62, 0
  %64 = xor i1 %63, true
  br i1 %64, label %33, label %65, !llvm.loop !22

65:                                               ; preds = %61, %59
  br label %66

66:                                               ; preds = %65, %31
  %67 = load i32, ptr %12, align 4, !tbaa !21
  %68 = icmp sle i32 %67, 0
  br i1 %68, label %69, label %76

69:                                               ; preds = %66
  %70 = getelementptr inbounds %struct.state, ptr %9, i32 0, i32 2
  %71 = load i64, ptr %70, align 8, !tbaa !15
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %71, ptr %72, align 8, !tbaa !13
  %73 = getelementptr inbounds %struct.state, ptr %9, i32 0, i32 5
  %74 = load i64, ptr %73, align 8, !tbaa !18
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %74, ptr %75, align 8, !tbaa !13
  br label %76

76:                                               ; preds = %69, %66
  %77 = load i32, ptr %12, align 4, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 256, ptr %9) #3
  ret i32 %77
}

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @bits(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @stored(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @fixed(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @dynamic(ptr noundef) #0

; 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 returns_twice "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 }
attributes #4 = { nounwind returns_twice }

!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 = !{!"state", !6, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !11, i64 32, !11, i64 40, !12, i64 48, !12, i64 52, !7, i64 56}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 8}
!15 = !{!10, !11, i64 16}
!16 = !{!10, !6, i64 24}
!17 = !{!10, !11, i64 32}
!18 = !{!10, !11, i64 40}
!19 = !{!10, !12, i64 48}
!20 = !{!10, !12, i64 52}
!21 = !{!12, !12, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; 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.state = type { ptr, i64, i64, ptr, i64, i64, i32, i32, [1 x %struct.__jmp_buf_tag] }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

; Function Attrs: nounwind uwtable
define dso_local i32 @puff(ptr noundef %0, ptr nocapture noundef %1, ptr noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.state, align 8
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %5) #4
  store ptr %0, ptr %5, align 8, !tbaa !5
  %6 = load i64, ptr %1, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %5, i64 8
  store i64 %6, ptr %7, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %5, i64 16
  store i64 0, ptr %8, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %5, i64 24
  store ptr %2, ptr %9, align 8, !tbaa !15
  %10 = load i64, ptr %3, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %5, i64 32
  store i64 %10, ptr %11, align 8, !tbaa !16
  %12 = getelementptr inbounds i8, ptr %5, i64 40
  %13 = getelementptr inbounds i8, ptr %5, i64 56
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %12, i8 0, i64 16, i1 false)
  %14 = call i32 @_setjmp(ptr noundef nonnull %13) #5
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %.preheader, label %.thread21

.preheader:                                       ; preds = %4, %25
  %15 = call i32 @bits(ptr noundef nonnull %5, i32 noundef 1)
  %16 = call i32 @bits(ptr noundef nonnull %5, i32 noundef 2)
  switch i32 %16, label %.thread17 [
    i32 0, label %17
    i32 1, label %19
    i32 2, label %21
  ]

17:                                               ; preds = %.preheader
  %18 = call i32 @stored(ptr noundef nonnull %5)
  br label %23

19:                                               ; preds = %.preheader
  %20 = call i32 @fixed(ptr noundef nonnull %5)
  br label %23

21:                                               ; preds = %.preheader
  %22 = call i32 @dynamic(ptr noundef nonnull %5)
  br label %23

23:                                               ; preds = %19, %21, %17
  %24 = phi i32 [ %18, %17 ], [ %20, %19 ], [ %22, %21 ]
  %.not14 = icmp eq i32 %24, 0
  br i1 %.not14, label %25, label %26

25:                                               ; preds = %23
  %.not15 = icmp eq i32 %15, 0
  br i1 %.not15, label %.preheader, label %.thread17, !llvm.loop !17

26:                                               ; preds = %23
  %27 = icmp slt i32 %24, 1
  br i1 %27, label %.thread17, label %.thread21

.thread17:                                        ; preds = %.preheader, %25, %26
  %.020 = phi i32 [ %24, %26 ], [ -1, %.preheader ], [ 0, %25 ]
  %28 = load i64, ptr %8, align 8, !tbaa !14
  store i64 %28, ptr %1, align 8, !tbaa !12
  %29 = load i64, ptr %12, align 8, !tbaa !19
  store i64 %29, ptr %3, align 8, !tbaa !12
  br label %.thread21

.thread21:                                        ; preds = %4, %.thread17, %26
  %.019 = phi i32 [ %.020, %.thread17 ], [ %24, %26 ], [ 2, %4 ]
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %5) #4
  ret i32 %.019
}

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

; Function Attrs: nounwind returns_twice
declare i32 @_setjmp(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @bits(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @stored(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @fixed(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @dynamic(ptr noundef) local_unnamed_addr #0

; 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 = { nounwind returns_twice "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 }
attributes #5 = { nounwind returns_twice }

!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 = !{!"state", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !10, i64 40, !11, i64 48, !11, i64 52, !8, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !7, i64 24}
!16 = !{!6, !10, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !10, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass