; LLVM IR from Stephane-D/SGDK :: src (vdp_spr)

; 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.VDPSprite = type { i16, %union.anon, %union.anon.1, i16 }
%union.anon = type { %struct.anon }
%struct.anon = type { i16 }
%union.anon.1 = type { i16 }

@vdpSpriteCache = external dso_local global [96 x %struct.VDPSprite], align 16
@allocStack = external hidden global [80 x ptr], align 16
@free = external hidden global ptr, align 8
@highestVDPSpriteIndex = external dso_local global i16, align 2

; Function Attrs: nounwind uwtable
define dso_local void @VDP_releaseAllSprites() #0 {
  %1 = alloca i16, align 2
  call void @llvm.lifetime.start.p0(i64 2, ptr %1) #2
  store i16 0, ptr %1, align 2, !tbaa !5
  br label %2

2:                                                ; preds = %15, %0
  %3 = load i16, ptr %1, align 2, !tbaa !5
  %4 = zext i16 %3 to i32
  %5 = icmp slt i32 %4, 80
  br i1 %5, label %6, label %18

6:                                                ; preds = %2
  %7 = load i16, ptr %1, align 2, !tbaa !5
  %8 = zext i16 %7 to i32
  %9 = sub nsw i32 79, %8
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [96 x %struct.VDPSprite], ptr @vdpSpriteCache, i64 0, i64 %10
  %12 = load i16, ptr %1, align 2, !tbaa !5
  %13 = zext i16 %12 to i64
  %14 = getelementptr inbounds [80 x ptr], ptr @allocStack, i64 0, i64 %13
  store ptr %11, ptr %14, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %6
  %16 = load i16, ptr %1, align 2, !tbaa !5
  %17 = add i16 %16, 1
  store i16 %17, ptr %1, align 2, !tbaa !5
  br label %2, !llvm.loop !11

18:                                               ; preds = %2
  store ptr getelementptr inbounds ([80 x ptr], ptr @allocStack, i64 0, i64 80), ptr @free, align 8, !tbaa !9
  store i16 -1, ptr @highestVDPSpriteIndex, align 2, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 2, ptr %1) #2
  ret void
}

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

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

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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.VDPSprite = type { i16, %union.anon, %union.anon.1, i16 }
%union.anon = type { %struct.anon }
%struct.anon = type { i16 }
%union.anon.1 = type { i16 }

@vdpSpriteCache = external dso_local global [96 x %struct.VDPSprite], align 16
@allocStack = external hidden global [80 x ptr], align 16
@free = external hidden local_unnamed_addr global ptr, align 8
@highestVDPSpriteIndex = external dso_local local_unnamed_addr global i16, align 2

; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @VDP_releaseAllSprites() local_unnamed_addr #0 {
vector.ph:
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 79, i64 78>), ptr @allocStack, align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 77, i64 76>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 16), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 75, i64 74>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 32), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 73, i64 72>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 48), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 71, i64 70>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 64), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 69, i64 68>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 80), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 67, i64 66>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 96), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 65, i64 64>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 112), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 63, i64 62>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 128), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 61, i64 60>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 144), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 59, i64 58>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 160), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 57, i64 56>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 176), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 55, i64 54>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 192), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 53, i64 52>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 208), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 51, i64 50>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 224), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 49, i64 48>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 240), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 47, i64 46>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 256), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 45, i64 44>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 272), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 43, i64 42>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 288), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 41, i64 40>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 304), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 39, i64 38>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 320), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 37, i64 36>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 336), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 35, i64 34>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 352), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 33, i64 32>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 368), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 31, i64 30>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 384), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 29, i64 28>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 400), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 27, i64 26>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 416), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 25, i64 24>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 432), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 23, i64 22>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 448), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 21, i64 20>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 464), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 19, i64 18>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 480), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 17, i64 16>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 496), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 15, i64 14>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 512), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 13, i64 12>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 528), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 11, i64 10>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 544), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 9, i64 8>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 560), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 7, i64 6>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 576), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 5, i64 4>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 592), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 3, i64 2>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 608), align 16, !tbaa !5
  store <2 x ptr> getelementptr inbounds ([96 x %struct.VDPSprite], ptr @vdpSpriteCache, <2 x i64> zeroinitializer, <2 x i64> <i64 1, i64 0>), ptr getelementptr inbounds (i8, ptr @allocStack, i64 624), align 16, !tbaa !5
  store ptr getelementptr inbounds (i8, ptr @allocStack, i64 640), ptr @free, align 8, !tbaa !5
  store i16 -1, ptr @highestVDPSpriteIndex, align 2, !tbaa !9
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) 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" }

!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 = !{!"short", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass