; LLVM IR from alekmaul/pvsneslib :: snes-examples/graphics/Sprites/ObjectSize (ObjectSize)

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

@selectedItem = external dso_local global i16, align 2
@snesfont = external global i8, align 1
@snespal = external global i8, align 1
@keyPressed = external dso_local global i8, align 1
@pad_keys = external global [5 x i16], align 2
@pad0 = external dso_local global i16, align 2

; Function Attrs: nounwind uwtable
declare dso_local void @draw() #0

; Function Attrs: nounwind uwtable
declare dso_local void @changeObjSize() #0

declare void @WaitForVBlank() #1

; 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 @bgSetGfxPtr(i8 noundef zeroext 0, i16 noundef zeroext 8192)
  call void @bgSetMapPtr(i8 noundef zeroext 0, i16 noundef zeroext 26627, 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)
  store i16 0, ptr @selectedItem, align 2, !tbaa !5
  store i8 0, ptr @keyPressed, align 1, !tbaa !9
  call void @draw()
  call void @changeObjSize()
  call void @setScreenOn()
  br label %2

2:                                                ; preds = %40, %0
  %3 = load i16, ptr @pad_keys, align 2, !tbaa !5
  store i16 %3, ptr @pad0, align 2, !tbaa !5
  %4 = load i16, ptr @pad0, align 2, !tbaa !5
  %5 = icmp ne i16 %4, 0
  br i1 %5, label %6, label %39

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

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

15:                                               ; preds = %11
  %16 = load i8, ptr @keyPressed, align 1, !tbaa !9
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %21, label %18

18:                                               ; preds = %15
  %19 = load i16, ptr @selectedItem, align 2, !tbaa !5
  %20 = add i16 %19, -1
  store i16 %20, ptr @selectedItem, align 2, !tbaa !5
  call void @draw()
  call void @changeObjSize()
  store i8 -1, ptr @keyPressed, align 1, !tbaa !9
  br label %21

21:                                               ; preds = %18, %15, %11
  br label %22

22:                                               ; preds = %21, %6
  %23 = load i16, ptr @pad0, align 2, !tbaa !5
  %24 = zext i16 %23 to i32
  %25 = and i32 %24, 1024
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %38

27:                                               ; preds = %22
  %28 = load i16, ptr @selectedItem, align 2, !tbaa !5
  %29 = zext i16 %28 to i32
  %30 = icmp slt i32 %29, 5
  br i1 %30, label %31, label %37

31:                                               ; preds = %27
  %32 = load i8, ptr @keyPressed, align 1, !tbaa !9
  %33 = icmp ne i8 %32, 0
  br i1 %33, label %37, label %34

34:                                               ; preds = %31
  %35 = load i16, ptr @selectedItem, align 2, !tbaa !5
  %36 = add i16 %35, 1
  store i16 %36, ptr @selectedItem, align 2, !tbaa !5
  call void @draw()
  call void @changeObjSize()
  store i8 -1, ptr @keyPressed, align 1, !tbaa !9
  br label %37

37:                                               ; preds = %34, %31, %27
  br label %38

38:                                               ; preds = %37, %22
  br label %40

39:                                               ; preds = %2
  store i8 0, ptr @keyPressed, align 1, !tbaa !9
  br label %40

40:                                               ; preds = %39, %38
  call void @WaitForVBlank()
  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 @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 @setScreenOn() #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"

@selectedItem = external dso_local local_unnamed_addr global i16, align 2
@snesfont = external global i8, align 1
@snespal = external global i8, align 1
@keyPressed = external dso_local local_unnamed_addr global i8, align 1
@pad_keys = external local_unnamed_addr global [5 x i16], align 2
@pad0 = external dso_local local_unnamed_addr global i16, align 2

; Function Attrs: nounwind uwtable
declare dso_local void @draw() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @changeObjSize() local_unnamed_addr #0

declare void @WaitForVBlank() local_unnamed_addr #1

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  tail call void @consoleSetTextMapPtr(i16 noundef zeroext 26624) #3
  tail call void @consoleSetTextGfxPtr(i16 noundef zeroext 12288) #3
  tail call void @consoleSetTextOffset(i16 noundef zeroext 256) #3
  tail call void @consoleInitText(i8 noundef zeroext 0, i8 noundef zeroext 32, ptr noundef nonnull @snesfont, ptr noundef nonnull @snespal) #3
  tail call void @bgSetGfxPtr(i8 noundef zeroext 0, i16 noundef zeroext 8192) #3
  tail call void @bgSetMapPtr(i8 noundef zeroext 0, i16 noundef zeroext 26627, i8 noundef zeroext 0) #3
  tail call void @setMode(i8 noundef zeroext 1, i8 noundef zeroext 0) #3
  tail call void @bgSetDisable(i8 noundef zeroext 1) #3
  tail call void @bgSetDisable(i8 noundef zeroext 2) #3
  store i16 0, ptr @selectedItem, align 2, !tbaa !5
  store i8 0, ptr @keyPressed, align 1, !tbaa !9
  tail call void @draw()
  tail call void @changeObjSize()
  tail call void @setScreenOn() #3
  br label %1

1:                                                ; preds = %22, %0
  %2 = load i16, ptr @pad_keys, align 2, !tbaa !5
  store i16 %2, ptr @pad0, align 2, !tbaa !5
  %.not = icmp eq i16 %2, 0
  br i1 %.not, label %.sink.split, label %3

3:                                                ; preds = %1
  %4 = and i16 %2, 2048
  %.not4 = icmp eq i16 %4, 0
  br i1 %.not4, label %12, label %5

5:                                                ; preds = %3
  %6 = load i16, ptr @selectedItem, align 2, !tbaa !5
  %7 = icmp eq i16 %6, 0
  %8 = load i8, ptr @keyPressed, align 1
  %9 = icmp ne i8 %8, 0
  %or.cond = select i1 %7, i1 true, i1 %9
  br i1 %or.cond, label %12, label %10

10:                                               ; preds = %5
  %11 = add i16 %6, -1
  store i16 %11, ptr @selectedItem, align 2, !tbaa !5
  tail call void @draw()
  tail call void @changeObjSize()
  store i8 -1, ptr @keyPressed, align 1, !tbaa !9
  %.pre = load i16, ptr @pad0, align 2, !tbaa !5
  br label %12

12:                                               ; preds = %5, %10, %3
  %13 = phi i16 [ %2, %5 ], [ %.pre, %10 ], [ %2, %3 ]
  %14 = and i16 %13, 1024
  %.not5 = icmp eq i16 %14, 0
  br i1 %.not5, label %22, label %15

15:                                               ; preds = %12
  %16 = load i16, ptr @selectedItem, align 2, !tbaa !5
  %17 = icmp ugt i16 %16, 4
  %18 = load i8, ptr @keyPressed, align 1
  %19 = icmp ne i8 %18, 0
  %or.cond3 = select i1 %17, i1 true, i1 %19
  br i1 %or.cond3, label %22, label %20

20:                                               ; preds = %15
  %21 = add nuw nsw i16 %16, 1
  store i16 %21, ptr @selectedItem, align 2, !tbaa !5
  tail call void @draw()
  tail call void @changeObjSize()
  br label %.sink.split

.sink.split:                                      ; preds = %1, %20
  %.sink = phi i8 [ -1, %20 ], [ 0, %1 ]
  store i8 %.sink, ptr @keyPressed, align 1, !tbaa !9
  br label %22

22:                                               ; preds = %.sink.split, %12, %15
  tail call void @WaitForVBlank() #3
  br label %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 @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 @setScreenOn() local_unnamed_addr #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" }
attributes #2 = { 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 #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 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass