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

; Function Attrs: nounwind uwtable
define dso_local void @fadeInBlue(i16 noundef zeroext %0, i16 noundef zeroext %1, ptr noundef %2, i16 noundef zeroext %3, i16 noundef zeroext %4) #0 {
  %6 = alloca i16, align 2
  %7 = alloca i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca i16, align 2
  %10 = alloca i16, align 2
  %11 = alloca [64 x i16], align 16
  %12 = alloca i16, align 2
  store i16 %0, ptr %6, align 2, !tbaa !5
  store i16 %1, ptr %7, align 2, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !9
  store i16 %3, ptr %9, align 2, !tbaa !5
  store i16 %4, ptr %10, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 128, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #3
  store i16 0, ptr %12, align 2, !tbaa !5
  br label %13

13:                                               ; preds = %36, %5
  %14 = load i16, ptr %12, align 2, !tbaa !5
  %15 = zext i16 %14 to i32
  %16 = load i16, ptr %7, align 2, !tbaa !5
  %17 = zext i16 %16 to i32
  %18 = load i16, ptr %6, align 2, !tbaa !5
  %19 = zext i16 %18 to i32
  %20 = sub nsw i32 %17, %19
  %21 = add nsw i32 %20, 1
  %22 = icmp slt i32 %15, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %13
  %25 = load ptr, ptr %8, align 8, !tbaa !9
  %26 = load i16, ptr %12, align 2, !tbaa !5
  %27 = zext i16 %26 to i64
  %28 = getelementptr inbounds i16, ptr %25, i64 %27
  %29 = load i16, ptr %28, align 2, !tbaa !5
  %30 = zext i16 %29 to i32
  %31 = and i32 %30, 3840
  %32 = trunc i32 %31 to i16
  %33 = load i16, ptr %12, align 2, !tbaa !5
  %34 = zext i16 %33 to i64
  %35 = getelementptr inbounds [64 x i16], ptr %11, i64 0, i64 %34
  store i16 %32, ptr %35, align 2, !tbaa !5
  br label %36

36:                                               ; preds = %24
  %37 = load i16, ptr %12, align 2, !tbaa !5
  %38 = add i16 %37, 1
  store i16 %38, ptr %12, align 2, !tbaa !5
  br label %13, !llvm.loop !11

39:                                               ; preds = %23
  %40 = load i16, ptr %6, align 2, !tbaa !5
  %41 = load i16, ptr %7, align 2, !tbaa !5
  %42 = getelementptr inbounds [64 x i16], ptr %11, i64 0, i64 0
  %43 = load i16, ptr %9, align 2, !tbaa !5
  call void @PAL_fadeIn(i16 noundef zeroext %40, i16 noundef zeroext %41, ptr noundef %42, i16 noundef zeroext %43, i8 noundef zeroext 0)
  %44 = load i16, ptr %6, align 2, !tbaa !5
  %45 = load i16, ptr %7, align 2, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !9
  %47 = load i16, ptr %10, align 2, !tbaa !5
  call void @PAL_fadeTo(i16 noundef zeroext %44, i16 noundef zeroext %45, ptr noundef %46, i16 noundef zeroext %47, i8 noundef zeroext 0)
  call void @llvm.lifetime.end.p0(i64 128, ptr %11) #3
  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

declare void @PAL_fadeIn(i16 noundef zeroext, i16 noundef zeroext, ptr noundef, i16 noundef zeroext, i8 noundef zeroext) #2

declare void @PAL_fadeTo(i16 noundef zeroext, i16 noundef zeroext, ptr noundef, i16 noundef zeroext, i8 noundef zeroext) #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 = { 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 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local void @fadeInBlue(i16 noundef zeroext %0, i16 noundef zeroext %1, ptr noundef %2, i16 noundef zeroext %3, i16 noundef zeroext %4) local_unnamed_addr #0 {
  %6 = alloca [64 x i16], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %6) #4
  %7 = zext i16 %1 to i32
  %8 = zext i16 %0 to i32
  %9 = sub nsw i32 %7, %8
  %.not13 = icmp slt i32 %9, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %10 = add nuw nsw i32 %7, 1
  %11 = sub nsw i32 %10, %8
  %min.iters.check = icmp ult i32 %11, 16
  br i1 %min.iters.check, label %.lr.ph.preheader17, label %vector.scevcheck

.lr.ph.preheader17:                               ; preds = %middle.block, %vector.scevcheck, %.lr.ph.preheader
  %.014.ph = phi i16 [ 0, %vector.scevcheck ], [ 0, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

vector.scevcheck:                                 ; preds = %.lr.ph.preheader
  %12 = add nuw nsw i32 %7, 1
  %13 = sub nsw i32 %12, %8
  %umax = tail call i32 @llvm.umax.i32(i32 %13, i32 1)
  %14 = add i32 %umax, -1
  %15 = and i32 %14, 65535
  %16 = icmp eq i32 %15, 65535
  %17 = icmp ugt i32 %14, 65535
  %18 = or i1 %16, %17
  br i1 %18, label %.lr.ph.preheader17, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i32 %11, -16
  %ind.end = trunc i32 %n.vec to i16
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %19 = and i32 %index, 65520
  %20 = zext nneg i32 %19 to i64
  %21 = getelementptr inbounds i16, ptr %2, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %wide.load = load <8 x i16>, ptr %21, align 2, !tbaa !5
  %wide.load16 = load <8 x i16>, ptr %22, align 2, !tbaa !5
  %23 = and <8 x i16> %wide.load, <i16 3840, i16 3840, i16 3840, i16 3840, i16 3840, i16 3840, i16 3840, i16 3840>
  %24 = and <8 x i16> %wide.load16, <i16 3840, i16 3840, i16 3840, i16 3840, i16 3840, i16 3840, i16 3840, i16 3840>
  %25 = getelementptr inbounds [64 x i16], ptr %6, i64 0, i64 %20
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  store <8 x i16> %23, ptr %25, align 16, !tbaa !5
  store <8 x i16> %24, ptr %26, align 16, !tbaa !5
  %index.next = add nuw i32 %index, 16
  %27 = icmp eq i32 %index.next, %n.vec
  br i1 %27, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i32 %11, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader17

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %5
  call void @PAL_fadeIn(i16 noundef zeroext %0, i16 noundef zeroext %1, ptr noundef nonnull %6, i16 noundef zeroext %3, i8 noundef zeroext 0) #4
  call void @PAL_fadeTo(i16 noundef zeroext %0, i16 noundef zeroext %1, ptr noundef %2, i16 noundef zeroext %4, i8 noundef zeroext 0) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %6) #4
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader17, %.lr.ph
  %.014 = phi i16 [ %33, %.lr.ph ], [ %.014.ph, %.lr.ph.preheader17 ]
  %28 = zext i16 %.014 to i64
  %29 = getelementptr inbounds i16, ptr %2, i64 %28
  %30 = load i16, ptr %29, align 2, !tbaa !5
  %31 = and i16 %30, 3840
  %32 = getelementptr inbounds [64 x i16], ptr %6, i64 0, i64 %28
  store i16 %31, ptr %32, align 2, !tbaa !5
  %33 = add i16 %.014, 1
  %34 = zext i16 %33 to i32
  %.not = icmp ult i32 %9, %34
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13
}

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

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

declare void @PAL_fadeIn(i16 noundef zeroext, i16 noundef zeroext, ptr noundef, i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #2

declare void @PAL_fadeTo(i16 noundef zeroext, i16 noundef zeroext, ptr noundef, i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #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 nosync nounwind speculatable willreturn memory(none) }
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, !6, i64 0}
!6 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass