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

%struct.Vec2 = type { i16, i16 }

@pos = external dso_local global %struct.Vec2, align 2
@px = external dso_local global i16, align 2
@blockmap = external dso_local global [1024 x i16], align 16
@.str = external hidden unnamed_addr constant [17 x i8], align 1
@pad_keys = external global [5 x i16], align 2
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@lives = external dso_local global i16, align 2
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @draw_screen() #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 @die() #0 {
  %1 = load i16, ptr @lives, align 2, !tbaa !5
  %2 = zext i16 %1 to i32
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %4, label %6

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

5:                                                ; preds = %5, %4
  br label %5

6:                                                ; preds = %0
  %7 = load i16, ptr @lives, align 2, !tbaa !5
  %8 = add i16 %7, -1
  store i16 %8, ptr @lives, align 2, !tbaa !5
  store i16 94, ptr @pos, align 2, !tbaa !9
  store i16 109, ptr getelementptr inbounds (%struct.Vec2, ptr @pos, i32 0, i32 1), align 2, !tbaa !11
  store i16 80, ptr @px, align 2, !tbaa !5
  %9 = load i16, ptr @lives, align 2, !tbaa !5
  call void @writenum(i16 noundef zeroext %9, i8 noundef zeroext 8, ptr noundef @blockmap, i16 noundef zeroext 310, i16 noundef zeroext 1062)
  call void @writestring(ptr noundef @.str, ptr noundef @blockmap, i16 noundef zeroext 584, i16 noundef zeroext 1014)
  call void @WaitForVBlank()
  call void @dmaCopyVram(ptr noundef @blockmap, i16 noundef zeroext 0, i16 noundef zeroext 2048)
  call void @draw_screen()
  br label %10

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

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

15:                                               ; preds = %10
  call void @writestring(ptr noundef @.str.1, ptr noundef @blockmap, i16 noundef zeroext 584, i16 noundef zeroext 1014)
  call void @writestring(ptr noundef @.str.1, ptr noundef @blockmap, i16 noundef zeroext 649, i16 noundef zeroext 1014)
  call void @WaitForVBlank()
  call void @dmaCopyVram(ptr noundef @blockmap, i16 noundef zeroext 0, i16 noundef zeroext 2048)
  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 = !{!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.Vec2 = type { i16, i16 }

@pos = external dso_local local_unnamed_addr global %struct.Vec2, align 2
@px = external dso_local local_unnamed_addr global i16, align 2
@blockmap = external dso_local global [1024 x i16], align 16
@.str = external hidden unnamed_addr constant [17 x i8], align 1
@pad_keys = external local_unnamed_addr global [5 x i16], align 2
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@lives = external dso_local local_unnamed_addr global i16, align 2
@.str.2 = external hidden unnamed_addr constant [10 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

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

; Function Attrs: nounwind uwtable
declare dso_local void @draw_screen() 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 @die() local_unnamed_addr #0 {
  %1 = load i16, ptr @lives, align 2, !tbaa !5
  %2 = icmp eq i16 %1, 0
  br i1 %2, label %3, label %5

3:                                                ; preds = %0
  tail call void @writestring(ptr noundef nonnull @.str.2, ptr noundef nonnull @blockmap, i16 noundef zeroext 615, 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 %4

4:                                                ; preds = %4, %3
  br label %4

5:                                                ; preds = %0
  %6 = add i16 %1, -1
  store i16 %6, ptr @lives, align 2, !tbaa !5
  store i16 94, ptr @pos, align 2, !tbaa !9
  store i16 109, ptr getelementptr inbounds (i8, ptr @pos, i64 2), align 2, !tbaa !11
  store i16 80, ptr @px, align 2, !tbaa !5
  tail call void @writenum(i16 noundef zeroext %6, i8 noundef zeroext 8, ptr noundef nonnull @blockmap, i16 noundef zeroext 310, i16 noundef zeroext 1062)
  tail call void @writestring(ptr noundef nonnull @.str, ptr noundef nonnull @blockmap, i16 noundef zeroext 584, 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
  tail call void @draw_screen()
  %7 = load i16, ptr @pad_keys, align 2, !tbaa !5
  %8 = icmp eq i16 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

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

._crit_edge:                                      ; preds = %.lr.ph, %5
  tail call void @writestring(ptr noundef nonnull @.str.1, ptr noundef nonnull @blockmap, i16 noundef zeroext 584, i16 noundef zeroext 1014)
  tail call void @writestring(ptr noundef nonnull @.str.1, ptr noundef nonnull @blockmap, i16 noundef zeroext 649, 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
  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 = !{!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: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SimplifyCFGPass,TailCallElimPass