; LLVM IR from alekmaul/pvsneslib :: snes-examples/input/mouse-data-test (mouse-data-test)

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

@LABELS = external dso_local constant [6 x ptr], align 16
@BUTTON_STRINGS = external dso_local constant [4 x ptr], align 16
@CURSOR_TILE = external dso_local constant <{ [13 x i8], [19 x i8] }>, align 16
@CURSOR_PALETTE = external dso_local constant [4 x i16], align 2
@cursor_xPos = external dso_local global i16, align 2
@cursor_yPos = external dso_local global i16, align 2
@Font_Tiles = external global i8, align 1
@Font_Palette = external global i8, align 1
@.str.10 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [3 x i8], align 1
@oamMemory = external global [544 x i8], align 16
@.str.16 = external hidden unnamed_addr constant [25 x i8], align 1
@mouseConnect = external global [2 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [25 x i8], align 1
@mouse_x = external global [2 x i8], align 1
@mouse_y = external global [2 x i8], align 1
@pad_keysdown = external global [5 x i16], align 2
@pad_keys = external global [5 x i16], align 2
@mousePressed = external global [2 x i8], align 1
@mouseButton = external global [2 x i8], align 1
@mouseSensitivity = external global [2 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [3 x i8], align 1
@lag_frame_counter = external global i16, align 2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i16, align 2
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 2, ptr %2) #3
  call void @consoleInit()
  call void @setMode(i8 noundef zeroext 1, i8 noundef zeroext 0)
  call void @bgSetDisable(i8 noundef zeroext 0)
  call void @bgSetDisable(i8 noundef zeroext 1)
  call void @bgSetGfxPtr(i8 noundef zeroext 2, i16 noundef zeroext 4096)
  call void @bgSetMapPtr(i8 noundef zeroext 2, i16 noundef zeroext 0, i8 noundef zeroext 0)
  call void @oamInitGfxSet(ptr noundef @CURSOR_TILE, i16 noundef zeroext 32, ptr noundef @CURSOR_PALETTE, i16 noundef zeroext 8, i8 noundef zeroext 0, i16 noundef zeroext 24576, i8 noundef zeroext 0)
  call void @consoleSetTextMapPtr(i16 noundef zeroext 0)
  call void @consoleSetTextGfxPtr(i16 noundef zeroext 4096)
  call void @consoleSetTextOffset(i16 noundef zeroext 0)
  call void @consoleInitText(i8 noundef zeroext 0, i8 noundef zeroext 8, ptr noundef @Font_Tiles, ptr noundef @Font_Palette)
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 2, ptr noundef @.str.10)
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 22, ptr noundef @.str.11, i32 noundef 1)
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 5, i16 noundef zeroext 23, ptr noundef @.str.12)
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 5, i16 noundef zeroext 24, ptr noundef @.str.13)
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 5, i16 noundef zeroext 25, ptr noundef @.str.14)
  store i16 0, ptr %2, align 2, !tbaa !5
  br label %3

3:                                                ; preds = %17, %0
  %4 = load i16, ptr %2, align 2, !tbaa !5
  %5 = zext i16 %4 to i32
  %6 = icmp slt i32 %5, 6
  br i1 %6, label %7, label %20

7:                                                ; preds = %3
  %8 = load i16, ptr %2, align 2, !tbaa !5
  %9 = zext i16 %8 to i32
  %10 = mul nsw i32 %9, 2
  %11 = add nsw i32 8, %10
  %12 = trunc i32 %11 to i16
  %13 = load i16, ptr %2, align 2, !tbaa !5
  %14 = zext i16 %13 to i64
  %15 = getelementptr inbounds [6 x ptr], ptr @LABELS, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext %12, ptr noundef @.str.15, ptr noundef %16)
  br label %17

17:                                               ; preds = %7
  %18 = load i16, ptr %2, align 2, !tbaa !5
  %19 = add i16 %18, 1
  store i16 %19, ptr %2, align 2, !tbaa !5
  br label %3, !llvm.loop !11

20:                                               ; preds = %3
  %21 = load i16, ptr @cursor_xPos, align 2, !tbaa !5
  %22 = trunc i16 %21 to i8
  store i8 %22, ptr @oamMemory, align 16, !tbaa !13
  %23 = load i16, ptr @cursor_yPos, align 2, !tbaa !5
  %24 = trunc i16 %23 to i8
  store i8 %24, ptr getelementptr inbounds ([544 x i8], ptr @oamMemory, i64 0, i64 1), align 1, !tbaa !13
  store i8 0, ptr getelementptr inbounds ([544 x i8], ptr @oamMemory, i64 0, i64 2), align 2, !tbaa !13
  store i8 48, ptr getelementptr inbounds ([544 x i8], ptr @oamMemory, i64 0, i64 3), align 1, !tbaa !13
  store i8 0, ptr getelementptr inbounds ([544 x i8], ptr @oamMemory, i64 0, i64 512), align 16, !tbaa !13
  call void @initMouse(i8 noundef zeroext 1)
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 4, ptr noundef @.str.16, i32 noundef 2)
  call void @setScreenOn()
  br label %25

25:                                               ; preds = %148, %20
  br label %26

26:                                               ; preds = %25
  call void @WaitForVBlank()
  %27 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mouseConnect, i64 0, i64 1), align 1, !tbaa !13
  %28 = zext i8 %27 to i32
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %37

30:                                               ; preds = %26
  br label %31

31:                                               ; preds = %35, %30
  %32 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mouseConnect, i64 0, i64 1), align 1, !tbaa !13
  %33 = zext i8 %32 to i32
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %31
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 4, ptr noundef @.str.17, i32 noundef 2)
  call void @WaitForVBlank()
  br label %31, !llvm.loop !14

36:                                               ; preds = %31
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 4, ptr noundef @.str.16, i32 noundef 2)
  call void @WaitForVBlank()
  br label %37

37:                                               ; preds = %36, %26
  %38 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mouse_x, i64 0, i64 1), align 1, !tbaa !13
  %39 = zext i8 %38 to i32
  %40 = and i32 %39, 128
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %55

42:                                               ; preds = %37
  %43 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mouse_x, i64 0, i64 1), align 1, !tbaa !13
  %44 = zext i8 %43 to i32
  %45 = and i32 %44, 126
  %46 = load i16, ptr @cursor_xPos, align 2, !tbaa !5
  %47 = zext i16 %46 to i32
  %48 = sub nsw i32 %47, %45
  %49 = trunc i32 %48 to i16
  store i16 %49, ptr @cursor_xPos, align 2, !tbaa !5
  %50 = load i16, ptr @cursor_xPos, align 2, !tbaa !5
  %51 = zext i16 %50 to i32
  %52 = icmp sge i32 %51, 32768
  br i1 %52, label %53, label %54

53:                                               ; preds = %42
  store i16 0, ptr @cursor_xPos, align 2, !tbaa !5
  br label %54

54:                                               ; preds = %53, %42
  br label %67

55:                                               ; preds = %37
  %56 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mouse_x, i64 0, i64 1), align 1, !tbaa !13
  %57 = zext i8 %56 to i32
  %58 = load i16, ptr @cursor_xPos, align 2, !tbaa !5
  %59 = zext i16 %58 to i32
  %60 = add nsw i32 %59, %57
  %61 = trunc i32 %60 to i16
  store i16 %61, ptr @cursor_xPos, align 2, !tbaa !5
  %62 = load i16, ptr @cursor_xPos, align 2, !tbaa !5
  %63 = zext i16 %62 to i32
  %64 = icmp sge i32 %63, 256
  br i1 %64, label %65, label %66

65:                                               ; preds = %55
  store i16 255, ptr @cursor_xPos, align 2, !tbaa !5
  br label %66

66:                                               ; preds = %65, %55
  br label %67

67:                                               ; preds = %66, %54
  %68 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mouse_y, i64 0, i64 1), align 1, !tbaa !13
  %69 = zext i8 %68 to i32
  %70 = and i32 %69, 128
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %85

72:                                               ; preds = %67
  %73 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mouse_y, i64 0, i64 1), align 1, !tbaa !13
  %74 = zext i8 %73 to i32
  %75 = and i32 %74, 126
  %76 = load i16, ptr @cursor_yPos, align 2, !tbaa !5
  %77 = zext i16 %76 to i32
  %78 = sub nsw i32 %77, %75
  %79 = trunc i32 %78 to i16
  store i16 %79, ptr @cursor_yPos, align 2, !tbaa !5
  %80 = load i16, ptr @cursor_yPos, align 2, !tbaa !5
  %81 = zext i16 %80 to i32
  %82 = icmp sge i32 %81, 32768
  br i1 %82, label %83, label %84

83:                                               ; preds = %72
  store i16 0, ptr @cursor_yPos, align 2, !tbaa !5
  br label %84

84:                                               ; preds = %83, %72
  br label %97

85:                                               ; preds = %67
  %86 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mouse_y, i64 0, i64 1), align 1, !tbaa !13
  %87 = zext i8 %86 to i32
  %88 = load i16, ptr @cursor_yPos, align 2, !tbaa !5
  %89 = zext i16 %88 to i32
  %90 = add nsw i32 %89, %87
  %91 = trunc i32 %90 to i16
  store i16 %91, ptr @cursor_yPos, align 2, !tbaa !5
  %92 = load i16, ptr @cursor_yPos, align 2, !tbaa !5
  %93 = zext i16 %92 to i32
  %94 = icmp sge i32 %93, 225
  br i1 %94, label %95, label %96

95:                                               ; preds = %85
  store i16 224, ptr @cursor_yPos, align 2, !tbaa !5
  br label %96

96:                                               ; preds = %95, %85
  br label %97

97:                                               ; preds = %96, %84
  %98 = load i16, ptr @pad_keysdown, align 2, !tbaa !5
  %99 = zext i16 %98 to i32
  %100 = and i32 %99, 16624
  %101 = icmp ne i32 %100, 0
  br i1 %101, label %102, label %133

102:                                              ; preds = %97
  %103 = load i16, ptr @pad_keysdown, align 2, !tbaa !5
  %104 = zext i16 %103 to i32
  %105 = and i32 %104, 16384
  %106 = icmp ne i32 %105, 0
  br i1 %106, label %107, label %108

107:                                              ; preds = %102
  call void @mouseSetSensitivity(i16 noundef zeroext 1, i8 noundef zeroext 0)
  br label %108

108:                                              ; preds = %107, %102
  %109 = load i16, ptr @pad_keysdown, align 2, !tbaa !5
  %110 = zext i16 %109 to i32
  %111 = and i32 %110, 64
  %112 = icmp ne i32 %111, 0
  br i1 %112, label %113, label %114

113:                                              ; preds = %108
  call void @mouseSetSensitivity(i16 noundef zeroext 1, i8 noundef zeroext 1)
  br label %114

114:                                              ; preds = %113, %108
  %115 = load i16, ptr @pad_keysdown, align 2, !tbaa !5
  %116 = zext i16 %115 to i32
  %117 = and i32 %116, 128
  %118 = icmp ne i32 %117, 0
  br i1 %118, label %119, label %120

119:                                              ; preds = %114
  call void @mouseSetSensitivity(i16 noundef zeroext 1, i8 noundef zeroext 2)
  br label %120

120:                                              ; preds = %119, %114
  %121 = load i16, ptr @pad_keysdown, align 2, !tbaa !5
  %122 = zext i16 %121 to i32
  %123 = and i32 %122, 16
  %124 = icmp ne i32 %123, 0
  br i1 %124, label %125, label %126

125:                                              ; preds = %120
  call void @mouseCycleSensitivity(i16 noundef zeroext 1)
  br label %126

126:                                              ; preds = %125, %120
  %127 = load i16, ptr @pad_keysdown, align 2, !tbaa !5
  %128 = zext i16 %127 to i32
  %129 = and i32 %128, 32
  %130 = icmp ne i32 %129, 0
  br i1 %130, label %131, label %132

131:                                              ; preds = %126
  call void @mouseCycleSensitivityTwice(i16 noundef zeroext 1)
  br label %132

132:                                              ; preds = %131, %126
  br label %133

133:                                              ; preds = %132, %97
  %134 = load i16, ptr @pad_keys, align 2, !tbaa !5
  %135 = zext i16 %134 to i32
  %136 = and i32 %135, 32768
  %137 = icmp ne i32 %136, 0
  br i1 %137, label %138, label %148

138:                                              ; preds = %133
  store i16 0, ptr %2, align 2, !tbaa !5
  br label %139

139:                                              ; preds = %144, %138
  %140 = load i16, ptr %2, align 2, !tbaa !5
  %141 = zext i16 %140 to i32
  %142 = icmp slt i32 %141, 1500
  br i1 %142, label %143, label %147

143:                                              ; preds = %139
  br label %144

144:                                              ; preds = %143
  %145 = load i16, ptr %2, align 2, !tbaa !5
  %146 = add i16 %145, 1
  store i16 %146, ptr %2, align 2, !tbaa !5
  br label %139, !llvm.loop !15

147:                                              ; preds = %139
  br label %148

148:                                              ; preds = %147, %133
  %149 = load i16, ptr @cursor_xPos, align 2, !tbaa !5
  %150 = trunc i16 %149 to i8
  store i8 %150, ptr @oamMemory, align 16, !tbaa !13
  %151 = load i16, ptr @cursor_yPos, align 2, !tbaa !5
  %152 = trunc i16 %151 to i8
  store i8 %152, ptr getelementptr inbounds ([544 x i8], ptr @oamMemory, i64 0, i64 1), align 1, !tbaa !13
  %153 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mousePressed, i64 0, i64 1), align 1, !tbaa !13
  %154 = zext i8 %153 to i32
  %155 = and i32 %154, 3
  %156 = sext i32 %155 to i64
  %157 = getelementptr inbounds [4 x ptr], ptr @BUTTON_STRINGS, i64 0, i64 %156
  %158 = load ptr, ptr %157, align 8, !tbaa !9
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 18, i16 noundef zeroext 8, ptr noundef %158)
  %159 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mouseButton, i64 0, i64 1), align 1, !tbaa !13
  %160 = zext i8 %159 to i32
  %161 = and i32 %160, 3
  %162 = sext i32 %161 to i64
  %163 = getelementptr inbounds [4 x ptr], ptr @BUTTON_STRINGS, i64 0, i64 %162
  %164 = load ptr, ptr %163, align 8, !tbaa !9
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 26, i16 noundef zeroext 8, ptr noundef %164)
  %165 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mouseSensitivity, i64 0, i64 1), align 1, !tbaa !13
  %166 = zext i8 %165 to i16
  call void @printU8(i16 noundef zeroext 18, i16 noundef zeroext 10, i16 noundef zeroext %166)
  %167 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mouse_x, i64 0, i64 1), align 1, !tbaa !13
  %168 = zext i8 %167 to i16
  call void @drawMouseDelta(i16 noundef zeroext 18, i16 noundef zeroext %168)
  %169 = load i8, ptr getelementptr inbounds ([2 x i8], ptr @mouse_y, i64 0, i64 1), align 1, !tbaa !13
  %170 = zext i8 %169 to i16
  call void @drawMouseDelta(i16 noundef zeroext 26, i16 noundef zeroext %170)
  %171 = load i16, ptr @cursor_xPos, align 2, !tbaa !5
  call void @printU8(i16 noundef zeroext 18, i16 noundef zeroext 14, i16 noundef zeroext %171)
  %172 = load i16, ptr @cursor_yPos, align 2, !tbaa !5
  call void @printU8(i16 noundef zeroext 26, i16 noundef zeroext 14, i16 noundef zeroext %172)
  %173 = load i16, ptr @lag_frame_counter, align 2, !tbaa !5
  %174 = zext i16 %173 to i32
  call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 18, i16 noundef zeroext 18, ptr noundef @.str.18, i32 noundef %174)
  br label %25
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare void @consoleInit() #2

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

declare void @bgSetDisable(i8 noundef zeroext) #2

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

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

declare void @oamInitGfxSet(ptr noundef, i16 noundef zeroext, ptr noundef, i16 noundef zeroext, i8 noundef zeroext, i16 noundef zeroext, i8 noundef zeroext) #2

declare void @consoleSetTextMapPtr(i16 noundef zeroext) #2

declare void @consoleSetTextGfxPtr(i16 noundef zeroext) #2

declare void @consoleSetTextOffset(i16 noundef zeroext) #2

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

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

declare void @initMouse(i8 noundef zeroext) #2

declare void @setScreenOn() #2

declare void @WaitForVBlank() #2

declare void @mouseSetSensitivity(i16 noundef zeroext, i8 noundef zeroext) #2

declare void @mouseCycleSensitivity(i16 noundef zeroext) #2

declare void @mouseCycleSensitivityTwice(i16 noundef zeroext) #2

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


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

@LABELS = external dso_local local_unnamed_addr constant [6 x ptr], align 16
@BUTTON_STRINGS = external dso_local local_unnamed_addr constant [4 x ptr], align 16
@CURSOR_TILE = external dso_local constant <{ [13 x i8], [19 x i8] }>, align 16
@CURSOR_PALETTE = external dso_local constant [4 x i16], align 2
@cursor_xPos = external dso_local local_unnamed_addr global i16, align 2
@cursor_yPos = external dso_local local_unnamed_addr global i16, align 2
@Font_Tiles = external global i8, align 1
@Font_Palette = external global i8, align 1
@.str.10 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [3 x i8], align 1
@oamMemory = external local_unnamed_addr global [544 x i8], align 16
@.str.16 = external hidden unnamed_addr constant [25 x i8], align 1
@mouseConnect = external local_unnamed_addr global [2 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [25 x i8], align 1
@mouse_x = external local_unnamed_addr global [2 x i8], align 1
@mouse_y = external local_unnamed_addr global [2 x i8], align 1
@pad_keysdown = external local_unnamed_addr global [5 x i16], align 2
@mousePressed = external local_unnamed_addr global [2 x i8], align 1
@mouseButton = external local_unnamed_addr global [2 x i8], align 1
@mouseSensitivity = external local_unnamed_addr global [2 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [3 x i8], align 1
@lag_frame_counter = external local_unnamed_addr global i16, align 2

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  tail call void @consoleInit() #4
  tail call void @setMode(i8 noundef zeroext 1, i8 noundef zeroext 0) #4
  tail call void @bgSetDisable(i8 noundef zeroext 0) #4
  tail call void @bgSetDisable(i8 noundef zeroext 1) #4
  tail call void @bgSetGfxPtr(i8 noundef zeroext 2, i16 noundef zeroext 4096) #4
  tail call void @bgSetMapPtr(i8 noundef zeroext 2, i16 noundef zeroext 0, i8 noundef zeroext 0) #4
  tail call void @oamInitGfxSet(ptr noundef nonnull @CURSOR_TILE, i16 noundef zeroext 32, ptr noundef nonnull @CURSOR_PALETTE, i16 noundef zeroext 8, i8 noundef zeroext 0, i16 noundef zeroext 24576, i8 noundef zeroext 0) #4
  tail call void @consoleSetTextMapPtr(i16 noundef zeroext 0) #4
  tail call void @consoleSetTextGfxPtr(i16 noundef zeroext 4096) #4
  tail call void @consoleSetTextOffset(i16 noundef zeroext 0) #4
  tail call void @consoleInitText(i8 noundef zeroext 0, i8 noundef zeroext 8, ptr noundef nonnull @Font_Tiles, ptr noundef nonnull @Font_Palette) #4
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 2, ptr noundef nonnull @.str.10) #4
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 22, ptr noundef nonnull @.str.11, i32 noundef 1) #4
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 5, i16 noundef zeroext 23, ptr noundef nonnull @.str.12) #4
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 5, i16 noundef zeroext 24, ptr noundef nonnull @.str.13) #4
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 5, i16 noundef zeroext 25, ptr noundef nonnull @.str.14) #4
  %1 = load ptr, ptr @LABELS, align 16, !tbaa !5
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 8, ptr noundef nonnull @.str.15, ptr noundef %1) #4
  %2 = load ptr, ptr getelementptr inbounds (i8, ptr @LABELS, i64 8), align 8, !tbaa !5
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 10, ptr noundef nonnull @.str.15, ptr noundef %2) #4
  %3 = load ptr, ptr getelementptr inbounds (i8, ptr @LABELS, i64 16), align 16, !tbaa !5
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 12, ptr noundef nonnull @.str.15, ptr noundef %3) #4
  %4 = load ptr, ptr getelementptr inbounds (i8, ptr @LABELS, i64 24), align 8, !tbaa !5
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 14, ptr noundef nonnull @.str.15, ptr noundef %4) #4
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @LABELS, i64 32), align 16, !tbaa !5
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 16, ptr noundef nonnull @.str.15, ptr noundef %5) #4
  %6 = load ptr, ptr getelementptr inbounds (i8, ptr @LABELS, i64 40), align 8, !tbaa !5
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 18, ptr noundef nonnull @.str.15, ptr noundef %6) #4
  %7 = load i16, ptr @cursor_xPos, align 2, !tbaa !9
  %8 = trunc i16 %7 to i8
  store i8 %8, ptr @oamMemory, align 16, !tbaa !11
  %9 = load i16, ptr @cursor_yPos, align 2, !tbaa !9
  %10 = trunc i16 %9 to i8
  store i8 %10, ptr getelementptr inbounds (i8, ptr @oamMemory, i64 1), align 1, !tbaa !11
  store i8 0, ptr getelementptr inbounds (i8, ptr @oamMemory, i64 2), align 2, !tbaa !11
  store i8 48, ptr getelementptr inbounds (i8, ptr @oamMemory, i64 3), align 1, !tbaa !11
  store i8 0, ptr getelementptr inbounds (i8, ptr @oamMemory, i64 512), align 16, !tbaa !11
  tail call void @initMouse(i8 noundef zeroext 1) #4
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 4, ptr noundef nonnull @.str.16, i32 noundef 2) #4
  tail call void @setScreenOn() #4
  br label %11

11:                                               ; preds = %.loopexit, %0
  tail call void @WaitForVBlank() #4
  %12 = load i8, ptr getelementptr inbounds (i8, ptr @mouseConnect, i64 1), align 1, !tbaa !11
  %13 = icmp eq i8 %12, 0
  br i1 %13, label %.preheader19, label %16

.preheader19:                                     ; preds = %11, %.preheader19
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 4, ptr noundef nonnull @.str.17, i32 noundef 2) #4
  tail call void @WaitForVBlank() #4
  %.pr = load i8, ptr getelementptr inbounds (i8, ptr @mouseConnect, i64 1), align 1, !tbaa !11
  %14 = icmp eq i8 %.pr, 0
  br i1 %14, label %.preheader19, label %15, !llvm.loop !12

15:                                               ; preds = %.preheader19
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 2, i16 noundef zeroext 4, ptr noundef nonnull @.str.16, i32 noundef 2) #4
  tail call void @WaitForVBlank() #4
  br label %16

16:                                               ; preds = %15, %11
  %17 = load i8, ptr getelementptr inbounds (i8, ptr @mouse_x, i64 1), align 1, !tbaa !11
  %.not = icmp sgt i8 %17, -1
  br i1 %.not, label %23, label %18

18:                                               ; preds = %16
  %19 = and i8 %17, 126
  %20 = zext nneg i8 %19 to i16
  %21 = load i16, ptr @cursor_xPos, align 2, !tbaa !9
  %22 = sub i16 %21, %20
  %spec.store.select = tail call i16 @llvm.smax.i16(i16 %22, i16 0)
  br label %27

23:                                               ; preds = %16
  %24 = load i16, ptr @cursor_xPos, align 2, !tbaa !9
  %25 = zext nneg i8 %17 to i16
  %26 = add i16 %24, %25
  %spec.store.select1 = tail call i16 @llvm.umin.i16(i16 %26, i16 255)
  br label %27

27:                                               ; preds = %23, %18
  %storemerge = phi i16 [ %spec.store.select1, %23 ], [ %spec.store.select, %18 ]
  store i16 %storemerge, ptr @cursor_xPos, align 2
  %28 = load i8, ptr getelementptr inbounds (i8, ptr @mouse_y, i64 1), align 1, !tbaa !11
  %.not10 = icmp sgt i8 %28, -1
  br i1 %.not10, label %34, label %29

29:                                               ; preds = %27
  %30 = and i8 %28, 126
  %31 = zext nneg i8 %30 to i16
  %32 = load i16, ptr @cursor_yPos, align 2, !tbaa !9
  %33 = sub i16 %32, %31
  %spec.store.select2 = tail call i16 @llvm.smax.i16(i16 %33, i16 0)
  br label %38

34:                                               ; preds = %27
  %35 = load i16, ptr @cursor_yPos, align 2, !tbaa !9
  %36 = zext nneg i8 %28 to i16
  %37 = add i16 %35, %36
  %spec.store.select3 = tail call i16 @llvm.umin.i16(i16 %37, i16 224)
  br label %38

38:                                               ; preds = %34, %29
  %storemerge11 = phi i16 [ %spec.store.select3, %34 ], [ %spec.store.select2, %29 ]
  store i16 %storemerge11, ptr @cursor_yPos, align 2
  %39 = load i16, ptr @pad_keysdown, align 2, !tbaa !9
  %40 = zext i16 %39 to i32
  %41 = and i32 %40, 16624
  %.not12 = icmp eq i32 %41, 0
  br i1 %.not12, label %.loopexit, label %42

42:                                               ; preds = %38
  %43 = and i32 %40, 16384
  %.not13 = icmp eq i32 %43, 0
  br i1 %.not13, label %45, label %44

44:                                               ; preds = %42
  tail call void @mouseSetSensitivity(i16 noundef zeroext 1, i8 noundef zeroext 0) #4
  %.pre = load i16, ptr @pad_keysdown, align 2, !tbaa !9
  br label %45

45:                                               ; preds = %44, %42
  %46 = phi i16 [ %.pre, %44 ], [ %39, %42 ]
  %47 = and i16 %46, 64
  %.not14 = icmp eq i16 %47, 0
  br i1 %.not14, label %49, label %48

48:                                               ; preds = %45
  tail call void @mouseSetSensitivity(i16 noundef zeroext 1, i8 noundef zeroext 1) #4
  %.pre23 = load i16, ptr @pad_keysdown, align 2, !tbaa !9
  br label %49

49:                                               ; preds = %48, %45
  %50 = phi i16 [ %.pre23, %48 ], [ %46, %45 ]
  %51 = and i16 %50, 128
  %.not15 = icmp eq i16 %51, 0
  br i1 %.not15, label %53, label %52

52:                                               ; preds = %49
  tail call void @mouseSetSensitivity(i16 noundef zeroext 1, i8 noundef zeroext 2) #4
  %.pre24 = load i16, ptr @pad_keysdown, align 2, !tbaa !9
  br label %53

53:                                               ; preds = %52, %49
  %54 = phi i16 [ %.pre24, %52 ], [ %50, %49 ]
  %55 = and i16 %54, 16
  %.not16 = icmp eq i16 %55, 0
  br i1 %.not16, label %57, label %56

56:                                               ; preds = %53
  tail call void @mouseCycleSensitivity(i16 noundef zeroext 1) #4
  %.pre25 = load i16, ptr @pad_keysdown, align 2, !tbaa !9
  br label %57

57:                                               ; preds = %56, %53
  %58 = phi i16 [ %.pre25, %56 ], [ %54, %53 ]
  %59 = and i16 %58, 32
  %.not17 = icmp eq i16 %59, 0
  br i1 %.not17, label %.loopexit, label %60

60:                                               ; preds = %57
  tail call void @mouseCycleSensitivityTwice(i16 noundef zeroext 1) #4
  br label %.loopexit

.loopexit:                                        ; preds = %38, %60, %57
  %61 = load i16, ptr @cursor_xPos, align 2, !tbaa !9
  %62 = trunc i16 %61 to i8
  store i8 %62, ptr @oamMemory, align 16, !tbaa !11
  %63 = load i16, ptr @cursor_yPos, align 2, !tbaa !9
  %64 = trunc i16 %63 to i8
  store i8 %64, ptr getelementptr inbounds (i8, ptr @oamMemory, i64 1), align 1, !tbaa !11
  %65 = load i8, ptr getelementptr inbounds (i8, ptr @mousePressed, i64 1), align 1, !tbaa !11
  %66 = and i8 %65, 3
  %67 = zext nneg i8 %66 to i64
  %68 = getelementptr inbounds [4 x ptr], ptr @BUTTON_STRINGS, i64 0, i64 %67
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 18, i16 noundef zeroext 8, ptr noundef %69) #4
  %70 = load i8, ptr getelementptr inbounds (i8, ptr @mouseButton, i64 1), align 1, !tbaa !11
  %71 = and i8 %70, 3
  %72 = zext nneg i8 %71 to i64
  %73 = getelementptr inbounds [4 x ptr], ptr @BUTTON_STRINGS, i64 0, i64 %72
  %74 = load ptr, ptr %73, align 8, !tbaa !5
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 26, i16 noundef zeroext 8, ptr noundef %74) #4
  %75 = load i8, ptr getelementptr inbounds (i8, ptr @mouseSensitivity, i64 1), align 1, !tbaa !11
  %76 = zext i8 %75 to i16
  tail call void @printU8(i16 noundef zeroext 18, i16 noundef zeroext 10, i16 noundef zeroext %76)
  %77 = load i8, ptr getelementptr inbounds (i8, ptr @mouse_x, i64 1), align 1, !tbaa !11
  %78 = zext i8 %77 to i16
  tail call void @drawMouseDelta(i16 noundef zeroext 18, i16 noundef zeroext %78)
  %79 = load i8, ptr getelementptr inbounds (i8, ptr @mouse_y, i64 1), align 1, !tbaa !11
  %80 = zext i8 %79 to i16
  tail call void @drawMouseDelta(i16 noundef zeroext 26, i16 noundef zeroext %80)
  %81 = load i16, ptr @cursor_xPos, align 2, !tbaa !9
  tail call void @printU8(i16 noundef zeroext 18, i16 noundef zeroext 14, i16 noundef zeroext %81)
  %82 = load i16, ptr @cursor_yPos, align 2, !tbaa !9
  tail call void @printU8(i16 noundef zeroext 26, i16 noundef zeroext 14, i16 noundef zeroext %82)
  %83 = load i16, ptr @lag_frame_counter, align 2, !tbaa !9
  %84 = zext i16 %83 to i32
  tail call void (i16, i16, ptr, ...) @consoleDrawText(i16 noundef zeroext 18, i16 noundef zeroext 18, ptr noundef nonnull @.str.18, i32 noundef %84) #4
  br label %11
}

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

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

declare void @setScreenOn() local_unnamed_addr #1

declare void @WaitForVBlank() local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @printU8(i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @drawMouseDelta(i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.umin.i16(i16, i16) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.smax.i16(i16, i16) #3

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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass