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

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

@snesfont = external global i8, align 1
@snespal = external global i8, align 1
@.str = external hidden unnamed_addr constant [23 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@pad_keys = external global [5 x i16], align 2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @consoleSetTextMapPtr(i16 noundef zeroext 26624)
  call void @consoleSetTextGfxPtr(i16 noundef zeroext 12288)
  call void @consoleSetTextOffset(i16 noundef zeroext 256)
  call void @consoleInitText(i8 noundef zeroext 0, i8 noundef zeroext 32, ptr noundef @snesfont, ptr noundef @snespal)
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 5, i16 noundef zeroext 8, ptr noundef @.str)
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 3, i16 noundef zeroext 10, ptr noundef @.str.1)
  call void @bgSetGfxPtr(i8 noundef zeroext 0, i16 noundef zeroext 8192)
  call void @bgSetMapPtr(i8 noundef zeroext 0, i16 noundef zeroext 26624, i8 noundef zeroext 0)
  call void @setMode(i8 noundef zeroext 1, i8 noundef zeroext 0)
  call void @bgSetDisable(i8 noundef zeroext 1)
  call void @bgSetDisable(i8 noundef zeroext 2)
  call void @setBrightness(i8 noundef zeroext 15)
  br label %2

2:                                                ; preds = %11, %0
  %3 = call zeroext i16 @rand()
  %4 = zext i16 %3 to i32
  %5 = and i32 %4, 65535
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 6, i16 noundef zeroext 12, ptr noundef @.str.2, i32 noundef %5)
  call void @WaitForVBlank()
  br label %6

6:                                                ; preds = %10, %2
  %7 = load i16, ptr @pad_keys, align 2, !tbaa !5
  %8 = zext i16 %7 to i32
  %9 = icmp eq 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 %2
}

declare void @consoleSetTextMapPtr(i16 noundef zeroext) #1

declare void @consoleSetTextGfxPtr(i16 noundef zeroext) #1

declare void @consoleSetTextOffset(i16 noundef zeroext) #1

declare void @consoleInitText(i8 noundef zeroext, i8 noundef zeroext, ptr noundef, ptr noundef) #1

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

declare void @bgSetGfxPtr(i8 noundef zeroext, i16 noundef zeroext) #1

declare void @bgSetMapPtr(i8 noundef zeroext, i16 noundef zeroext, i8 noundef zeroext) #1

declare void @setMode(i8 noundef zeroext, i8 noundef zeroext) #1

declare void @bgSetDisable(i8 noundef zeroext) #1

declare void @setBrightness(i8 noundef zeroext) #1

declare zeroext i16 @rand() #1

declare void @WaitForVBlank() #1

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


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

@snesfont = external global i8, align 1
@snespal = external global i8, align 1
@.str = external hidden unnamed_addr constant [23 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@pad_keys = external local_unnamed_addr global [5 x i16], align 2

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  tail call void @consoleSetTextMapPtr(i16 noundef zeroext 26624) #2
  tail call void @consoleSetTextGfxPtr(i16 noundef zeroext 12288) #2
  tail call void @consoleSetTextOffset(i16 noundef zeroext 256) #2
  tail call void @consoleInitText(i8 noundef zeroext 0, i8 noundef zeroext 32, ptr noundef nonnull @snesfont, ptr noundef nonnull @snespal) #2
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 5, i16 noundef zeroext 8, ptr noundef nonnull @.str) #2
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 3, i16 noundef zeroext 10, ptr noundef nonnull @.str.1) #2
  tail call void @bgSetGfxPtr(i8 noundef zeroext 0, i16 noundef zeroext 8192) #2
  tail call void @bgSetMapPtr(i8 noundef zeroext 0, i16 noundef zeroext 26624, i8 noundef zeroext 0) #2
  tail call void @setMode(i8 noundef zeroext 1, i8 noundef zeroext 0) #2
  tail call void @bgSetDisable(i8 noundef zeroext 1) #2
  tail call void @bgSetDisable(i8 noundef zeroext 2) #2
  tail call void @setBrightness(i8 noundef zeroext 15) #2
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.backedge, %0
  %1 = tail call zeroext i16 @rand() #2
  %2 = zext i16 %1 to i32
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 6, i16 noundef zeroext 12, ptr noundef nonnull @.str.2, i32 noundef %2) #2
  tail call void @WaitForVBlank() #2
  %3 = load i16, ptr @pad_keys, align 2, !tbaa !5
  %4 = icmp eq i16 %3, 0
  br i1 %4, label %.lr.ph, label %.loopexit.backedge

.loopexit.backedge:                               ; preds = %.lr.ph, %.loopexit
  br label %.loopexit

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

declare void @consoleSetTextMapPtr(i16 noundef zeroext) local_unnamed_addr #1

declare void @consoleSetTextGfxPtr(i16 noundef zeroext) local_unnamed_addr #1

declare void @consoleSetTextOffset(i16 noundef zeroext) local_unnamed_addr #1

declare void @consoleInitText(i8 noundef zeroext, i8 noundef zeroext, ptr noundef, ptr noundef) local_unnamed_addr #1

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

declare void @bgSetGfxPtr(i8 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #1

declare void @bgSetMapPtr(i8 noundef zeroext, i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

declare void @setMode(i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

declare void @bgSetDisable(i8 noundef zeroext) local_unnamed_addr #1

declare void @setBrightness(i8 noundef zeroext) local_unnamed_addr #1

declare zeroext i16 @rand() local_unnamed_addr #1

declare void @WaitForVBlank() local_unnamed_addr #1

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


; Effective O3 passes: GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass