; LLVM IR from Stephane-D/SGDK :: sample/fx/h-int/wobble/src (helpers)

; 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.Vect2D_s16 = type { i16, i16 }

@spriteOffsets = external hidden global [80 x %struct.Vect2D_s16], align 16
@vdpSpriteIndexNext = external hidden global i16, align 2

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

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

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

6:                                                ; preds = %119, %2
  %7 = load i16, ptr %5, align 2, !tbaa !5
  %8 = zext i16 %7 to i32
  %9 = load i16, ptr @vdpSpriteIndexNext, align 2, !tbaa !5
  %10 = zext i16 %9 to i32
  %11 = icmp slt i32 %8, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #3
  br label %122

13:                                               ; preds = %6
  %14 = load i16, ptr %5, align 2, !tbaa !5
  %15 = load i16, ptr %5, align 2, !tbaa !5
  %16 = zext i16 %15 to i64
  %17 = getelementptr inbounds [80 x %struct.Vect2D_s16], ptr @spriteOffsets, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.Vect2D_s16, ptr %17, i32 0, i32 0
  %19 = load i16, ptr %18, align 4, !tbaa !9
  %20 = sext i16 %19 to i32
  %21 = load i16, ptr %3, align 2, !tbaa !5
  %22 = sext i16 %21 to i32
  %23 = add nsw i32 %20, %22
  %24 = icmp sgt i32 -32, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %13
  br label %36

26:                                               ; preds = %13
  %27 = load i16, ptr %5, align 2, !tbaa !5
  %28 = zext i16 %27 to i64
  %29 = getelementptr inbounds [80 x %struct.Vect2D_s16], ptr @spriteOffsets, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.Vect2D_s16, ptr %29, i32 0, i32 0
  %31 = load i16, ptr %30, align 4, !tbaa !9
  %32 = sext i16 %31 to i32
  %33 = load i16, ptr %3, align 2, !tbaa !5
  %34 = sext i16 %33 to i32
  %35 = add nsw i32 %32, %34
  br label %36

36:                                               ; preds = %26, %25
  %37 = phi i32 [ -32, %25 ], [ %35, %26 ]
  %38 = icmp slt i32 320, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  br label %64

40:                                               ; preds = %36
  %41 = load i16, ptr %5, align 2, !tbaa !5
  %42 = zext i16 %41 to i64
  %43 = getelementptr inbounds [80 x %struct.Vect2D_s16], ptr @spriteOffsets, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.Vect2D_s16, ptr %43, i32 0, i32 0
  %45 = load i16, ptr %44, align 4, !tbaa !9
  %46 = sext i16 %45 to i32
  %47 = load i16, ptr %3, align 2, !tbaa !5
  %48 = sext i16 %47 to i32
  %49 = add nsw i32 %46, %48
  %50 = icmp sgt i32 -32, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %40
  br label %62

52:                                               ; preds = %40
  %53 = load i16, ptr %5, align 2, !tbaa !5
  %54 = zext i16 %53 to i64
  %55 = getelementptr inbounds [80 x %struct.Vect2D_s16], ptr @spriteOffsets, i64 0, i64 %54
  %56 = getelementptr inbounds %struct.Vect2D_s16, ptr %55, i32 0, i32 0
  %57 = load i16, ptr %56, align 4, !tbaa !9
  %58 = sext i16 %57 to i32
  %59 = load i16, ptr %3, align 2, !tbaa !5
  %60 = sext i16 %59 to i32
  %61 = add nsw i32 %58, %60
  br label %62

62:                                               ; preds = %52, %51
  %63 = phi i32 [ -32, %51 ], [ %61, %52 ]
  br label %64

64:                                               ; preds = %62, %39
  %65 = phi i32 [ 320, %39 ], [ %63, %62 ]
  %66 = trunc i32 %65 to i16
  %67 = load i16, ptr %5, align 2, !tbaa !5
  %68 = zext i16 %67 to i64
  %69 = getelementptr inbounds [80 x %struct.Vect2D_s16], ptr @spriteOffsets, i64 0, i64 %68
  %70 = getelementptr inbounds %struct.Vect2D_s16, ptr %69, i32 0, i32 1
  %71 = load i16, ptr %70, align 2, !tbaa !11
  %72 = sext i16 %71 to i32
  %73 = load i16, ptr %4, align 2, !tbaa !5
  %74 = sext i16 %73 to i32
  %75 = add nsw i32 %72, %74
  %76 = icmp sgt i32 -32, %75
  br i1 %76, label %77, label %78

77:                                               ; preds = %64
  br label %88

78:                                               ; preds = %64
  %79 = load i16, ptr %5, align 2, !tbaa !5
  %80 = zext i16 %79 to i64
  %81 = getelementptr inbounds [80 x %struct.Vect2D_s16], ptr @spriteOffsets, i64 0, i64 %80
  %82 = getelementptr inbounds %struct.Vect2D_s16, ptr %81, i32 0, i32 1
  %83 = load i16, ptr %82, align 2, !tbaa !11
  %84 = sext i16 %83 to i32
  %85 = load i16, ptr %4, align 2, !tbaa !5
  %86 = sext i16 %85 to i32
  %87 = add nsw i32 %84, %86
  br label %88

88:                                               ; preds = %78, %77
  %89 = phi i32 [ -32, %77 ], [ %87, %78 ]
  %90 = icmp slt i32 224, %89
  br i1 %90, label %91, label %92

91:                                               ; preds = %88
  br label %116

92:                                               ; preds = %88
  %93 = load i16, ptr %5, align 2, !tbaa !5
  %94 = zext i16 %93 to i64
  %95 = getelementptr inbounds [80 x %struct.Vect2D_s16], ptr @spriteOffsets, i64 0, i64 %94
  %96 = getelementptr inbounds %struct.Vect2D_s16, ptr %95, i32 0, i32 1
  %97 = load i16, ptr %96, align 2, !tbaa !11
  %98 = sext i16 %97 to i32
  %99 = load i16, ptr %4, align 2, !tbaa !5
  %100 = sext i16 %99 to i32
  %101 = add nsw i32 %98, %100
  %102 = icmp sgt i32 -32, %101
  br i1 %102, label %103, label %104

103:                                              ; preds = %92
  br label %114

104:                                              ; preds = %92
  %105 = load i16, ptr %5, align 2, !tbaa !5
  %106 = zext i16 %105 to i64
  %107 = getelementptr inbounds [80 x %struct.Vect2D_s16], ptr @spriteOffsets, i64 0, i64 %106
  %108 = getelementptr inbounds %struct.Vect2D_s16, ptr %107, i32 0, i32 1
  %109 = load i16, ptr %108, align 2, !tbaa !11
  %110 = sext i16 %109 to i32
  %111 = load i16, ptr %4, align 2, !tbaa !5
  %112 = sext i16 %111 to i32
  %113 = add nsw i32 %110, %112
  br label %114

114:                                              ; preds = %104, %103
  %115 = phi i32 [ -32, %103 ], [ %113, %104 ]
  br label %116

116:                                              ; preds = %114, %91
  %117 = phi i32 [ 224, %91 ], [ %115, %114 ]
  %118 = trunc i32 %117 to i16
  call void @VDP_setSpritePosition(i16 noundef zeroext %14, i16 noundef signext %66, i16 noundef signext %118)
  br label %119

119:                                              ; preds = %116
  %120 = load i16, ptr %5, align 2, !tbaa !5
  %121 = add i16 %120, 1
  store i16 %121, ptr %5, align 2, !tbaa !5
  br label %6, !llvm.loop !12

122:                                              ; preds = %12
  %123 = load i16, ptr @vdpSpriteIndexNext, align 2, !tbaa !5
  call void @VDP_updateSprites(i16 noundef zeroext %123, i32 noundef 1)
  ret void
}

declare void @VDP_setSpritePosition(i16 noundef zeroext, i16 noundef signext, i16 noundef signext) #2

declare void @VDP_updateSprites(i16 noundef zeroext, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 2}
!11 = !{!10, !6, i64 2}
!12 = distinct !{!12, !13}
!13 = !{!"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.Vect2D_s16 = type { i16, i16 }

@spriteOffsets = external hidden local_unnamed_addr global [80 x %struct.Vect2D_s16], align 16
@vdpSpriteIndexNext = external hidden local_unnamed_addr global i16, align 2

; Function Attrs: nounwind uwtable
define dso_local void @moveSprites(i16 noundef signext %0, i16 noundef signext %1) local_unnamed_addr #0 {
  %3 = load i16, ptr @vdpSpriteIndexNext, align 2, !tbaa !5
  %.not = icmp eq i16 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = sext i16 %0 to i32
  %5 = sext i16 %1 to i32
  br label %6

._crit_edge:                                      ; preds = %6, %2
  %.lcssa = phi i16 [ 0, %2 ], [ %19, %6 ]
  tail call void @VDP_updateSprites(i16 noundef zeroext %.lcssa, i32 noundef 1) #3
  ret void

6:                                                ; preds = %.lr.ph, %6
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %6 ]
  %7 = getelementptr inbounds [80 x %struct.Vect2D_s16], ptr @spriteOffsets, i64 0, i64 %indvars.iv
  %8 = load i16, ptr %7, align 4, !tbaa !9
  %9 = sext i16 %8 to i32
  %10 = add nsw i32 %9, %4
  %spec.select = tail call i32 @llvm.smax.i32(i32 %10, i32 -32)
  %spec.select26 = tail call i32 @llvm.smin.i32(i32 %spec.select, i32 320)
  %11 = trunc nsw i32 %spec.select26 to i16
  %12 = getelementptr inbounds i8, ptr %7, i64 2
  %13 = load i16, ptr %12, align 2, !tbaa !11
  %14 = sext i16 %13 to i32
  %15 = add nsw i32 %14, %5
  %spec.select24 = tail call i32 @llvm.smax.i32(i32 %15, i32 -32)
  %16 = tail call i32 @llvm.smin.i32(i32 %spec.select24, i32 224)
  %17 = trunc nsw i32 %16 to i16
  %18 = trunc nuw i64 %indvars.iv to i16
  tail call void @VDP_setSpritePosition(i16 noundef zeroext %18, i16 noundef signext %11, i16 noundef signext %17) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = load i16, ptr @vdpSpriteIndexNext, align 2, !tbaa !5
  %20 = zext i16 %19 to i64
  %21 = icmp ult i64 %indvars.iv.next, %20
  br i1 %21, label %6, label %._crit_edge, !llvm.loop !12
}

declare void @VDP_setSpritePosition(i16 noundef zeroext, i16 noundef signext, i16 noundef signext) local_unnamed_addr #1

declare void @VDP_updateSprites(i16 noundef zeroext, i32 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 2}
!11 = !{!10, !6, i64 2}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass