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

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

@VBlankProcess = external global i16, align 2

; Function Attrs: noinline nounwind uwtable
declare dso_local zeroext i8 @PAL_initFade(i16 noundef zeroext, i16 noundef zeroext, ptr noundef, ptr noundef, i16 noundef zeroext) #0

; Function Attrs: noinline nounwind uwtable
declare dso_local zeroext i8 @PAL_doFadeStep() #0

; Function Attrs: nounwind uwtable
define dso_local void @PAL_fade(i16 noundef zeroext %0, i16 noundef zeroext %1, ptr noundef %2, ptr noundef %3, i16 noundef zeroext %4, i8 noundef zeroext %5) #1 {
  %7 = alloca i16, align 2
  %8 = alloca i16, align 2
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i16, align 2
  %12 = alloca i8, align 1
  store i16 %0, ptr %7, align 2, !tbaa !5
  store i16 %1, ptr %8, align 2, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store i16 %4, ptr %11, align 2, !tbaa !5
  store i8 %5, ptr %12, align 1, !tbaa !11
  %13 = load i16, ptr %7, align 2, !tbaa !5
  %14 = load i16, ptr %8, align 2, !tbaa !5
  %15 = load ptr, ptr %9, align 8, !tbaa !9
  %16 = load ptr, ptr %10, align 8, !tbaa !9
  %17 = load i16, ptr %11, align 2, !tbaa !5
  %18 = call zeroext i8 @PAL_initFade(i16 noundef zeroext %13, i16 noundef zeroext %14, ptr noundef %15, ptr noundef %16, i16 noundef zeroext %17)
  %19 = icmp ne i8 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %6
  br label %37

21:                                               ; preds = %6
  %22 = load i8, ptr %12, align 1, !tbaa !11
  %23 = icmp ne i8 %22, 0
  br i1 %23, label %24, label %29

24:                                               ; preds = %21
  %25 = load volatile i16, ptr @VBlankProcess, align 2, !tbaa !5
  %26 = zext i16 %25 to i32
  %27 = or i32 %26, 1
  %28 = trunc i32 %27 to i16
  store volatile i16 %28, ptr @VBlankProcess, align 2, !tbaa !5
  br label %37

29:                                               ; preds = %21
  br label %30

30:                                               ; preds = %32, %29
  %31 = call zeroext i8 @SYS_doVBlankProcess()
  br label %32

32:                                               ; preds = %30
  %33 = call zeroext i8 @PAL_doFadeStep()
  %34 = icmp ne i8 %33, 0
  br i1 %34, label %30, label %35, !llvm.loop !12

35:                                               ; preds = %32
  %36 = call zeroext i8 @SYS_doVBlankProcess()
  br label %37

37:                                               ; preds = %35, %24, %20
  ret void
}

declare zeroext i8 @SYS_doVBlankProcess() #2

attributes #0 = { noinline 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 = { 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" }

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

@VBlankProcess = external global i16, align 2

; Function Attrs: noinline nounwind uwtable
declare dso_local zeroext i8 @PAL_initFade(i16 noundef zeroext, i16 noundef zeroext, ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: noinline nounwind uwtable
declare dso_local zeroext i8 @PAL_doFadeStep() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @PAL_fade(i16 noundef zeroext %0, i16 noundef zeroext %1, ptr noundef %2, ptr noundef %3, i16 noundef zeroext %4, i8 noundef zeroext %5) local_unnamed_addr #1 {
  %7 = tail call zeroext i8 @PAL_initFade(i16 noundef zeroext %0, i16 noundef zeroext %1, ptr noundef %2, ptr noundef %3, i16 noundef zeroext %4)
  %.not = icmp eq i8 %7, 0
  br i1 %.not, label %16, label %8

8:                                                ; preds = %6
  %.not5 = icmp eq i8 %5, 0
  br i1 %.not5, label %.preheader, label %9

9:                                                ; preds = %8
  %10 = load volatile i16, ptr @VBlankProcess, align 2, !tbaa !5
  %11 = or i16 %10, 1
  store volatile i16 %11, ptr @VBlankProcess, align 2, !tbaa !5
  br label %16

.preheader:                                       ; preds = %8, %.preheader
  %12 = tail call zeroext i8 @SYS_doVBlankProcess() #3
  %13 = tail call zeroext i8 @PAL_doFadeStep()
  %.not6 = icmp eq i8 %13, 0
  br i1 %.not6, label %14, label %.preheader, !llvm.loop !9

14:                                               ; preds = %.preheader
  %15 = tail call zeroext i8 @SYS_doVBlankProcess() #3
  br label %16

16:                                               ; preds = %6, %14, %9
  ret void
}

declare zeroext i8 @SYS_doVBlankProcess() local_unnamed_addr #2

attributes #0 = { noinline 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InstCombinePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass