; LLVM IR from alekmaul/pvsneslib :: snes-examples/games/breakout (breakout)

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

@blockmap = external dso_local global [1024 x i16], align 16
@pad_keys = external global [5 x i16], align 2
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@pad0 = external dso_local global i16, align 2
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @writestring(ptr noundef, ptr noundef, i16 noundef zeroext, i16 noundef zeroext) #0

declare void @WaitForVBlank() #1

declare void @dmaCopyVram(ptr noundef, i16 noundef zeroext, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local void @handle_pause() #0 {
  %1 = load i16, ptr @pad0, align 2, !tbaa !5
  %2 = zext i16 %1 to i32
  %3 = and i32 %2, 4096
  %4 = icmp ne i32 %3, 0
  br i1 %4, label %5, label %25

5:                                                ; preds = %0
  call void @writestring(ptr noundef @.str.3, ptr noundef @blockmap, i16 noundef zeroext 617, i16 noundef zeroext 1014)
  call void @WaitForVBlank()
  call void @dmaCopyVram(ptr noundef @blockmap, i16 noundef zeroext 0, i16 noundef zeroext 2048)
  br label %6

6:                                                ; preds = %10, %5
  %7 = load i16, ptr @pad_keys, align 2, !tbaa !5
  %8 = zext i16 %7 to i32
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %6
  call void @WaitForVBlank()
  br label %6, !llvm.loop !9

11:                                               ; preds = %6
  br label %12

12:                                               ; preds = %17, %11
  %13 = load i16, ptr @pad_keys, align 2, !tbaa !5
  %14 = zext i16 %13 to i32
  %15 = and i32 %14, 4096
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  call void @WaitForVBlank()
  br label %12, !llvm.loop !11

18:                                               ; preds = %12
  br label %19

19:                                               ; preds = %23, %18
  %20 = load i16, ptr @pad_keys, align 2, !tbaa !5
  %21 = zext i16 %20 to i32
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  call void @WaitForVBlank()
  br label %19, !llvm.loop !12

24:                                               ; preds = %19
  call void @writestring(ptr noundef @.str.1, ptr noundef @blockmap, i16 noundef zeroext 617, i16 noundef zeroext 1014)
  call void @WaitForVBlank()
  call void @dmaCopyVram(ptr noundef @blockmap, i16 noundef zeroext 0, i16 noundef zeroext 2048)
  br label %25

25:                                               ; preds = %24, %0
  ret void
}

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

!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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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

@blockmap = external dso_local global [1024 x i16], align 16
@pad_keys = external local_unnamed_addr global [5 x i16], align 2
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@pad0 = external dso_local local_unnamed_addr global i16, align 2
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @writestring(ptr noundef, ptr noundef, i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #0

declare void @WaitForVBlank() local_unnamed_addr #1

declare void @dmaCopyVram(ptr noundef, i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @handle_pause() local_unnamed_addr #0 {
  %1 = load i16, ptr @pad0, align 2, !tbaa !5
  %2 = and i16 %1, 4096
  %.not = icmp eq i16 %2, 0
  br i1 %.not, label %9, label %3

3:                                                ; preds = %0
  tail call void @writestring(ptr noundef nonnull @.str.3, ptr noundef nonnull @blockmap, i16 noundef zeroext 617, i16 noundef zeroext 1014)
  tail call void @WaitForVBlank() #2
  tail call void @dmaCopyVram(ptr noundef nonnull @blockmap, i16 noundef zeroext 0, i16 noundef zeroext 2048) #2
  %4 = load i16, ptr @pad_keys, align 2, !tbaa !5
  %.not14 = icmp eq i16 %4, 0
  br i1 %.not14, label %.lr.ph5.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  tail call void @WaitForVBlank() #2
  %5 = load i16, ptr @pad_keys, align 2, !tbaa !5
  %.not1 = icmp eq i16 %5, 0
  br i1 %.not1, label %.lr.ph5.preheader, label %.lr.ph, !llvm.loop !9

.lr.ph5.preheader:                                ; preds = %.lr.ph, %3
  br label %.lr.ph5

.lr.ph5:                                          ; preds = %.lr.ph5.preheader, %.lr.ph5
  tail call void @WaitForVBlank() #2
  %6 = load i16, ptr @pad_keys, align 2, !tbaa !5
  %7 = and i16 %6, 4096
  %8 = icmp eq i16 %7, 0
  br i1 %8, label %.lr.ph5, label %.lr.ph7, !llvm.loop !11

.lr.ph7:                                          ; preds = %.lr.ph5, %.lr.ph7
  tail call void @WaitForVBlank() #2
  %.pr = load i16, ptr @pad_keys, align 2, !tbaa !5
  %.not2 = icmp eq i16 %.pr, 0
  br i1 %.not2, label %._crit_edge, label %.lr.ph7, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph7
  tail call void @writestring(ptr noundef nonnull @.str.1, ptr noundef nonnull @blockmap, i16 noundef zeroext 617, i16 noundef zeroext 1014)
  tail call void @WaitForVBlank() #2
  tail call void @dmaCopyVram(ptr noundef nonnull @blockmap, i16 noundef zeroext 0, i16 noundef zeroext 2048) #2
  br label %9

9:                                                ; preds = %._crit_edge, %0
  ret void
}

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 = { 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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SimplifyCFGPass,TailCallElimPass