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

; 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.brrsamples = type { i8, i8, i8, i8, i8, i8, i8, i8 }

@bgcolor = external dso_local global i16, align 2
@keyapressed = external dso_local global i8, align 1
@snesfont = external global i8, align 1
@snespal = external global i8, align 1
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@soundbrrend = external global i8, align 1
@soundbrr = external global i8, align 1
@tadasound = external dso_local global %struct.brrsamples, 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 @spcBoot()
  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 @spcAllocateSoundRegion(i8 noundef zeroext 39)
  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 (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 5, i16 noundef zeroext 10, ptr noundef @.str)
  call void @setScreenOn()
  call void @spcSetSoundEntry(i8 noundef zeroext 15, i8 noundef zeroext 15, i8 noundef zeroext 4, i16 noundef zeroext trunc (i64 sub (i64 ptrtoint (ptr @soundbrrend to i64), i64 ptrtoint (ptr @soundbrr to i64)) to i16), ptr noundef @soundbrr, ptr noundef @tadasound)
  br label %2

2:                                                ; preds = %26, %0
  %3 = load i16, ptr @pad_keys, align 2, !tbaa !5
  %4 = zext i16 %3 to i32
  %5 = and i32 %4, 128
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %25

7:                                                ; preds = %2
  %8 = load i8, ptr @keyapressed, align 1, !tbaa !9
  %9 = zext i8 %8 to i32
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %24

11:                                               ; preds = %7
  store i8 1, ptr @keyapressed, align 1, !tbaa !9
  call void @spcPlaySound(i8 noundef zeroext 0)
  %12 = load i16, ptr @bgcolor, align 2, !tbaa !5
  %13 = zext i16 %12 to i32
  %14 = add nsw i32 %13, 16
  %15 = trunc i32 %14 to i16
  store i16 %15, ptr @bgcolor, align 2, !tbaa !5
  store volatile i8 0, ptr inttoptr (i64 8481 to ptr), align 1, !tbaa !9
  %16 = load i16, ptr @bgcolor, align 2, !tbaa !5
  %17 = zext i16 %16 to i32
  %18 = and i32 %17, 255
  %19 = trunc i32 %18 to i8
  store i8 %19, ptr inttoptr (i64 8482 to ptr), align 1, !tbaa !9
  %20 = load i16, ptr @bgcolor, align 2, !tbaa !5
  %21 = zext i16 %20 to i32
  %22 = ashr i32 %21, 8
  %23 = trunc i32 %22 to i8
  store i8 %23, ptr inttoptr (i64 8482 to ptr), align 1, !tbaa !9
  br label %24

24:                                               ; preds = %11, %7
  br label %26

25:                                               ; preds = %2
  store i8 0, ptr @keyapressed, align 1, !tbaa !9
  br label %26

26:                                               ; preds = %25, %24
  call void @spcProcess()
  call void @WaitForVBlank()
  br label %2
}

declare void @spcBoot() #1

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 @spcAllocateSoundRegion(i8 noundef zeroext) #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 @consoleDrawText(i16 noundef zeroext, i16 noundef zeroext, ptr noundef, ...) #1

declare void @setScreenOn() #1

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

declare void @spcPlaySound(i8 noundef zeroext) #1

declare void @spcProcess() #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 = !{!7, !7, i64 0}


; 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.brrsamples = type { i8, i8, i8, i8, i8, i8, i8, i8 }

@bgcolor = external dso_local local_unnamed_addr global i16, align 2
@keyapressed = external dso_local local_unnamed_addr global i8, align 1
@snesfont = external global i8, align 1
@snespal = external global i8, align 1
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@soundbrrend = external global i8, align 1
@soundbrr = external global i8, align 1
@tadasound = external dso_local global %struct.brrsamples, 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 @spcBoot() #2
  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 @spcAllocateSoundRegion(i8 noundef zeroext 39) #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 (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 5, i16 noundef zeroext 10, ptr noundef nonnull @.str) #2
  tail call void @setScreenOn() #2
  tail call void @spcSetSoundEntry(i8 noundef zeroext 15, i8 noundef zeroext 15, i8 noundef zeroext 4, i16 noundef zeroext trunc (i64 sub (i64 ptrtoint (ptr @soundbrrend to i64), i64 ptrtoint (ptr @soundbrr to i64)) to i16), ptr noundef nonnull @soundbrr, ptr noundef nonnull @tadasound) #2
  br label %1

1:                                                ; preds = %16, %0
  %2 = load i16, ptr @pad_keys, align 2, !tbaa !5
  %3 = and i16 %2, 128
  %.not = icmp eq i16 %3, 0
  br i1 %.not, label %15, label %4

4:                                                ; preds = %1
  %5 = load i8, ptr @keyapressed, align 1, !tbaa !9
  %6 = icmp eq i8 %5, 0
  br i1 %6, label %7, label %16

7:                                                ; preds = %4
  store i8 1, ptr @keyapressed, align 1, !tbaa !9
  tail call void @spcPlaySound(i8 noundef zeroext 0) #2
  %8 = load i16, ptr @bgcolor, align 2, !tbaa !5
  %9 = add i16 %8, 16
  store i16 %9, ptr @bgcolor, align 2, !tbaa !5
  store volatile i8 0, ptr inttoptr (i64 8481 to ptr), align 1, !tbaa !9
  %10 = load i16, ptr @bgcolor, align 2, !tbaa !5
  %11 = trunc i16 %10 to i8
  store i8 %11, ptr inttoptr (i64 8482 to ptr), align 2, !tbaa !9
  %12 = load i16, ptr @bgcolor, align 2, !tbaa !5
  %13 = lshr i16 %12, 8
  %14 = trunc nuw i16 %13 to i8
  store i8 %14, ptr inttoptr (i64 8482 to ptr), align 2, !tbaa !9
  br label %16

15:                                               ; preds = %1
  store i8 0, ptr @keyapressed, align 1, !tbaa !9
  br label %16

16:                                               ; preds = %4, %7, %15
  tail call void @spcProcess() #2
  tail call void @WaitForVBlank() #2
  br label %1
}

declare void @spcBoot() local_unnamed_addr #1

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 @spcAllocateSoundRegion(i8 noundef zeroext) 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 @consoleDrawText(i16 noundef zeroext, i16 noundef zeroext, ptr noundef, ...) local_unnamed_addr #1

declare void @setScreenOn() local_unnamed_addr #1

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

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

declare void @spcProcess() 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 = !{!7, !7, i64 0}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferAlignmentPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass