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

@dir = external dso_local constant [4 x %struct.Vec2], align 16
@pos = external dso_local global %struct.Vec2, align 2
@px = external dso_local global i16, align 2
@level = external dso_local global i16, align 2
@blockmap = external dso_local global [1024 x i16], align 16
@backmap = external dso_local global [1024 x i16], align 16
@blocks = external dso_local global [100 x i8], align 16
@b = external dso_local global i16, align 2
@i = external dso_local global i8, align 1
@blockcount = external dso_local global i16, align 2
@pad_keys = external global [5 x i16], align 2
@pad0 = external dso_local global i16, align 2
@vel = external dso_local global %struct.Vec2, align 2
@k = external dso_local global i8, align 1
@bx = external dso_local global i16, align 2
@obx = external dso_local global i16, align 2
@by = external dso_local global i16, align 2
@oby = external dso_local global i16, align 2
@score = external dso_local global i16, align 2
@hiscore = external dso_local global i16, align 2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @clamp(i16 noundef zeroext, 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

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

declare void @WaitForVBlank() #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @run_frame() #0 {
  %1 = load i16, ptr @pad_keys, align 2, !tbaa !5
  store i16 %1, ptr @pad0, align 2, !tbaa !5
  call void @handle_pause()
  %2 = load i16, ptr @pad0, align 2, !tbaa !5
  %3 = zext i16 %2 to i32
  %4 = and i32 %3, 128
  %5 = icmp ne i32 %4, 0
  br i1 %5, label %6, label %27

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

11:                                               ; preds = %6
  %12 = load i16, ptr @px, align 2, !tbaa !5
  %13 = zext i16 %12 to i32
  %14 = add nsw i32 %13, 4
  %15 = trunc i32 %14 to i16
  store i16 %15, ptr @px, align 2, !tbaa !5
  br label %16

16:                                               ; preds = %11, %6
  %17 = load i16, ptr @pad0, align 2, !tbaa !5
  %18 = zext i16 %17 to i32
  %19 = and i32 %18, 512
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %26

21:                                               ; preds = %16
  %22 = load i16, ptr @px, align 2, !tbaa !5
  %23 = zext i16 %22 to i32
  %24 = sub nsw i32 %23, 4
  %25 = trunc i32 %24 to i16
  store i16 %25, ptr @px, align 2, !tbaa !5
  br label %26

26:                                               ; preds = %21, %16
  br label %48

27:                                               ; preds = %0
  %28 = load i16, ptr @pad0, align 2, !tbaa !5
  %29 = zext i16 %28 to i32
  %30 = and i32 %29, 256
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %37

32:                                               ; preds = %27
  %33 = load i16, ptr @px, align 2, !tbaa !5
  %34 = zext i16 %33 to i32
  %35 = add nsw i32 %34, 2
  %36 = trunc i32 %35 to i16
  store i16 %36, ptr @px, align 2, !tbaa !5
  br label %37

37:                                               ; preds = %32, %27
  %38 = load i16, ptr @pad0, align 2, !tbaa !5
  %39 = zext i16 %38 to i32
  %40 = and i32 %39, 512
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %47

42:                                               ; preds = %37
  %43 = load i16, ptr @px, align 2, !tbaa !5
  %44 = zext i16 %43 to i32
  %45 = sub nsw i32 %44, 2
  %46 = trunc i32 %45 to i16
  store i16 %46, ptr @px, align 2, !tbaa !5
  br label %47

47:                                               ; preds = %42, %37
  br label %48

48:                                               ; preds = %47, %26
  %49 = load i16, ptr @px, align 2, !tbaa !5
  %50 = call zeroext i16 @clamp(i16 noundef zeroext %49, i16 noundef zeroext 16, i16 noundef zeroext 144)
  store i16 %50, ptr @px, align 2, !tbaa !5
  %51 = load i16, ptr @vel, align 2, !tbaa !9
  %52 = sext i16 %51 to i32
  %53 = load i16, ptr @pos, align 2, !tbaa !9
  %54 = sext i16 %53 to i32
  %55 = add nsw i32 %54, %52
  %56 = trunc i32 %55 to i16
  store i16 %56, ptr @pos, align 2, !tbaa !9
  %57 = load i16, ptr getelementptr inbounds (%struct.Vec2, ptr @vel, i32 0, i32 1), align 2, !tbaa !11
  %58 = sext i16 %57 to i32
  %59 = load i16, ptr getelementptr inbounds (%struct.Vec2, ptr @pos, i32 0, i32 1), align 2, !tbaa !11
  %60 = sext i16 %59 to i32
  %61 = add nsw i32 %60, %58
  %62 = trunc i32 %61 to i16
  store i16 %62, ptr getelementptr inbounds (%struct.Vec2, ptr @pos, i32 0, i32 1), align 2, !tbaa !11
  %63 = load i16, ptr @pos, align 2, !tbaa !9
  %64 = sext i16 %63 to i32
  %65 = icmp sgt i32 %64, 171
  br i1 %65, label %66, label %71

66:                                               ; preds = %48
  %67 = load i16, ptr @vel, align 2, !tbaa !9
  %68 = sext i16 %67 to i32
  %69 = sub nsw i32 0, %68
  %70 = trunc i32 %69 to i16
  store i16 %70, ptr @vel, align 2, !tbaa !9
  store i16 171, ptr @pos, align 2, !tbaa !9
  br label %81

71:                                               ; preds = %48
  %72 = load i16, ptr @pos, align 2, !tbaa !9
  %73 = sext i16 %72 to i32
  %74 = icmp slt i32 %73, 16
  br i1 %74, label %75, label %80

75:                                               ; preds = %71
  %76 = load i16, ptr @vel, align 2, !tbaa !9
  %77 = sext i16 %76 to i32
  %78 = sub nsw i32 0, %77
  %79 = trunc i32 %78 to i16
  store i16 %79, ptr @vel, align 2, !tbaa !9
  store i16 16, ptr @pos, align 2, !tbaa !9
  br label %80

80:                                               ; preds = %75, %71
  br label %81

81:                                               ; preds = %80, %66
  %82 = load i16, ptr getelementptr inbounds (%struct.Vec2, ptr @pos, i32 0, i32 1), align 2, !tbaa !11
  %83 = sext i16 %82 to i32
  %84 = icmp slt i32 %83, 15
  br i1 %84, label %85, label %90

85:                                               ; preds = %81
  %86 = load i16, ptr getelementptr inbounds (%struct.Vec2, ptr @vel, i32 0, i32 1), align 2, !tbaa !11
  %87 = sext i16 %86 to i32
  %88 = sub nsw i32 0, %87
  %89 = trunc i32 %88 to i16
  store i16 %89, ptr getelementptr inbounds (%struct.Vec2, ptr @vel, i32 0, i32 1), align 2, !tbaa !11
  br label %284

90:                                               ; preds = %81
  %91 = load i16, ptr getelementptr inbounds (%struct.Vec2, ptr @pos, i32 0, i32 1), align 2, !tbaa !11
  %92 = sext i16 %91 to i32
  %93 = icmp sgt i32 %92, 195
  br i1 %93, label %94, label %137

94:                                               ; preds = %90
  %95 = load i16, ptr getelementptr inbounds (%struct.Vec2, ptr @pos, i32 0, i32 1), align 2, !tbaa !11
  %96 = sext i16 %95 to i32
  %97 = icmp slt i32 %96, 203
  br i1 %97, label %98, label %130

98:                                               ; preds = %94
  %99 = load i16, ptr @pos, align 2, !tbaa !9
  %100 = sext i16 %99 to i32
  %101 = load i16, ptr @px, align 2, !tbaa !5
  %102 = zext i16 %101 to i32
  %103 = icmp sge i32 %100, %102
  br i1 %103, label %104, label %129

104:                                              ; preds = %98
  %105 = load i16, ptr @pos, align 2, !tbaa !9
  %106 = sext i16 %105 to i32
  %107 = load i16, ptr @px, align 2, !tbaa !5
  %108 = zext i16 %107 to i32
  %109 = add nsw i32 %108, 27
  %110 = icmp sle i32 %106, %109
  br i1 %110, label %111, label %129

111:                                              ; preds = %104
  %112 = load i16, ptr @pos, align 2, !tbaa !9
  %113 = sext i16 %112 to i32
  %114 = load i16, ptr @px, align 2, !tbaa !5
  %115 = zext i16 %114 to i32
  %116 = sub nsw i32 %113, %115
  %117 = sdiv i32 %116, 7
  %118 = trunc i32 %117 to i8
  store i8 %118, ptr @k, align 1, !tbaa !12
  %119 = load i8, ptr @k, align 1, !tbaa !12
  %120 = zext i8 %119 to i64
  %121 = getelementptr inbounds [4 x %struct.Vec2], ptr @dir, i64 0, i64 %120
  %122 = getelementptr inbounds %struct.Vec2, ptr %121, i32 0, i32 0
  %123 = load i16, ptr %122, align 4, !tbaa !9
  store i16 %123, ptr @vel, align 2, !tbaa !9
  %124 = load i8, ptr @k, align 1, !tbaa !12
  %125 = zext i8 %124 to i64
  %126 = getelementptr inbounds [4 x %struct.Vec2], ptr @dir, i64 0, i64 %125
  %127 = getelementptr inbounds %struct.Vec2, ptr %126, i32 0, i32 1
  %128 = load i16, ptr %127, align 2, !tbaa !11
  store i16 %128, ptr getelementptr inbounds (%struct.Vec2, ptr @vel, i32 0, i32 1), align 2, !tbaa !11
  br label %129

129:                                              ; preds = %111, %104, %98
  br label %136

130:                                              ; preds = %94
  %131 = load i16, ptr getelementptr inbounds (%struct.Vec2, ptr @pos, i32 0, i32 1), align 2, !tbaa !11
  %132 = sext i16 %131 to i32
  %133 = icmp sgt i32 %132, 224
  br i1 %133, label %134, label %135

134:                                              ; preds = %130
  call void @die()
  br label %135

135:                                              ; preds = %134, %130
  br label %136

136:                                              ; preds = %135, %129
  br label %283

137:                                              ; preds = %90
  %138 = load i16, ptr getelementptr inbounds (%struct.Vec2, ptr @pos, i32 0, i32 1), align 2, !tbaa !11
  %139 = sext i16 %138 to i32
  %140 = icmp slt i32 %139, 112
  br i1 %140, label %141, label %282

141:                                              ; preds = %137
  %142 = load i16, ptr @bx, align 2, !tbaa !5
  store i16 %142, ptr @obx, align 2, !tbaa !5
  %143 = load i16, ptr @by, align 2, !tbaa !5
  store i16 %143, ptr @oby, align 2, !tbaa !5
  %144 = load i16, ptr @pos, align 2, !tbaa !9
  %145 = sext i16 %144 to i32
  %146 = sub nsw i32 %145, 14
  %147 = ashr i32 %146, 4
  %148 = trunc i32 %147 to i16
  store i16 %148, ptr @bx, align 2, !tbaa !5
  %149 = load i16, ptr getelementptr inbounds (%struct.Vec2, ptr @pos, i32 0, i32 1), align 2, !tbaa !11
  %150 = sext i16 %149 to i32
  %151 = sub nsw i32 %150, 14
  %152 = ashr i32 %151, 3
  %153 = trunc i32 %152 to i16
  store i16 %153, ptr @by, align 2, !tbaa !5
  %154 = load i16, ptr @bx, align 2, !tbaa !5
  %155 = zext i16 %154 to i32
  %156 = load i16, ptr @by, align 2, !tbaa !5
  %157 = zext i16 %156 to i32
  %158 = shl i32 %157, 3
  %159 = add nsw i32 %155, %158
  %160 = load i16, ptr @by, align 2, !tbaa !5
  %161 = zext i16 %160 to i32
  %162 = shl i32 %161, 1
  %163 = add nsw i32 %159, %162
  %164 = sub nsw i32 %163, 10
  %165 = trunc i32 %164 to i16
  store i16 %165, ptr @b, align 2, !tbaa !5
  %166 = load i16, ptr @b, align 2, !tbaa !5
  %167 = zext i16 %166 to i32
  %168 = icmp sge i32 %167, 0
  br i1 %168, label %169, label %281

169:                                              ; preds = %141
  %170 = load i16, ptr @b, align 2, !tbaa !5
  %171 = zext i16 %170 to i32
  %172 = icmp slt i32 %171, 100
  br i1 %172, label %173, label %281

173:                                              ; preds = %169
  %174 = load i16, ptr @b, align 2, !tbaa !5
  %175 = zext i16 %174 to i64
  %176 = getelementptr inbounds [100 x i8], ptr @blocks, i64 0, i64 %175
  %177 = load i8, ptr %176, align 1, !tbaa !12
  %178 = zext i8 %177 to i32
  %179 = icmp ne i32 %178, 8
  br i1 %179, label %180, label %280

180:                                              ; preds = %173
  %181 = load i16, ptr @blockcount, align 2, !tbaa !5
  %182 = add i16 %181, -1
  store i16 %182, ptr @blockcount, align 2, !tbaa !5
  store i8 0, ptr @i, align 1, !tbaa !12
  br label %183

183:                                              ; preds = %200, %180
  %184 = load i8, ptr @i, align 1, !tbaa !12
  %185 = zext i8 %184 to i32
  %186 = load i16, ptr @level, align 2, !tbaa !5
  %187 = zext i16 %186 to i32
  %188 = icmp sle i32 %185, %187
  br i1 %188, label %189, label %203

189:                                              ; preds = %183
  %190 = load i16, ptr @b, align 2, !tbaa !5
  %191 = zext i16 %190 to i64
  %192 = getelementptr inbounds [100 x i8], ptr @blocks, i64 0, i64 %191
  %193 = load i8, ptr %192, align 1, !tbaa !12
  %194 = zext i8 %193 to i32
  %195 = add nsw i32 %194, 1
  %196 = load i16, ptr @score, align 2, !tbaa !5
  %197 = zext i16 %196 to i32
  %198 = add nsw i32 %197, %195
  %199 = trunc i32 %198 to i16
  store i16 %199, ptr @score, align 2, !tbaa !5
  br label %200

200:                                              ; preds = %189
  %201 = load i8, ptr @i, align 1, !tbaa !12
  %202 = add i8 %201, 1
  store i8 %202, ptr @i, align 1, !tbaa !12
  br label %183, !llvm.loop !13

203:                                              ; preds = %183
  %204 = load i16, ptr @oby, align 2, !tbaa !5
  %205 = zext i16 %204 to i32
  %206 = load i16, ptr @by, align 2, !tbaa !5
  %207 = zext i16 %206 to i32
  %208 = icmp ne i32 %205, %207
  br i1 %208, label %209, label %214

209:                                              ; preds = %203
  %210 = load i16, ptr getelementptr inbounds (%struct.Vec2, ptr @vel, i32 0, i32 1), align 2, !tbaa !11
  %211 = sext i16 %210 to i32
  %212 = sub nsw i32 0, %211
  %213 = trunc i32 %212 to i16
  store i16 %213, ptr getelementptr inbounds (%struct.Vec2, ptr @vel, i32 0, i32 1), align 2, !tbaa !11
  br label %214

214:                                              ; preds = %209, %203
  %215 = load i16, ptr @obx, align 2, !tbaa !5
  %216 = zext i16 %215 to i32
  %217 = load i16, ptr @bx, align 2, !tbaa !5
  %218 = zext i16 %217 to i32
  %219 = icmp ne i32 %216, %218
  br i1 %219, label %220, label %225

220:                                              ; preds = %214
  %221 = load i16, ptr @vel, align 2, !tbaa !9
  %222 = sext i16 %221 to i32
  %223 = sub nsw i32 0, %222
  %224 = trunc i32 %223 to i16
  store i16 %224, ptr @vel, align 2, !tbaa !9
  br label %225

225:                                              ; preds = %220, %214
  %226 = load i16, ptr @b, align 2, !tbaa !5
  %227 = zext i16 %226 to i64
  %228 = getelementptr inbounds [100 x i8], ptr @blocks, i64 0, i64 %227
  store i8 8, ptr %228, align 1, !tbaa !12
  %229 = load i16, ptr @by, align 2, !tbaa !5
  %230 = zext i16 %229 to i32
  %231 = shl i32 %230, 5
  %232 = load i16, ptr @bx, align 2, !tbaa !5
  %233 = zext i16 %232 to i32
  %234 = shl i32 %233, 1
  %235 = add nsw i32 %231, %234
  %236 = trunc i32 %235 to i16
  store i16 %236, ptr @b, align 2, !tbaa !5
  %237 = load i16, ptr @b, align 2, !tbaa !5
  %238 = zext i16 %237 to i32
  %239 = add nsw i32 66, %238
  %240 = sext i32 %239 to i64
  %241 = getelementptr inbounds [1024 x i16], ptr @blockmap, i64 0, i64 %240
  store i16 0, ptr %241, align 2, !tbaa !5
  %242 = load i16, ptr @b, align 2, !tbaa !5
  %243 = zext i16 %242 to i32
  %244 = add nsw i32 67, %243
  %245 = sext i32 %244 to i64
  %246 = getelementptr inbounds [1024 x i16], ptr @blockmap, i64 0, i64 %245
  store i16 0, ptr %246, align 2, !tbaa !5
  %247 = load i16, ptr @b, align 2, !tbaa !5
  %248 = zext i16 %247 to i32
  %249 = add nsw i32 99, %248
  %250 = sext i32 %249 to i64
  %251 = getelementptr inbounds [1024 x i16], ptr @backmap, i64 0, i64 %250
  %252 = load i16, ptr %251, align 2, !tbaa !5
  %253 = zext i16 %252 to i32
  %254 = sub nsw i32 %253, 1024
  %255 = trunc i32 %254 to i16
  store i16 %255, ptr %251, align 2, !tbaa !5
  %256 = load i16, ptr @b, align 2, !tbaa !5
  %257 = zext i16 %256 to i32
  %258 = add nsw i32 100, %257
  %259 = sext i32 %258 to i64
  %260 = getelementptr inbounds [1024 x i16], ptr @backmap, i64 0, i64 %259
  %261 = load i16, ptr %260, align 2, !tbaa !5
  %262 = zext i16 %261 to i32
  %263 = sub nsw i32 %262, 1024
  %264 = trunc i32 %263 to i16
  store i16 %264, ptr %260, align 2, !tbaa !5
  %265 = load i16, ptr @score, align 2, !tbaa !5
  call void @writenum(i16 noundef zeroext %265, i8 noundef zeroext 8, ptr noundef @blockmap, i16 noundef zeroext 245, i16 noundef zeroext 1062)
  %266 = load i16, ptr @score, align 2, !tbaa !5
  %267 = zext i16 %266 to i32
  %268 = load i16, ptr @hiscore, align 2, !tbaa !5
  %269 = zext i16 %268 to i32
  %270 = icmp sgt i32 %267, %269
  br i1 %270, label %271, label %274

271:                                              ; preds = %225
  %272 = load i16, ptr @score, align 2, !tbaa !5
  store i16 %272, ptr @hiscore, align 2, !tbaa !5
  %273 = load i16, ptr @score, align 2, !tbaa !5
  call void @writenum(i16 noundef zeroext %273, i8 noundef zeroext 8, ptr noundef @blockmap, i16 noundef zeroext 149, i16 noundef zeroext 1062)
  br label %274

274:                                              ; preds = %271, %225
  call void @WaitForVBlank()
  call void @dmaCopyVram(ptr noundef @blockmap, i16 noundef zeroext 0, i16 noundef zeroext 2048)
  call void @dmaCopyVram(ptr noundef @backmap, i16 noundef zeroext 1024, i16 noundef zeroext 2048)
  %275 = load i16, ptr @blockcount, align 2, !tbaa !5
  %276 = zext i16 %275 to i32
  %277 = icmp eq i32 %276, 0
  br i1 %277, label %278, label %279

278:                                              ; preds = %274
  call void @new_level()
  br label %279

279:                                              ; preds = %278, %274
  br label %280

280:                                              ; preds = %279, %173
  br label %281

281:                                              ; preds = %280, %169, %141
  br label %282

282:                                              ; preds = %281, %137
  br label %283

283:                                              ; preds = %282, %136
  br label %284

284:                                              ; preds = %283, %85
  call void @draw_screen()
  call void @WaitForVBlank()
  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 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 }

@dir = external dso_local local_unnamed_addr constant [4 x %struct.Vec2], align 16
@pos = external dso_local local_unnamed_addr global %struct.Vec2, align 2
@px = external dso_local local_unnamed_addr global i16, align 2
@level = external dso_local local_unnamed_addr global i16, align 2
@blockmap = external dso_local global [1024 x i16], align 16
@backmap = external dso_local global [1024 x i16], align 16
@blocks = external dso_local local_unnamed_addr global [100 x i8], align 16
@b = external dso_local local_unnamed_addr global i16, align 2
@i = external dso_local local_unnamed_addr global i8, align 1
@blockcount = external dso_local local_unnamed_addr global i16, align 2
@pad_keys = external local_unnamed_addr global [5 x i16], align 2
@pad0 = external dso_local local_unnamed_addr global i16, align 2
@vel = external dso_local local_unnamed_addr global %struct.Vec2, align 2
@k = external dso_local local_unnamed_addr global i8, align 1
@bx = external dso_local local_unnamed_addr global i16, align 2
@obx = external dso_local local_unnamed_addr global i16, align 2
@by = external dso_local local_unnamed_addr global i16, align 2
@oby = external dso_local local_unnamed_addr global i16, align 2
@score = external dso_local local_unnamed_addr global i16, align 2
@hiscore = external dso_local local_unnamed_addr global i16, align 2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @clamp(i16 noundef zeroext, 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

; Function Attrs: nounwind uwtable
declare dso_local void @new_level() 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
declare dso_local void @die() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @run_frame() local_unnamed_addr #0 {
  %1 = load i16, ptr @pad_keys, align 2, !tbaa !5
  store i16 %1, ptr @pad0, align 2, !tbaa !5
  tail call void @handle_pause()
  %2 = load i16, ptr @pad0, align 2, !tbaa !5
  %3 = zext i16 %2 to i32
  %4 = and i32 %3, 128
  %.not = icmp eq i32 %4, 0
  %5 = and i32 %3, 256
  %.not6 = icmp ne i32 %5, 0
  %.pre.pre = load i16, ptr @px, align 2, !tbaa !5
  %6 = and i16 %2, 512
  %.not7 = icmp ne i16 %6, 0
  %7 = or i1 %.not6, %.not7
  br i1 %.not, label %condstore.split23, label %condstore.split

condstore.split:                                  ; preds = %0
  %8 = add i16 %.pre.pre, 4
  %.pre19 = select i1 %.not6, i16 %8, i16 %.pre.pre
  %9 = add i16 %.pre19, -4
  %.ph = select i1 %.not7, i16 %9, i16 %.pre19
  br i1 %7, label %.sink.split, label %12

condstore.split23:                                ; preds = %0
  %10 = add i16 %.pre.pre, 2
  %.pre = select i1 %.not6, i16 %10, i16 %.pre.pre
  %11 = add i16 %.pre, -2
  %.ph24 = select i1 %.not7, i16 %11, i16 %.pre
  br i1 %7, label %.sink.split, label %12

.sink.split:                                      ; preds = %condstore.split23, %condstore.split
  %.ph24.sink = phi i16 [ %.ph, %condstore.split ], [ %.ph24, %condstore.split23 ]
  store i16 %.ph24.sink, ptr @px, align 2, !tbaa !5
  br label %12

12:                                               ; preds = %.sink.split, %condstore.split23, %condstore.split
  %13 = phi i16 [ %.ph, %condstore.split ], [ %.ph24, %condstore.split23 ], [ %.ph24.sink, %.sink.split ]
  %14 = tail call zeroext i16 @clamp(i16 noundef zeroext %13, i16 noundef zeroext 16, i16 noundef zeroext 144)
  store i16 %14, ptr @px, align 2, !tbaa !5
  %15 = load i16, ptr @vel, align 2, !tbaa !9
  %16 = load i16, ptr @pos, align 2, !tbaa !9
  %17 = add i16 %16, %15
  store i16 %17, ptr @pos, align 2, !tbaa !9
  %18 = load i16, ptr getelementptr inbounds (i8, ptr @vel, i64 2), align 2, !tbaa !11
  %19 = load i16, ptr getelementptr inbounds (i8, ptr @pos, i64 2), align 2, !tbaa !11
  %20 = add i16 %19, %18
  store i16 %20, ptr getelementptr inbounds (i8, ptr @pos, i64 2), align 2, !tbaa !11
  %21 = icmp sgt i16 %17, 171
  br i1 %21, label %.sink.split26, label %22

22:                                               ; preds = %12
  %23 = icmp slt i16 %17, 16
  br i1 %23, label %.sink.split26, label %25

.sink.split26:                                    ; preds = %22, %12
  %.sink = phi i16 [ 171, %12 ], [ 16, %22 ]
  %24 = sub i16 0, %15
  store i16 %24, ptr @vel, align 2, !tbaa !9
  store i16 %.sink, ptr @pos, align 2, !tbaa !9
  br label %25

25:                                               ; preds = %.sink.split26, %22
  %26 = phi i16 [ %15, %22 ], [ %24, %.sink.split26 ]
  %27 = phi i16 [ %17, %22 ], [ %.sink, %.sink.split26 ]
  %28 = icmp slt i16 %20, 15
  br i1 %28, label %29, label %31

29:                                               ; preds = %25
  %30 = sub i16 0, %18
  store i16 %30, ptr getelementptr inbounds (i8, ptr @vel, i64 2), align 2, !tbaa !11
  br label %122

31:                                               ; preds = %25
  %32 = icmp ugt i16 %20, 195
  br i1 %32, label %33, label %49

33:                                               ; preds = %31
  %34 = icmp ult i16 %20, 203
  br i1 %34, label %35, label %46

35:                                               ; preds = %33
  %36 = zext nneg i16 %27 to i32
  %37 = zext i16 %14 to i32
  %.not14 = icmp ult i16 %27, %14
  %38 = add nuw nsw i32 %37, 27
  %.not15 = icmp ult i32 %38, %36
  %or.cond = select i1 %.not14, i1 true, i1 %.not15
  br i1 %or.cond, label %122, label %39

39:                                               ; preds = %35
  %.lhs.trunc = sub nsw i16 %27, %14
  %40 = sdiv i16 %.lhs.trunc, 7
  %41 = trunc i16 %40 to i8
  store i8 %41, ptr @k, align 1, !tbaa !12
  %42 = and i16 %40, 255
  %43 = zext nneg i16 %42 to i64
  %44 = getelementptr inbounds [4 x %struct.Vec2], ptr @dir, i64 0, i64 %43
  %45 = load <2 x i16>, ptr %44, align 4, !tbaa !5
  store <2 x i16> %45, ptr @vel, align 2, !tbaa !5
  br label %122

46:                                               ; preds = %33
  %47 = icmp ugt i16 %20, 224
  br i1 %47, label %48, label %122

48:                                               ; preds = %46
  tail call void @die()
  br label %122

49:                                               ; preds = %31
  %50 = icmp ult i16 %20, 112
  br i1 %50, label %51, label %122

51:                                               ; preds = %49
  %52 = load i16, ptr @bx, align 2, !tbaa !5
  store i16 %52, ptr @obx, align 2, !tbaa !5
  %53 = load i16, ptr @by, align 2, !tbaa !5
  store i16 %53, ptr @oby, align 2, !tbaa !5
  %54 = zext nneg i16 %27 to i32
  %55 = add nuw nsw i32 %54, 1048562
  %56 = lshr i32 %55, 4
  %57 = trunc i32 %56 to i16
  store i16 %57, ptr @bx, align 2, !tbaa !5
  %58 = zext nneg i16 %20 to i32
  %59 = add nuw nsw i32 %58, 524274
  %60 = lshr i32 %59, 3
  %61 = trunc i32 %60 to i16
  store i16 %61, ptr @by, align 2, !tbaa !5
  %62 = and i32 %59, 65528
  %63 = shl nuw nsw i32 %60, 1
  %64 = add nuw nsw i32 %63, %62
  %65 = add nuw nsw i32 %64, %56
  %66 = trunc i32 %65 to i16
  %67 = add nsw i16 %66, -10
  store i16 %67, ptr @b, align 2, !tbaa !5
  %68 = icmp ult i16 %67, 100
  br i1 %68, label %69, label %122

69:                                               ; preds = %51
  %70 = zext nneg i16 %67 to i64
  %71 = getelementptr inbounds [100 x i8], ptr @blocks, i64 0, i64 %70
  %72 = load i8, ptr %71, align 1, !tbaa !12
  %.not10 = icmp eq i8 %72, 8
  br i1 %.not10, label %122, label %73

73:                                               ; preds = %69
  %74 = load i16, ptr @blockcount, align 2, !tbaa !5
  %75 = add i16 %74, -1
  store i16 %75, ptr @blockcount, align 2, !tbaa !5
  %76 = load i16, ptr @level, align 2, !tbaa !5
  %score.promoted = load i16, ptr @score, align 2, !tbaa !5
  %77 = zext i8 %72 to i16
  %78 = add nuw nsw i16 %77, 1
  %79 = add i16 %76, 1
  %80 = tail call i16 @llvm.umax.i16(i16 %79, i16 1)
  %umax31 = zext i16 %80 to i32
  %min.iters.check = icmp ult i16 %79, 24
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %73
  %81 = add i16 %76, 1
  %umax = tail call i16 @llvm.umax.i16(i16 %81, i16 1)
  %82 = add i16 %umax, -1
  %83 = and i16 %82, 255
  %84 = icmp eq i16 %83, 255
  %85 = icmp ugt i16 %82, 255
  %86 = or i1 %84, %85
  br i1 %86, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i32 %umax31, 65520
  %ind.end = trunc i32 %n.vec to i8
  %87 = insertelement <8 x i16> <i16 poison, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>, i16 %score.promoted, i64 0
  %broadcast.splatinsert = insertelement <8 x i16> poison, i16 %78, i64 0
  %broadcast.splat = shufflevector <8 x i16> %broadcast.splatinsert, <8 x i16> poison, <8 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <8 x i16> [ %87, %vector.ph ], [ %88, %vector.body ]
  %vec.phi32 = phi <8 x i16> [ zeroinitializer, %vector.ph ], [ %89, %vector.body ]
  %88 = add <8 x i16> %broadcast.splat, %vec.phi
  %89 = add <8 x i16> %broadcast.splat, %vec.phi32
  %index.next = add nuw i32 %index, 16
  %90 = icmp eq i32 %index.next, %n.vec
  br i1 %90, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <8 x i16> %89, %88
  %91 = tail call i16 @llvm.vector.reduce.add.v8i16(<8 x i16> %bin.rdx)
  %cmp.n = icmp eq i32 %n.vec, %umax31
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.scevcheck, %73
  %storemerge17.ph = phi i8 [ 0, %vector.scevcheck ], [ 0, %73 ], [ %ind.end, %middle.block ]
  %.ph33 = phi i16 [ %score.promoted, %vector.scevcheck ], [ %score.promoted, %73 ], [ %91, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %storemerge17 = phi i8 [ %94, %scalar.ph ], [ %storemerge17.ph, %scalar.ph.preheader ]
  %92 = phi i16 [ %93, %scalar.ph ], [ %.ph33, %scalar.ph.preheader ]
  %93 = add i16 %78, %92
  %94 = add i8 %storemerge17, 1
  %95 = zext i8 %94 to i16
  %.not11 = icmp ult i16 %76, %95
  br i1 %.not11, label %.loopexit, label %scalar.ph, !llvm.loop !17

.loopexit:                                        ; preds = %scalar.ph, %middle.block
  %.lcssa30 = phi i16 [ %91, %middle.block ], [ %93, %scalar.ph ]
  %.lcssa = phi i8 [ %ind.end, %middle.block ], [ %94, %scalar.ph ]
  store i16 %.lcssa30, ptr @score, align 2, !tbaa !5
  store i8 %.lcssa, ptr @i, align 1, !tbaa !12
  %.not12 = icmp eq i16 %53, %61
  br i1 %.not12, label %98, label %96

96:                                               ; preds = %.loopexit
  %97 = sub i16 0, %18
  store i16 %97, ptr getelementptr inbounds (i8, ptr @vel, i64 2), align 2, !tbaa !11
  br label %98

98:                                               ; preds = %96, %.loopexit
  %.not13 = icmp eq i16 %52, %57
  br i1 %.not13, label %101, label %99

99:                                               ; preds = %98
  %100 = sub i16 0, %26
  store i16 %100, ptr @vel, align 2, !tbaa !9
  br label %101

101:                                              ; preds = %99, %98
  store i8 8, ptr %71, align 1, !tbaa !12
  %102 = shl i16 %61, 5
  %103 = shl nsw i16 %57, 1
  %104 = add i16 %103, %102
  store i16 %104, ptr @b, align 2, !tbaa !5
  %105 = zext i16 %104 to i64
  %106 = add nuw nsw i64 %105, 66
  %107 = getelementptr inbounds [1024 x i16], ptr @blockmap, i64 0, i64 %106
  store i16 0, ptr %107, align 4, !tbaa !5
  %108 = add nuw nsw i64 %105, 67
  %109 = getelementptr inbounds [1024 x i16], ptr @blockmap, i64 0, i64 %108
  store i16 0, ptr %109, align 2, !tbaa !5
  %110 = add nuw nsw i64 %105, 99
  %111 = getelementptr inbounds [1024 x i16], ptr @backmap, i64 0, i64 %110
  %112 = load <2 x i16>, ptr %111, align 2, !tbaa !5
  %113 = add <2 x i16> %112, <i16 -1024, i16 -1024>
  store <2 x i16> %113, ptr %111, align 2, !tbaa !5
  tail call void @writenum(i16 noundef zeroext %.lcssa30, i8 noundef zeroext 8, ptr noundef nonnull @blockmap, i16 noundef zeroext 245, i16 noundef zeroext 1062)
  %114 = load i16, ptr @score, align 2, !tbaa !5
  %115 = load i16, ptr @hiscore, align 2, !tbaa !5
  %116 = icmp ugt i16 %114, %115
  br i1 %116, label %117, label %118

117:                                              ; preds = %101
  store i16 %114, ptr @hiscore, align 2, !tbaa !5
  tail call void @writenum(i16 noundef zeroext %114, i8 noundef zeroext 8, ptr noundef nonnull @blockmap, i16 noundef zeroext 149, i16 noundef zeroext 1062)
  br label %118

118:                                              ; preds = %117, %101
  tail call void @WaitForVBlank() #3
  tail call void @dmaCopyVram(ptr noundef nonnull @blockmap, i16 noundef zeroext 0, i16 noundef zeroext 2048) #3
  tail call void @dmaCopyVram(ptr noundef nonnull @backmap, i16 noundef zeroext 1024, i16 noundef zeroext 2048) #3
  %119 = load i16, ptr @blockcount, align 2, !tbaa !5
  %120 = icmp eq i16 %119, 0
  br i1 %120, label %121, label %122

121:                                              ; preds = %118
  tail call void @new_level()
  br label %122

122:                                              ; preds = %46, %48, %35, %39, %51, %118, %121, %69, %49, %29
  tail call void @draw_screen()
  tail call void @WaitForVBlank() #3
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.vector.reduce.add.v8i16(<8 x i16>) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 2}
!11 = !{!10, !6, i64 2}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !14, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SCCPPass,SLPVectorizerPass,SimplifyCFGPass,TailCallElimPass