; LLVM IR from Stephane-D/SGDK :: src (joy)

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

@gport = external hidden global i16, align 2
@portType = external hidden global [2 x i8], align 1
@portSupport = external hidden global [2 x i8], align 1
@joyType = external hidden global [8 x i8], align 1
@joyState = external hidden global [8 x i16], align 16
@joyAxisX = external hidden global [8 x i16], align 16
@joyAxisY = external hidden global [8 x i16], align 16
@gun = external hidden global i8, align 1
@extSet = external hidden global i8, align 1

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

declare zeroext i8 @Z80_getAndRequestBus(i8 noundef zeroext) #1

declare void @Z80_releaseBus() #1

; Function Attrs: noinline nounwind uwtable
define dso_local void @JOY_setSupport(i16 noundef zeroext %0, i16 noundef zeroext %1) #2 {
  %3 = alloca i16, align 2
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  store i16 %0, ptr %3, align 2, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #4
  %11 = load i16, ptr %3, align 2, !tbaa !5
  %12 = zext i16 %11 to i32
  %13 = icmp sgt i32 %12, 1
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i32 1, ptr %6, align 4
  br label %313

15:                                               ; preds = %2
  %16 = load i16, ptr %3, align 2, !tbaa !5
  %17 = zext i16 %16 to i64
  %18 = getelementptr inbounds [2 x i8], ptr @portType, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %29, label %22

22:                                               ; preds = %15
  %23 = load i16, ptr %3, align 2, !tbaa !5
  %24 = zext i16 %23 to i64
  %25 = getelementptr inbounds [2 x i8], ptr @portType, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = zext i8 %26 to i32
  %28 = icmp eq i32 %27, 1
  br i1 %28, label %29, label %208

29:                                               ; preds = %22, %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  %30 = load i16, ptr %4, align 2, !tbaa !5
  %31 = zext i16 %30 to i32
  %32 = icmp eq i32 %31, 8
  br i1 %32, label %41, label %33

33:                                               ; preds = %29
  %34 = load i16, ptr %4, align 2, !tbaa !5
  %35 = zext i16 %34 to i32
  %36 = icmp eq i32 %35, 9
  br i1 %36, label %41, label %37

37:                                               ; preds = %33
  %38 = load i16, ptr %4, align 2, !tbaa !5
  %39 = zext i16 %38 to i32
  %40 = icmp eq i32 %39, 7
  br i1 %40, label %41, label %124

41:                                               ; preds = %37, %33, %29
  %42 = load i16, ptr %3, align 2, !tbaa !5
  %43 = zext i16 %42 to i64
  %44 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !9
  %46 = zext i8 %45 to i32
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %123

48:                                               ; preds = %41
  call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 7)
  %49 = load i16, ptr %4, align 2, !tbaa !5
  %50 = zext i16 %49 to i32
  %51 = icmp eq i32 %50, 7
  %52 = zext i1 %51 to i64
  %53 = select i1 %51, i32 4, i32 5
  %54 = trunc i32 %53 to i8
  %55 = load i16, ptr %3, align 2, !tbaa !5
  %56 = zext i16 %55 to i64
  %57 = getelementptr inbounds [8 x i8], ptr @joyType, i64 0, i64 %56
  store volatile i8 %54, ptr %57, align 1, !tbaa !9
  %58 = load i16, ptr %3, align 2, !tbaa !5
  %59 = zext i16 %58 to i64
  %60 = getelementptr inbounds [8 x i16], ptr @joyState, i64 0, i64 %59
  store volatile i16 0, ptr %60, align 2, !tbaa !5
  %61 = load i16, ptr %3, align 2, !tbaa !5
  %62 = zext i16 %61 to i64
  %63 = getelementptr inbounds [8 x i16], ptr @joyAxisX, i64 0, i64 %62
  store volatile i16 -1, ptr %63, align 2, !tbaa !5
  %64 = load i16, ptr %3, align 2, !tbaa !5
  %65 = zext i16 %64 to i64
  %66 = getelementptr inbounds [8 x i16], ptr @joyAxisY, i64 0, i64 %65
  store volatile i16 -1, ptr %66, align 2, !tbaa !5
  store i8 0, ptr @gun, align 1, !tbaa !9
  store i8 0, ptr @extSet, align 1, !tbaa !9
  %67 = load i16, ptr %3, align 2, !tbaa !5
  store i16 %67, ptr @gport, align 2, !tbaa !5
  %68 = load i16, ptr %4, align 2, !tbaa !5
  %69 = zext i16 %68 to i32
  %70 = icmp eq i32 %69, 9
  br i1 %70, label %71, label %100

71:                                               ; preds = %48
  %72 = load i16, ptr %3, align 2, !tbaa !5
  %73 = zext i16 %72 to i32
  %74 = icmp ne i32 %73, 0
  %75 = zext i1 %74 to i64
  %76 = select i1 %74, i32 5, i32 2
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [8 x i8], ptr @joyType, i64 0, i64 %77
  store volatile i8 5, ptr %78, align 1, !tbaa !9
  %79 = load i16, ptr %3, align 2, !tbaa !5
  %80 = zext i16 %79 to i32
  %81 = icmp ne i32 %80, 0
  %82 = zext i1 %81 to i64
  %83 = select i1 %81, i32 5, i32 2
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [8 x i16], ptr @joyState, i64 0, i64 %84
  store volatile i16 0, ptr %85, align 2, !tbaa !5
  %86 = load i16, ptr %3, align 2, !tbaa !5
  %87 = zext i16 %86 to i32
  %88 = icmp ne i32 %87, 0
  %89 = zext i1 %88 to i64
  %90 = select i1 %88, i32 5, i32 2
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [8 x i16], ptr @joyAxisX, i64 0, i64 %91
  store volatile i16 -1, ptr %92, align 2, !tbaa !5
  %93 = load i16, ptr %3, align 2, !tbaa !5
  %94 = zext i16 %93 to i32
  %95 = icmp ne i32 %94, 0
  %96 = zext i1 %95 to i64
  %97 = select i1 %95, i32 5, i32 2
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [8 x i16], ptr @joyAxisY, i64 0, i64 %98
  store volatile i16 -1, ptr %99, align 2, !tbaa !5
  br label %100

100:                                              ; preds = %71, %48
  call void @SYS_setExtIntCallback(ptr noundef @externalIntCB)
  %101 = call zeroext i8 @Z80_getAndRequestBus(i8 noundef zeroext 1)
  %102 = zext i8 %101 to i16
  store i16 %102, ptr %5, align 2, !tbaa !5
  %103 = load i16, ptr %3, align 2, !tbaa !5
  %104 = zext i16 %103 to i32
  %105 = mul nsw i32 %104, 2
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds i8, ptr inttoptr (i64 10551305 to ptr), i64 %106
  store ptr %107, ptr %7, align 8, !tbaa !10
  %108 = load ptr, ptr %7, align 8, !tbaa !10
  store volatile i8 -80, ptr %108, align 1, !tbaa !9
  %109 = load i16, ptr %5, align 2, !tbaa !5
  %110 = icmp ne i16 %109, 0
  br i1 %110, label %112, label %111

111:                                              ; preds = %100
  call void @Z80_releaseBus()
  br label %112

112:                                              ; preds = %111, %100
  call void @VDP_setHVLatching(i8 noundef zeroext 1)
  %113 = call zeroext i8 @VDP_getReg(i16 noundef zeroext 11)
  store i8 %113, ptr %8, align 1, !tbaa !9
  %114 = load i8, ptr %8, align 1, !tbaa !9
  %115 = zext i8 %114 to i32
  %116 = or i32 %115, 8
  %117 = trunc i32 %116 to i8
  call void @VDP_setReg(i16 noundef zeroext 11, i8 noundef zeroext %117)
  call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 1)
  %118 = load i16, ptr %4, align 2, !tbaa !5
  %119 = trunc i16 %118 to i8
  %120 = load i16, ptr %3, align 2, !tbaa !5
  %121 = zext i16 %120 to i64
  %122 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %121
  store i8 %119, ptr %122, align 1, !tbaa !9
  br label %123

123:                                              ; preds = %112, %41
  br label %207

124:                                              ; preds = %37
  %125 = load i16, ptr %4, align 2, !tbaa !5
  %126 = zext i16 %125 to i32
  %127 = icmp eq i32 %126, 0
  br i1 %127, label %128, label %177

128:                                              ; preds = %124
  %129 = load i16, ptr %3, align 2, !tbaa !5
  %130 = zext i16 %129 to i64
  %131 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %130
  %132 = load i8, ptr %131, align 1, !tbaa !9
  %133 = zext i8 %132 to i32
  %134 = icmp eq i32 %133, 8
  br i1 %134, label %149, label %135

135:                                              ; preds = %128
  %136 = load i16, ptr %3, align 2, !tbaa !5
  %137 = zext i16 %136 to i64
  %138 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %137
  %139 = load i8, ptr %138, align 1, !tbaa !9
  %140 = zext i8 %139 to i32
  %141 = icmp eq i32 %140, 9
  br i1 %141, label %149, label %142

142:                                              ; preds = %135
  %143 = load i16, ptr %3, align 2, !tbaa !5
  %144 = zext i16 %143 to i64
  %145 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %144
  %146 = load i8, ptr %145, align 1, !tbaa !9
  %147 = zext i8 %146 to i32
  %148 = icmp eq i32 %147, 7
  br i1 %148, label %149, label %173

149:                                              ; preds = %142, %135, %128
  call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 7)
  %150 = call zeroext i8 @Z80_getAndRequestBus(i8 noundef zeroext 1)
  %151 = zext i8 %150 to i16
  store i16 %151, ptr %5, align 2, !tbaa !5
  %152 = load i16, ptr %3, align 2, !tbaa !5
  %153 = zext i16 %152 to i32
  %154 = mul nsw i32 %153, 2
  %155 = sext i32 %154 to i64
  %156 = getelementptr inbounds i8, ptr inttoptr (i64 10551305 to ptr), i64 %155
  store ptr %156, ptr %7, align 8, !tbaa !10
  %157 = load ptr, ptr %7, align 8, !tbaa !10
  store volatile i8 48, ptr %157, align 1, !tbaa !9
  %158 = load i16, ptr %5, align 2, !tbaa !5
  %159 = icmp ne i16 %158, 0
  br i1 %159, label %161, label %160

160:                                              ; preds = %149
  call void @Z80_releaseBus()
  br label %161

161:                                              ; preds = %160, %149
  call void @VDP_setHVLatching(i8 noundef zeroext 0)
  %162 = call zeroext i8 @VDP_getReg(i16 noundef zeroext 11)
  store i8 %162, ptr %8, align 1, !tbaa !9
  %163 = load i8, ptr %8, align 1, !tbaa !9
  %164 = zext i8 %163 to i32
  %165 = and i32 %164, -9
  %166 = trunc i32 %165 to i8
  call void @VDP_setReg(i16 noundef zeroext 11, i8 noundef zeroext %166)
  call void @SYS_setExtIntCallback(ptr noundef null)
  %167 = load i16, ptr %3, align 2, !tbaa !5
  %168 = zext i16 %167 to i32
  %169 = icmp eq i32 %168, 0
  br i1 %169, label %170, label %171

170:                                              ; preds = %161
  store volatile i8 15, ptr @joyType, align 1, !tbaa !9
  store volatile i8 15, ptr getelementptr inbounds ([8 x i8], ptr @joyType, i64 0, i64 2), align 1, !tbaa !9
  store volatile i16 0, ptr @joyState, align 16, !tbaa !5
  store volatile i16 0, ptr getelementptr inbounds ([8 x i16], ptr @joyState, i64 0, i64 2), align 4, !tbaa !5
  br label %172

171:                                              ; preds = %161
  store volatile i8 15, ptr getelementptr inbounds ([8 x i8], ptr @joyType, i64 0, i64 1), align 1, !tbaa !9
  store volatile i8 15, ptr getelementptr inbounds ([8 x i8], ptr @joyType, i64 0, i64 5), align 1, !tbaa !9
  store volatile i16 0, ptr getelementptr inbounds ([8 x i16], ptr @joyState, i64 0, i64 1), align 2, !tbaa !5
  store volatile i16 0, ptr getelementptr inbounds ([8 x i16], ptr @joyState, i64 0, i64 5), align 2, !tbaa !5
  br label %172

172:                                              ; preds = %171, %170
  store i16 -1, ptr @gport, align 2, !tbaa !5
  call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 3)
  br label %173

173:                                              ; preds = %172, %142
  %174 = load i16, ptr %3, align 2, !tbaa !5
  %175 = zext i16 %174 to i64
  %176 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %175
  store i8 0, ptr %176, align 1, !tbaa !9
  br label %206

177:                                              ; preds = %124
  %178 = load i16, ptr %4, align 2, !tbaa !5
  %179 = zext i16 %178 to i32
  %180 = icmp eq i32 %179, 4
  br i1 %180, label %181, label %205

181:                                              ; preds = %177
  %182 = call zeroext i8 @Z80_getAndRequestBus(i8 noundef zeroext 1)
  %183 = zext i8 %182 to i16
  store i16 %183, ptr %5, align 2, !tbaa !5
  %184 = load i16, ptr %3, align 2, !tbaa !5
  %185 = zext i16 %184 to i32
  %186 = mul nsw i32 %185, 2
  %187 = sext i32 %186 to i64
  %188 = getelementptr inbounds i8, ptr inttoptr (i64 10551305 to ptr), i64 %187
  store ptr %188, ptr %7, align 8, !tbaa !10
  %189 = load ptr, ptr %7, align 8, !tbaa !10
  store volatile i8 64, ptr %189, align 1, !tbaa !9
  %190 = load i16, ptr %3, align 2, !tbaa !5
  %191 = zext i16 %190 to i32
  %192 = mul nsw i32 %191, 2
  %193 = sext i32 %192 to i64
  %194 = getelementptr inbounds i8, ptr inttoptr (i64 10551299 to ptr), i64 %193
  store ptr %194, ptr %7, align 8, !tbaa !10
  %195 = load ptr, ptr %7, align 8, !tbaa !10
  store volatile i8 64, ptr %195, align 1, !tbaa !9
  %196 = load i16, ptr %5, align 2, !tbaa !5
  %197 = icmp ne i16 %196, 0
  br i1 %197, label %199, label %198

198:                                              ; preds = %181
  call void @Z80_releaseBus()
  br label %199

199:                                              ; preds = %198, %181
  %200 = load i16, ptr %4, align 2, !tbaa !5
  %201 = trunc i16 %200 to i8
  %202 = load i16, ptr %3, align 2, !tbaa !5
  %203 = zext i16 %202 to i64
  %204 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %203
  store i8 %201, ptr %204, align 1, !tbaa !9
  br label %205

205:                                              ; preds = %199, %177
  br label %206

206:                                              ; preds = %205, %173
  br label %207

207:                                              ; preds = %206, %123
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %312

208:                                              ; preds = %22
  %209 = load i16, ptr %4, align 2, !tbaa !5
  %210 = zext i16 %209 to i32
  %211 = icmp eq i32 %210, 10
  br i1 %211, label %216, label %212

212:                                              ; preds = %208
  %213 = load i16, ptr %4, align 2, !tbaa !5
  %214 = zext i16 %213 to i32
  %215 = icmp eq i32 %214, 0
  br i1 %215, label %216, label %305

216:                                              ; preds = %212, %208
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  %217 = load i16, ptr %4, align 2, !tbaa !5
  %218 = zext i16 %217 to i32
  %219 = icmp eq i32 %218, 10
  br i1 %219, label %220, label %264

220:                                              ; preds = %216
  %221 = load i16, ptr %3, align 2, !tbaa !5
  %222 = zext i16 %221 to i64
  %223 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %222
  %224 = load i8, ptr %223, align 1, !tbaa !9
  %225 = zext i8 %224 to i32
  %226 = icmp eq i32 %225, 0
  br i1 %226, label %227, label %263

227:                                              ; preds = %220
  call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 7)
  %228 = load i16, ptr %3, align 2, !tbaa !5
  %229 = zext i16 %228 to i64
  %230 = getelementptr inbounds [8 x i8], ptr @joyType, i64 0, i64 %229
  store volatile i8 6, ptr %230, align 1, !tbaa !9
  %231 = load i16, ptr %3, align 2, !tbaa !5
  %232 = zext i16 %231 to i64
  %233 = getelementptr inbounds [8 x i16], ptr @joyState, i64 0, i64 %232
  store volatile i16 0, ptr %233, align 2, !tbaa !5
  %234 = load i16, ptr %3, align 2, !tbaa !5
  %235 = zext i16 %234 to i64
  %236 = getelementptr inbounds [8 x i16], ptr @joyAxisX, i64 0, i64 %235
  store volatile i16 -1, ptr %236, align 2, !tbaa !5
  %237 = load i16, ptr %3, align 2, !tbaa !5
  %238 = zext i16 %237 to i64
  %239 = getelementptr inbounds [8 x i16], ptr @joyAxisY, i64 0, i64 %238
  store volatile i16 -1, ptr %239, align 2, !tbaa !5
  store i8 0, ptr @gun, align 1, !tbaa !9
  store i8 0, ptr @extSet, align 1, !tbaa !9
  %240 = load i16, ptr %3, align 2, !tbaa !5
  store i16 %240, ptr @gport, align 2, !tbaa !5
  call void @SYS_setExtIntCallback(ptr noundef @externalIntCB)
  %241 = call zeroext i8 @Z80_getAndRequestBus(i8 noundef zeroext 1)
  %242 = zext i8 %241 to i16
  store i16 %242, ptr %5, align 2, !tbaa !5
  %243 = load i16, ptr %3, align 2, !tbaa !5
  %244 = zext i16 %243 to i32
  %245 = mul nsw i32 %244, 2
  %246 = sext i32 %245 to i64
  %247 = getelementptr inbounds i8, ptr inttoptr (i64 10551305 to ptr), i64 %246
  store ptr %247, ptr %9, align 8, !tbaa !10
  %248 = load ptr, ptr %9, align 8, !tbaa !10
  store volatile i8 -128, ptr %248, align 1, !tbaa !9
  %249 = load i16, ptr %5, align 2, !tbaa !5
  %250 = icmp ne i16 %249, 0
  br i1 %250, label %252, label %251

251:                                              ; preds = %227
  call void @Z80_releaseBus()
  br label %252

252:                                              ; preds = %251, %227
  call void @VDP_setHVLatching(i8 noundef zeroext 1)
  %253 = call zeroext i8 @VDP_getReg(i16 noundef zeroext 11)
  store i8 %253, ptr %10, align 1, !tbaa !9
  %254 = load i8, ptr %10, align 1, !tbaa !9
  %255 = zext i8 %254 to i32
  %256 = or i32 %255, 8
  %257 = trunc i32 %256 to i8
  call void @VDP_setReg(i16 noundef zeroext 11, i8 noundef zeroext %257)
  call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 1)
  %258 = load i16, ptr %4, align 2, !tbaa !5
  %259 = trunc i16 %258 to i8
  %260 = load i16, ptr %3, align 2, !tbaa !5
  %261 = zext i16 %260 to i64
  %262 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %261
  store i8 %259, ptr %262, align 1, !tbaa !9
  br label %263

263:                                              ; preds = %252, %220
  br label %304

264:                                              ; preds = %216
  %265 = load i16, ptr %4, align 2, !tbaa !5
  %266 = zext i16 %265 to i32
  %267 = icmp eq i32 %266, 0
  br i1 %267, label %268, label %303

268:                                              ; preds = %264
  %269 = load i16, ptr %3, align 2, !tbaa !5
  %270 = zext i16 %269 to i64
  %271 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %270
  %272 = load i8, ptr %271, align 1, !tbaa !9
  %273 = zext i8 %272 to i32
  %274 = icmp eq i32 %273, 10
  br i1 %274, label %275, label %299

275:                                              ; preds = %268
  call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 7)
  %276 = call zeroext i8 @Z80_getAndRequestBus(i8 noundef zeroext 1)
  %277 = zext i8 %276 to i16
  store i16 %277, ptr %5, align 2, !tbaa !5
  %278 = load i16, ptr %3, align 2, !tbaa !5
  %279 = zext i16 %278 to i32
  %280 = mul nsw i32 %279, 2
  %281 = sext i32 %280 to i64
  %282 = getelementptr inbounds i8, ptr inttoptr (i64 10551305 to ptr), i64 %281
  store ptr %282, ptr %9, align 8, !tbaa !10
  %283 = load ptr, ptr %9, align 8, !tbaa !10
  store volatile i8 64, ptr %283, align 1, !tbaa !9
  %284 = load i16, ptr %5, align 2, !tbaa !5
  %285 = icmp ne i16 %284, 0
  br i1 %285, label %287, label %286

286:                                              ; preds = %275
  call void @Z80_releaseBus()
  br label %287

287:                                              ; preds = %286, %275
  call void @VDP_setHVLatching(i8 noundef zeroext 0)
  %288 = call zeroext i8 @VDP_getReg(i16 noundef zeroext 11)
  store i8 %288, ptr %10, align 1, !tbaa !9
  %289 = load i8, ptr %10, align 1, !tbaa !9
  %290 = zext i8 %289 to i32
  %291 = and i32 %290, -9
  %292 = trunc i32 %291 to i8
  call void @VDP_setReg(i16 noundef zeroext 11, i8 noundef zeroext %292)
  call void @SYS_setExtIntCallback(ptr noundef null)
  %293 = load i16, ptr %3, align 2, !tbaa !5
  %294 = zext i16 %293 to i32
  %295 = icmp eq i32 %294, 0
  br i1 %295, label %296, label %297

296:                                              ; preds = %287
  store volatile i8 15, ptr @joyType, align 1, !tbaa !9
  store volatile i16 0, ptr @joyState, align 16, !tbaa !5
  br label %298

297:                                              ; preds = %287
  store volatile i8 15, ptr getelementptr inbounds ([8 x i8], ptr @joyType, i64 0, i64 1), align 1, !tbaa !9
  store volatile i16 0, ptr getelementptr inbounds ([8 x i16], ptr @joyState, i64 0, i64 1), align 2, !tbaa !5
  br label %298

298:                                              ; preds = %297, %296
  store i16 -1, ptr @gport, align 2, !tbaa !5
  call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 3)
  br label %299

299:                                              ; preds = %298, %268
  %300 = load i16, ptr %3, align 2, !tbaa !5
  %301 = zext i16 %300 to i64
  %302 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %301
  store i8 0, ptr %302, align 1, !tbaa !9
  br label %303

303:                                              ; preds = %299, %264
  br label %304

304:                                              ; preds = %303, %263
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %311

305:                                              ; preds = %212
  %306 = load i16, ptr %4, align 2, !tbaa !5
  %307 = trunc i16 %306 to i8
  %308 = load i16, ptr %3, align 2, !tbaa !5
  %309 = zext i16 %308 to i64
  %310 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %309
  store i8 %307, ptr %310, align 1, !tbaa !9
  br label %311

311:                                              ; preds = %305, %304
  br label %312

312:                                              ; preds = %311, %207
  store i32 0, ptr %6, align 4
  br label %313

313:                                              ; preds = %312, %14
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #4
  %314 = load i32, ptr %6, align 4
  switch i32 %314, label %316 [
    i32 0, label %315
    i32 1, label %315
  ]

315:                                              ; preds = %313, %313
  ret void

316:                                              ; preds = %313
  unreachable
}

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

declare void @SYS_setInterruptMaskLevel(i16 noundef zeroext) #1

declare void @SYS_setExtIntCallback(ptr noundef) #1

declare void @VDP_setHVLatching(i8 noundef zeroext) #1

declare zeroext i8 @VDP_getReg(i16 noundef zeroext) #1

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

; Function Attrs: nounwind uwtable
declare hidden void @externalIntCB() #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noinline 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 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 #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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !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"

@gport = external hidden local_unnamed_addr global i16, align 2
@portType = external hidden local_unnamed_addr global [2 x i8], align 1
@portSupport = external hidden local_unnamed_addr global [2 x i8], align 1
@joyType = external hidden global [8 x i8], align 1
@joyState = external hidden global [8 x i16], align 16
@joyAxisX = external hidden global [8 x i16], align 16
@joyAxisY = external hidden global [8 x i16], align 16
@gun = external hidden local_unnamed_addr global i8, align 1
@extSet = external hidden local_unnamed_addr global i8, align 1

declare zeroext i8 @Z80_getAndRequestBus(i8 noundef zeroext) local_unnamed_addr #0

declare void @Z80_releaseBus() local_unnamed_addr #0

; Function Attrs: noinline nounwind uwtable
define dso_local void @JOY_setSupport(i16 noundef zeroext %0, i16 noundef zeroext %1) local_unnamed_addr #1 {
  %3 = zext i16 %0 to i32
  %4 = icmp ugt i16 %0, 1
  br i1 %4, label %103, label %5

5:                                                ; preds = %2
  %6 = zext nneg i16 %0 to i64
  %7 = getelementptr inbounds [2 x i8], ptr @portType, i64 0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %switch = icmp ult i8 %8, 2
  br i1 %switch, label %9, label %64

9:                                                ; preds = %5
  %10 = icmp eq i16 %1, 9
  %11 = icmp eq i16 %1, 7
  switch i16 %1, label %103 [
    i16 9, label %12
    i16 8, label %12
    i16 7, label %12
    i16 0, label %38
    i16 4, label %55
  ]

12:                                               ; preds = %9, %9, %9
  %13 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %6
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = icmp eq i8 %14, 0
  br i1 %15, label %16, label %103

16:                                               ; preds = %12
  tail call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 7) #3
  %17 = select i1 %11, i8 4, i8 5
  %18 = getelementptr inbounds [8 x i8], ptr @joyType, i64 0, i64 %6
  store volatile i8 %17, ptr %18, align 1, !tbaa !5
  %19 = getelementptr inbounds [8 x i16], ptr @joyState, i64 0, i64 %6
  store volatile i16 0, ptr %19, align 2, !tbaa !8
  %20 = getelementptr inbounds [8 x i16], ptr @joyAxisX, i64 0, i64 %6
  store volatile i16 -1, ptr %20, align 2, !tbaa !8
  %21 = getelementptr inbounds [8 x i16], ptr @joyAxisY, i64 0, i64 %6
  store volatile i16 -1, ptr %21, align 2, !tbaa !8
  store i8 0, ptr @gun, align 1, !tbaa !5
  store i8 0, ptr @extSet, align 1, !tbaa !5
  store i16 %0, ptr @gport, align 2, !tbaa !8
  br i1 %10, label %22, label %28

22:                                               ; preds = %16
  %.not80 = icmp eq i16 %0, 0
  %23 = select i1 %.not80, i64 2, i64 5
  %24 = getelementptr inbounds [8 x i8], ptr @joyType, i64 0, i64 %23
  store volatile i8 5, ptr %24, align 1, !tbaa !5
  %25 = getelementptr inbounds [8 x i16], ptr @joyState, i64 0, i64 %23
  store volatile i16 0, ptr %25, align 2, !tbaa !8
  %26 = getelementptr inbounds [8 x i16], ptr @joyAxisX, i64 0, i64 %23
  store volatile i16 -1, ptr %26, align 2, !tbaa !8
  %27 = getelementptr inbounds [8 x i16], ptr @joyAxisY, i64 0, i64 %23
  store volatile i16 -1, ptr %27, align 2, !tbaa !8
  br label %28

28:                                               ; preds = %22, %16
  tail call void @SYS_setExtIntCallback(ptr noundef nonnull @externalIntCB) #3
  %29 = tail call zeroext i8 @Z80_getAndRequestBus(i8 noundef zeroext 1) #3
  %30 = shl nuw nsw i32 %3, 1
  %31 = zext nneg i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr inttoptr (i64 10551305 to ptr), i64 %31
  store volatile i8 -80, ptr %32, align 1, !tbaa !5
  %.not81 = icmp eq i8 %29, 0
  br i1 %.not81, label %33, label %34

33:                                               ; preds = %28
  tail call void @Z80_releaseBus() #3
  br label %34

34:                                               ; preds = %33, %28
  tail call void @VDP_setHVLatching(i8 noundef zeroext 1) #3
  %35 = tail call zeroext i8 @VDP_getReg(i16 noundef zeroext 11) #3
  %36 = or i8 %35, 8
  tail call void @VDP_setReg(i16 noundef zeroext 11, i8 noundef zeroext %36) #3
  tail call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 1) #3
  %37 = trunc nuw i16 %1 to i8
  store i8 %37, ptr %13, align 1, !tbaa !5
  br label %103

38:                                               ; preds = %9
  %39 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %6
  %40 = load i8, ptr %39, align 1, !tbaa !5
  %.off = add i8 %40, -7
  %switch82 = icmp ult i8 %.off, 3
  br i1 %switch82, label %41, label %54

41:                                               ; preds = %38
  tail call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 7) #3
  %42 = tail call zeroext i8 @Z80_getAndRequestBus(i8 noundef zeroext 1) #3
  %43 = shl nuw nsw i32 %3, 1
  %44 = zext nneg i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr inttoptr (i64 10551305 to ptr), i64 %44
  store volatile i8 48, ptr %45, align 1, !tbaa !5
  %.not79 = icmp eq i8 %42, 0
  br i1 %.not79, label %46, label %47

46:                                               ; preds = %41
  tail call void @Z80_releaseBus() #3
  br label %47

47:                                               ; preds = %46, %41
  tail call void @VDP_setHVLatching(i8 noundef zeroext 0) #3
  %48 = tail call zeroext i8 @VDP_getReg(i16 noundef zeroext 11) #3
  %49 = and i8 %48, -9
  tail call void @VDP_setReg(i16 noundef zeroext 11, i8 noundef zeroext %49) #3
  tail call void @SYS_setExtIntCallback(ptr noundef null) #3
  %50 = icmp eq i16 %0, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %47
  store volatile i8 15, ptr @joyType, align 1, !tbaa !5
  store volatile i8 15, ptr getelementptr inbounds (i8, ptr @joyType, i64 2), align 1, !tbaa !5
  store volatile i16 0, ptr @joyState, align 16, !tbaa !8
  store volatile i16 0, ptr getelementptr inbounds (i8, ptr @joyState, i64 4), align 4, !tbaa !8
  br label %53

52:                                               ; preds = %47
  store volatile i8 15, ptr getelementptr inbounds (i8, ptr @joyType, i64 1), align 1, !tbaa !5
  store volatile i8 15, ptr getelementptr inbounds (i8, ptr @joyType, i64 5), align 1, !tbaa !5
  store volatile i16 0, ptr getelementptr inbounds (i8, ptr @joyState, i64 2), align 2, !tbaa !8
  store volatile i16 0, ptr getelementptr inbounds (i8, ptr @joyState, i64 10), align 2, !tbaa !8
  br label %53

53:                                               ; preds = %52, %51
  store i16 -1, ptr @gport, align 2, !tbaa !8
  tail call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 3) #3
  br label %54

54:                                               ; preds = %38, %53
  store i8 0, ptr %39, align 1, !tbaa !5
  br label %103

55:                                               ; preds = %9
  %56 = tail call zeroext i8 @Z80_getAndRequestBus(i8 noundef zeroext 1) #3
  %57 = shl nuw nsw i32 %3, 1
  %58 = zext nneg i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr inttoptr (i64 10551305 to ptr), i64 %58
  store volatile i8 64, ptr %59, align 1, !tbaa !5
  %60 = getelementptr inbounds i8, ptr inttoptr (i64 10551299 to ptr), i64 %58
  store volatile i8 64, ptr %60, align 1, !tbaa !5
  %.not78 = icmp eq i8 %56, 0
  br i1 %.not78, label %61, label %62

61:                                               ; preds = %55
  tail call void @Z80_releaseBus() #3
  br label %62

62:                                               ; preds = %61, %55
  %63 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %6
  store i8 4, ptr %63, align 1, !tbaa !5
  br label %103

64:                                               ; preds = %5
  switch i16 %1, label %100 [
    i16 10, label %65
    i16 0, label %82
  ]

65:                                               ; preds = %64
  %66 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %6
  %67 = load i8, ptr %66, align 1, !tbaa !5
  %68 = icmp eq i8 %67, 0
  br i1 %68, label %69, label %103

69:                                               ; preds = %65
  tail call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 7) #3
  %70 = getelementptr inbounds [8 x i8], ptr @joyType, i64 0, i64 %6
  store volatile i8 6, ptr %70, align 1, !tbaa !5
  %71 = getelementptr inbounds [8 x i16], ptr @joyState, i64 0, i64 %6
  store volatile i16 0, ptr %71, align 2, !tbaa !8
  %72 = getelementptr inbounds [8 x i16], ptr @joyAxisX, i64 0, i64 %6
  store volatile i16 -1, ptr %72, align 2, !tbaa !8
  %73 = getelementptr inbounds [8 x i16], ptr @joyAxisY, i64 0, i64 %6
  store volatile i16 -1, ptr %73, align 2, !tbaa !8
  store i8 0, ptr @gun, align 1, !tbaa !5
  store i8 0, ptr @extSet, align 1, !tbaa !5
  store i16 %0, ptr @gport, align 2, !tbaa !8
  tail call void @SYS_setExtIntCallback(ptr noundef nonnull @externalIntCB) #3
  %74 = tail call zeroext i8 @Z80_getAndRequestBus(i8 noundef zeroext 1) #3
  %75 = shl nuw nsw i32 %3, 1
  %76 = zext nneg i32 %75 to i64
  %77 = getelementptr inbounds i8, ptr inttoptr (i64 10551305 to ptr), i64 %76
  store volatile i8 -128, ptr %77, align 1, !tbaa !5
  %.not77 = icmp eq i8 %74, 0
  br i1 %.not77, label %78, label %79

78:                                               ; preds = %69
  tail call void @Z80_releaseBus() #3
  br label %79

79:                                               ; preds = %78, %69
  tail call void @VDP_setHVLatching(i8 noundef zeroext 1) #3
  %80 = tail call zeroext i8 @VDP_getReg(i16 noundef zeroext 11) #3
  %81 = or i8 %80, 8
  tail call void @VDP_setReg(i16 noundef zeroext 11, i8 noundef zeroext %81) #3
  tail call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 1) #3
  store i8 10, ptr %66, align 1, !tbaa !5
  br label %103

82:                                               ; preds = %64
  %83 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %6
  %84 = load i8, ptr %83, align 1, !tbaa !5
  %85 = icmp eq i8 %84, 10
  br i1 %85, label %86, label %99

86:                                               ; preds = %82
  tail call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 7) #3
  %87 = tail call zeroext i8 @Z80_getAndRequestBus(i8 noundef zeroext 1) #3
  %88 = shl nuw nsw i32 %3, 1
  %89 = zext nneg i32 %88 to i64
  %90 = getelementptr inbounds i8, ptr inttoptr (i64 10551305 to ptr), i64 %89
  store volatile i8 64, ptr %90, align 1, !tbaa !5
  %.not = icmp eq i8 %87, 0
  br i1 %.not, label %91, label %92

91:                                               ; preds = %86
  tail call void @Z80_releaseBus() #3
  br label %92

92:                                               ; preds = %91, %86
  tail call void @VDP_setHVLatching(i8 noundef zeroext 0) #3
  %93 = tail call zeroext i8 @VDP_getReg(i16 noundef zeroext 11) #3
  %94 = and i8 %93, -9
  tail call void @VDP_setReg(i16 noundef zeroext 11, i8 noundef zeroext %94) #3
  tail call void @SYS_setExtIntCallback(ptr noundef null) #3
  %95 = icmp eq i16 %0, 0
  br i1 %95, label %96, label %97

96:                                               ; preds = %92
  store volatile i8 15, ptr @joyType, align 1, !tbaa !5
  store volatile i16 0, ptr @joyState, align 16, !tbaa !8
  br label %98

97:                                               ; preds = %92
  store volatile i8 15, ptr getelementptr inbounds (i8, ptr @joyType, i64 1), align 1, !tbaa !5
  store volatile i16 0, ptr getelementptr inbounds (i8, ptr @joyState, i64 2), align 2, !tbaa !8
  br label %98

98:                                               ; preds = %97, %96
  store i16 -1, ptr @gport, align 2, !tbaa !8
  tail call void @SYS_setInterruptMaskLevel(i16 noundef zeroext 3) #3
  br label %99

99:                                               ; preds = %98, %82
  store i8 0, ptr %83, align 1, !tbaa !5
  br label %103

100:                                              ; preds = %64
  %101 = trunc i16 %1 to i8
  %102 = getelementptr inbounds [2 x i8], ptr @portSupport, i64 0, i64 %6
  store i8 %101, ptr %102, align 1, !tbaa !5
  br label %103

103:                                              ; preds = %100, %9, %54, %62, %12, %34, %99, %65, %79, %2
  ret void
}

declare void @SYS_setInterruptMaskLevel(i16 noundef zeroext) local_unnamed_addr #0

declare void @SYS_setExtIntCallback(ptr noundef) local_unnamed_addr #0

declare void @VDP_setHVLatching(i8 noundef zeroext) local_unnamed_addr #0

declare zeroext i8 @VDP_getReg(i16 noundef zeroext) local_unnamed_addr #0

declare void @VDP_setReg(i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @externalIntCB() #2

attributes #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 = { noinline 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 #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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass