; LLVM IR from PyCee/NUS_library :: src/io (NUS_system_events)

; 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.NUS_window = type { ptr, i16, i16, ptr, ptr, i32, %struct.xcb_intern_atom_cookie_t, ptr, %struct.xcb_intern_atom_cookie_t, ptr }
%struct.xcb_intern_atom_cookie_t = type { i32 }
%struct.xcb_generic_event_t = type { i8, i8, i16, [7 x i32], i32 }
%struct.xcb_key_press_event_t = type { i8, i8, i16, i32, i32, i32, i32, i16, i16, i16, i16, i16, i8, i8 }
%struct.xcb_button_press_event_t = type { i8, i8, i16, i32, i32, i32, i32, i16, i16, i16, i16, i16, i8, i8 }
%struct.xcb_client_message_event_t = type { i8, i8, i16, i32, i32, %union.xcb_client_message_data_t }
%union.xcb_client_message_data_t = type { [5 x i32] }
%struct.xcb_intern_atom_reply_t = type { i8, i8, i16, i32, i32 }
%struct.xcb_motion_notify_event_t = type { i8, i8, i16, i32, i32, i32, i32, i16, i16, i16, i16, i16, i8, i8 }

@nus_system_events_handle.mouse_position_x = external hidden global float, align 4
@nus_system_events_handle.mouse_position_y = external hidden global float, align 4

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @nus_system_events_handle(ptr noundef byval(%struct.NUS_window) align 8 %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %14, %1
  %10 = getelementptr inbounds %struct.NUS_window, ptr %0, i32 0, i32 3
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = call ptr @xcb_poll_for_event(ptr noundef %11)
  store ptr %12, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %27

14:                                               ; preds = %9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = add i32 %16, 1
  store i32 %17, ptr %7, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = mul i64 8, %18
  %20 = call ptr @realloc(ptr noundef %15, i64 noundef %19) #6
  store ptr %20, ptr %5, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = sub i32 %23, 1
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds ptr, ptr %22, i64 %25
  store ptr %21, ptr %26, align 8, !tbaa !5
  br label %9, !llvm.loop !15

27:                                               ; preds = %9
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = icmp ugt i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  br label %31

31:                                               ; preds = %30, %27
  %32 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %32, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %2, align 4, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %169, %31
  %34 = load i32, ptr %2, align 4, !tbaa !9
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = icmp ult i32 %34, %35
  br i1 %36, label %37, label %172

37:                                               ; preds = %33
  %38 = load i32, ptr %2, align 4, !tbaa !9
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = sub i32 %39, 1
  %41 = icmp ult i32 %38, %40
  br i1 %41, label %42, label %107

42:                                               ; preds = %37
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i32, ptr %2, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds ptr, ptr %43, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.xcb_generic_event_t, ptr %47, i32 0, i32 0
  %49 = load i8, ptr %48, align 4, !tbaa !17
  %50 = zext i8 %49 to i32
  %51 = and i32 %50, -129
  %52 = icmp eq i32 %51, 3
  br i1 %52, label %53, label %107

53:                                               ; preds = %42
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr %2, align 4, !tbaa !9
  %56 = add i32 %55, 1
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds ptr, ptr %54, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.xcb_generic_event_t, ptr %59, i32 0, i32 0
  %61 = load i8, ptr %60, align 4, !tbaa !17
  %62 = zext i8 %61 to i32
  %63 = and i32 %62, -129
  %64 = icmp eq i32 %63, 2
  br i1 %64, label %65, label %107

65:                                               ; preds = %53
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load i32, ptr %2, align 4, !tbaa !9
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds ptr, ptr %66, i64 %68
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.xcb_key_press_event_t, ptr %70, i32 0, i32 3
  %72 = load i32, ptr %71, align 4, !tbaa !19
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = load i32, ptr %2, align 4, !tbaa !9
  %75 = add i32 %74, 1
  %76 = zext i32 %75 to i64
  %77 = getelementptr inbounds ptr, ptr %73, i64 %76
  %78 = load ptr, ptr %77, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.xcb_key_press_event_t, ptr %78, i32 0, i32 3
  %80 = load i32, ptr %79, align 4, !tbaa !19
  %81 = icmp eq i32 %72, %80
  br i1 %81, label %82, label %107

82:                                               ; preds = %65
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load i32, ptr %2, align 4, !tbaa !9
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds ptr, ptr %83, i64 %85
  %87 = load ptr, ptr %86, align 8, !tbaa !5
  call void @free(ptr noundef %87) #5
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = load i32, ptr %2, align 4, !tbaa !9
  %90 = zext i32 %89 to i64
  %91 = getelementptr inbounds ptr, ptr %88, i64 %90
  store ptr null, ptr %91, align 8, !tbaa !5
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = load i32, ptr %2, align 4, !tbaa !9
  %94 = add i32 %93, 1
  %95 = zext i32 %94 to i64
  %96 = getelementptr inbounds ptr, ptr %92, i64 %95
  %97 = load ptr, ptr %96, align 8, !tbaa !5
  call void @free(ptr noundef %97) #5
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = load i32, ptr %2, align 4, !tbaa !9
  %100 = add i32 %99, 1
  %101 = zext i32 %100 to i64
  %102 = getelementptr inbounds ptr, ptr %98, i64 %101
  store ptr null, ptr %102, align 8, !tbaa !5
  %103 = load i32, ptr %8, align 4, !tbaa !9
  %104 = sub i32 %103, 2
  store i32 %104, ptr %8, align 4, !tbaa !9
  %105 = load i32, ptr %2, align 4, !tbaa !9
  %106 = add i32 %105, 1
  store i32 %106, ptr %2, align 4, !tbaa !9
  br label %168

107:                                              ; preds = %65, %53, %42, %37
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  %109 = load i32, ptr %3, align 4, !tbaa !9
  %110 = add i32 %109, 1
  %111 = zext i32 %110 to i64
  %112 = mul i64 8, %111
  %113 = call ptr @realloc(ptr noundef %108, i64 noundef %112) #6
  store ptr %113, ptr %6, align 8, !tbaa !5
  %114 = load ptr, ptr %5, align 8, !tbaa !5
  %115 = load i32, ptr %2, align 4, !tbaa !9
  %116 = zext i32 %115 to i64
  %117 = getelementptr inbounds ptr, ptr %114, i64 %116
  %118 = load ptr, ptr %117, align 8, !tbaa !5
  %119 = load ptr, ptr %6, align 8, !tbaa !5
  %120 = load i32, ptr %3, align 4, !tbaa !9
  %121 = zext i32 %120 to i64
  %122 = getelementptr inbounds ptr, ptr %119, i64 %121
  store ptr %118, ptr %122, align 8, !tbaa !5
  %123 = load i32, ptr %3, align 4, !tbaa !9
  %124 = add i32 %123, 1
  store i32 %124, ptr %3, align 4, !tbaa !9
  %125 = load ptr, ptr %5, align 8, !tbaa !5
  %126 = load i32, ptr %2, align 4, !tbaa !9
  %127 = zext i32 %126 to i64
  %128 = getelementptr inbounds ptr, ptr %125, i64 %127
  %129 = load ptr, ptr %128, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.xcb_generic_event_t, ptr %129, i32 0, i32 0
  %131 = load i8, ptr %130, align 4, !tbaa !17
  %132 = zext i8 %131 to i32
  %133 = and i32 %132, -129
  %134 = icmp eq i32 %133, 5
  br i1 %134, label %135, label %167

135:                                              ; preds = %107
  %136 = load ptr, ptr %5, align 8, !tbaa !5
  %137 = load i32, ptr %2, align 4, !tbaa !9
  %138 = zext i32 %137 to i64
  %139 = getelementptr inbounds ptr, ptr %136, i64 %138
  %140 = load ptr, ptr %139, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.xcb_button_press_event_t, ptr %140, i32 0, i32 1
  %142 = load i8, ptr %141, align 1, !tbaa !21
  %143 = zext i8 %142 to i32
  %144 = icmp sge i32 %143, 4
  br i1 %144, label %145, label %167

145:                                              ; preds = %135
  %146 = load ptr, ptr %5, align 8, !tbaa !5
  %147 = load i32, ptr %2, align 4, !tbaa !9
  %148 = zext i32 %147 to i64
  %149 = getelementptr inbounds ptr, ptr %146, i64 %148
  %150 = load ptr, ptr %149, align 8, !tbaa !5
  %151 = getelementptr inbounds %struct.xcb_button_press_event_t, ptr %150, i32 0, i32 1
  %152 = load i8, ptr %151, align 1, !tbaa !21
  %153 = zext i8 %152 to i32
  %154 = icmp sle i32 %153, 7
  br i1 %154, label %155, label %167

155:                                              ; preds = %145
  %156 = load ptr, ptr %5, align 8, !tbaa !5
  %157 = load i32, ptr %2, align 4, !tbaa !9
  %158 = zext i32 %157 to i64
  %159 = getelementptr inbounds ptr, ptr %156, i64 %158
  %160 = load ptr, ptr %159, align 8, !tbaa !5
  call void @free(ptr noundef %160) #5
  %161 = load ptr, ptr %5, align 8, !tbaa !5
  %162 = load i32, ptr %2, align 4, !tbaa !9
  %163 = zext i32 %162 to i64
  %164 = getelementptr inbounds ptr, ptr %161, i64 %163
  store ptr null, ptr %164, align 8, !tbaa !5
  %165 = load i32, ptr %8, align 4, !tbaa !9
  %166 = sub i32 %165, 1
  store i32 %166, ptr %8, align 4, !tbaa !9
  br label %167

167:                                              ; preds = %155, %145, %135, %107
  br label %168

168:                                              ; preds = %167, %82
  br label %169

169:                                              ; preds = %168
  %170 = load i32, ptr %2, align 4, !tbaa !9
  %171 = add i32 %170, 1
  store i32 %171, ptr %2, align 4, !tbaa !9
  br label %33, !llvm.loop !23

172:                                              ; preds = %33
  %173 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %173, ptr %7, align 4, !tbaa !9
  %174 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %174) #5
  %175 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %175, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %176

176:                                              ; preds = %304, %172
  %177 = load i32, ptr %2, align 4, !tbaa !9
  %178 = load i32, ptr %7, align 4, !tbaa !9
  %179 = icmp ult i32 %177, %178
  br i1 %179, label %180, label %307

180:                                              ; preds = %176
  %181 = load ptr, ptr %5, align 8, !tbaa !5
  %182 = load i32, ptr %2, align 4, !tbaa !9
  %183 = zext i32 %182 to i64
  %184 = getelementptr inbounds ptr, ptr %181, i64 %183
  %185 = load ptr, ptr %184, align 8, !tbaa !5
  store ptr %185, ptr %4, align 8, !tbaa !5
  %186 = load ptr, ptr %4, align 8, !tbaa !5
  %187 = getelementptr inbounds %struct.xcb_generic_event_t, ptr %186, i32 0, i32 0
  %188 = load i8, ptr %187, align 4, !tbaa !17
  %189 = zext i8 %188 to i32
  %190 = and i32 %189, -129
  switch i32 %190, label %301 [
    i32 33, label %191
    i32 12, label %302
    i32 2, label %203
    i32 3, label %208
    i32 4, label %213
    i32 5, label %253
    i32 6, label %262
  ]

191:                                              ; preds = %180
  %192 = load ptr, ptr %4, align 8, !tbaa !5
  %193 = getelementptr inbounds %struct.xcb_client_message_event_t, ptr %192, i32 0, i32 5
  %194 = getelementptr inbounds [5 x i32], ptr %193, i64 0, i64 0
  %195 = load i32, ptr %194, align 4, !tbaa !24
  %196 = getelementptr inbounds %struct.NUS_window, ptr %0, i32 0, i32 9
  %197 = load ptr, ptr %196, align 8, !tbaa !25
  %198 = getelementptr inbounds %struct.xcb_intern_atom_reply_t, ptr %197, i32 0, i32 4
  %199 = load i32, ptr %198, align 4, !tbaa !26
  %200 = icmp eq i32 %195, %199
  br i1 %200, label %201, label %202

201:                                              ; preds = %191
  call void @nus_callback_close_window()
  br label %202

202:                                              ; preds = %201, %191
  br label %302

203:                                              ; preds = %180
  %204 = load ptr, ptr %4, align 8, !tbaa !5
  %205 = getelementptr inbounds %struct.xcb_key_press_event_t, ptr %204, i32 0, i32 1
  %206 = load i8, ptr %205, align 1, !tbaa !28
  %207 = zext i8 %206 to i32
  call void @nus_callback_key(i32 noundef %207, i8 noundef zeroext 1)
  br label %302

208:                                              ; preds = %180
  %209 = load ptr, ptr %4, align 8, !tbaa !5
  %210 = getelementptr inbounds %struct.xcb_key_press_event_t, ptr %209, i32 0, i32 1
  %211 = load i8, ptr %210, align 1, !tbaa !28
  %212 = zext i8 %211 to i32
  call void @nus_callback_key(i32 noundef %212, i8 noundef zeroext 2)
  br label %302

213:                                              ; preds = %180
  %214 = load ptr, ptr %5, align 8, !tbaa !5
  %215 = load i32, ptr %2, align 4, !tbaa !9
  %216 = zext i32 %215 to i64
  %217 = getelementptr inbounds ptr, ptr %214, i64 %216
  %218 = load ptr, ptr %217, align 8, !tbaa !5
  %219 = getelementptr inbounds %struct.xcb_button_press_event_t, ptr %218, i32 0, i32 1
  %220 = load i8, ptr %219, align 1, !tbaa !21
  %221 = zext i8 %220 to i32
  %222 = icmp sge i32 %221, 4
  br i1 %222, label %223, label %243

223:                                              ; preds = %213
  %224 = load ptr, ptr %5, align 8, !tbaa !5
  %225 = load i32, ptr %2, align 4, !tbaa !9
  %226 = zext i32 %225 to i64
  %227 = getelementptr inbounds ptr, ptr %224, i64 %226
  %228 = load ptr, ptr %227, align 8, !tbaa !5
  %229 = getelementptr inbounds %struct.xcb_button_press_event_t, ptr %228, i32 0, i32 1
  %230 = load i8, ptr %229, align 1, !tbaa !21
  %231 = zext i8 %230 to i32
  %232 = icmp sle i32 %231, 7
  br i1 %232, label %233, label %243

233:                                              ; preds = %223
  %234 = load ptr, ptr %5, align 8, !tbaa !5
  %235 = load i32, ptr %2, align 4, !tbaa !9
  %236 = zext i32 %235 to i64
  %237 = getelementptr inbounds ptr, ptr %234, i64 %236
  %238 = load ptr, ptr %237, align 8, !tbaa !5
  %239 = getelementptr inbounds %struct.xcb_button_press_event_t, ptr %238, i32 0, i32 1
  %240 = load i8, ptr %239, align 1, !tbaa !21
  %241 = zext i8 %240 to i32
  %242 = sub nsw i32 %241, 4
  call void @nus_callback_mouse_scroll(i32 noundef %242)
  br label %252

243:                                              ; preds = %223, %213
  %244 = load ptr, ptr %5, align 8, !tbaa !5
  %245 = load i32, ptr %2, align 4, !tbaa !9
  %246 = zext i32 %245 to i64
  %247 = getelementptr inbounds ptr, ptr %244, i64 %246
  %248 = load ptr, ptr %247, align 8, !tbaa !5
  %249 = getelementptr inbounds %struct.xcb_button_press_event_t, ptr %248, i32 0, i32 1
  %250 = load i8, ptr %249, align 1, !tbaa !21
  %251 = zext i8 %250 to i32
  call void @nus_callback_mouse_button(i32 noundef %251, i8 noundef zeroext 1)
  br label %252

252:                                              ; preds = %243, %233
  br label %302

253:                                              ; preds = %180
  %254 = load ptr, ptr %5, align 8, !tbaa !5
  %255 = load i32, ptr %2, align 4, !tbaa !9
  %256 = zext i32 %255 to i64
  %257 = getelementptr inbounds ptr, ptr %254, i64 %256
  %258 = load ptr, ptr %257, align 8, !tbaa !5
  %259 = getelementptr inbounds %struct.xcb_button_press_event_t, ptr %258, i32 0, i32 1
  %260 = load i8, ptr %259, align 1, !tbaa !21
  %261 = zext i8 %260 to i32
  call void @nus_callback_mouse_button(i32 noundef %261, i8 noundef zeroext 2)
  br label %302

262:                                              ; preds = %180
  %263 = load ptr, ptr %5, align 8, !tbaa !5
  %264 = load i32, ptr %2, align 4, !tbaa !9
  %265 = zext i32 %264 to i64
  %266 = getelementptr inbounds ptr, ptr %263, i64 %265
  %267 = load ptr, ptr %266, align 8, !tbaa !5
  %268 = getelementptr inbounds %struct.xcb_motion_notify_event_t, ptr %267, i32 0, i32 9
  %269 = load i16, ptr %268, align 4, !tbaa !29
  %270 = sext i16 %269 to i32
  %271 = sitofp i32 %270 to float
  %272 = load float, ptr @nus_system_events_handle.mouse_position_x, align 4, !tbaa !31
  %273 = fsub float %271, %272
  %274 = load ptr, ptr %5, align 8, !tbaa !5
  %275 = load i32, ptr %2, align 4, !tbaa !9
  %276 = zext i32 %275 to i64
  %277 = getelementptr inbounds ptr, ptr %274, i64 %276
  %278 = load ptr, ptr %277, align 8, !tbaa !5
  %279 = getelementptr inbounds %struct.xcb_motion_notify_event_t, ptr %278, i32 0, i32 10
  %280 = load i16, ptr %279, align 2, !tbaa !33
  %281 = sext i16 %280 to i32
  %282 = sitofp i32 %281 to float
  %283 = load float, ptr @nus_system_events_handle.mouse_position_y, align 4, !tbaa !31
  %284 = fsub float %282, %283
  call void @nus_callback_mouse_motion(float noundef %273, float noundef %284)
  %285 = load ptr, ptr %5, align 8, !tbaa !5
  %286 = load i32, ptr %2, align 4, !tbaa !9
  %287 = zext i32 %286 to i64
  %288 = getelementptr inbounds ptr, ptr %285, i64 %287
  %289 = load ptr, ptr %288, align 8, !tbaa !5
  %290 = getelementptr inbounds %struct.xcb_motion_notify_event_t, ptr %289, i32 0, i32 9
  %291 = load i16, ptr %290, align 4, !tbaa !29
  %292 = sitofp i16 %291 to float
  store float %292, ptr @nus_system_events_handle.mouse_position_x, align 4, !tbaa !31
  %293 = load ptr, ptr %5, align 8, !tbaa !5
  %294 = load i32, ptr %2, align 4, !tbaa !9
  %295 = zext i32 %294 to i64
  %296 = getelementptr inbounds ptr, ptr %293, i64 %295
  %297 = load ptr, ptr %296, align 8, !tbaa !5
  %298 = getelementptr inbounds %struct.xcb_motion_notify_event_t, ptr %297, i32 0, i32 10
  %299 = load i16, ptr %298, align 2, !tbaa !33
  %300 = sitofp i16 %299 to float
  store float %300, ptr @nus_system_events_handle.mouse_position_y, align 4, !tbaa !31
  br label %302

301:                                              ; preds = %180
  br label %302

302:                                              ; preds = %301, %262, %253, %252, %208, %203, %202, %180
  %303 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %303) #5
  br label %304

304:                                              ; preds = %302
  %305 = load i32, ptr %2, align 4, !tbaa !9
  %306 = add i32 %305, 1
  store i32 %306, ptr %2, align 4, !tbaa !9
  br label %176, !llvm.loop !34

307:                                              ; preds = %176
  %308 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %308) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret void
}

declare ptr @xcb_poll_for_event(ptr noundef) #3

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #4

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

; Function Attrs: nounwind uwtable
declare hidden void @nus_callback_key(i32 noundef, i8 noundef zeroext) #2

; Function Attrs: nounwind uwtable
declare hidden void @nus_callback_mouse_scroll(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @nus_callback_mouse_button(i32 noundef, i8 noundef zeroext) #2

; Function Attrs: nounwind uwtable
declare hidden void @nus_callback_mouse_motion(float noundef, float noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { "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 allocsize(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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(1) }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"NUS_window", !6, i64 0, !13, i64 8, !13, i64 10, !6, i64 16, !6, i64 24, !10, i64 32, !14, i64 36, !6, i64 40, !14, i64 48, !6, i64 56}
!13 = !{!"short", !7, i64 0}
!14 = !{!"xcb_intern_atom_cookie_t", !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !7, i64 0}
!18 = !{!"", !7, i64 0, !7, i64 1, !13, i64 2, !7, i64 4, !10, i64 32}
!19 = !{!20, !10, i64 4}
!20 = !{!"xcb_key_press_event_t", !7, i64 0, !7, i64 1, !13, i64 2, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 20, !13, i64 22, !13, i64 24, !13, i64 26, !13, i64 28, !7, i64 30, !7, i64 31}
!21 = !{!22, !7, i64 1}
!22 = !{!"xcb_button_press_event_t", !7, i64 0, !7, i64 1, !13, i64 2, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 20, !13, i64 22, !13, i64 24, !13, i64 26, !13, i64 28, !7, i64 30, !7, i64 31}
!23 = distinct !{!23, !16}
!24 = !{!7, !7, i64 0}
!25 = !{!12, !6, i64 56}
!26 = !{!27, !10, i64 8}
!27 = !{!"xcb_intern_atom_reply_t", !7, i64 0, !7, i64 1, !13, i64 2, !10, i64 4, !10, i64 8}
!28 = !{!20, !7, i64 1}
!29 = !{!30, !13, i64 24}
!30 = !{!"xcb_motion_notify_event_t", !7, i64 0, !7, i64 1, !13, i64 2, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 20, !13, i64 22, !13, i64 24, !13, i64 26, !13, i64 28, !7, i64 30, !7, i64 31}
!31 = !{!32, !32, i64 0}
!32 = !{!"float", !7, i64 0}
!33 = !{!30, !13, i64 26}
!34 = distinct !{!34, !16}


; 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.NUS_window = type { ptr, i16, i16, ptr, ptr, i32, %struct.xcb_intern_atom_cookie_t, ptr, %struct.xcb_intern_atom_cookie_t, ptr }
%struct.xcb_intern_atom_cookie_t = type { i32 }

@nus_system_events_handle.mouse_position_x = external hidden local_unnamed_addr global float, align 4
@nus_system_events_handle.mouse_position_y = external hidden local_unnamed_addr global float, align 4

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @nus_system_events_handle(ptr nocapture noundef readonly byval(%struct.NUS_window) align 8 %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = tail call ptr @xcb_poll_for_event(ptr noundef %3) #4
  %.not91 = icmp eq ptr %4, null
  br i1 %.not91, label %._crit_edge.thread, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %.not106 = icmp eq i32 %6, 0
  br i1 %.not106, label %._crit_edge.thread, label %.lr.ph99

.lr.ph:                                           ; preds = %1, %.lr.ph
  %5 = phi ptr [ %12, %.lr.ph ], [ %4, %1 ]
  %.07993 = phi i32 [ %6, %.lr.ph ], [ 0, %1 ]
  %.08292 = phi ptr [ %9, %.lr.ph ], [ null, %1 ]
  %6 = add i32 %.07993, 1
  %7 = zext i32 %6 to i64
  %8 = shl nuw nsw i64 %7, 3
  %9 = tail call ptr @realloc(ptr noundef %.08292, i64 noundef %8) #5
  %10 = zext i32 %.07993 to i64
  %11 = getelementptr inbounds ptr, ptr %9, i64 %10
  store ptr %5, ptr %11, align 8, !tbaa !13
  %12 = tail call ptr @xcb_poll_for_event(ptr noundef %3) #4
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !14

.lr.ph99:                                         ; preds = %.preheader, %54
  %.098 = phi i32 [ %.1, %54 ], [ %6, %.preheader ]
  %.08097 = phi ptr [ %.181, %54 ], [ null, %.preheader ]
  %.08396 = phi i32 [ %.184, %54 ], [ 0, %.preheader ]
  %.08595 = phi i32 [ %55, %54 ], [ 0, %.preheader ]
  %13 = icmp ult i32 %.08595, %.07993
  %14 = zext i32 %.08595 to i64
  br i1 %13, label %15, label %._crit_edge110

15:                                               ; preds = %.lr.ph99
  %16 = getelementptr inbounds ptr, ptr %9, i64 %14
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = load i8, ptr %17, align 4, !tbaa !16
  %19 = and i8 %18, 127
  %20 = icmp eq i8 %19, 3
  br i1 %20, label %21, label %._crit_edge110

21:                                               ; preds = %15
  %22 = add nuw i32 %.08595, 1
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds ptr, ptr %9, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = load i8, ptr %25, align 4, !tbaa !16
  %27 = and i8 %26, 127
  %28 = icmp eq i8 %27, 2
  br i1 %28, label %29, label %._crit_edge110

29:                                               ; preds = %21
  %30 = getelementptr inbounds i8, ptr %17, i64 4
  %31 = load i32, ptr %30, align 4, !tbaa !18
  %32 = getelementptr inbounds i8, ptr %25, i64 4
  %33 = load i32, ptr %32, align 4, !tbaa !18
  %34 = icmp eq i32 %31, %33
  br i1 %34, label %35, label %._crit_edge110

35:                                               ; preds = %29
  tail call void @free(ptr noundef nonnull %17) #4
  store ptr null, ptr %16, align 8, !tbaa !13
  %36 = load ptr, ptr %24, align 8, !tbaa !13
  tail call void @free(ptr noundef %36) #4
  br label %.sink.split

._crit_edge110:                                   ; preds = %.lr.ph99, %29, %21, %15
  %37 = add i32 %.08396, 1
  %38 = zext i32 %37 to i64
  %39 = shl nuw nsw i64 %38, 3
  %40 = tail call ptr @realloc(ptr noundef %.08097, i64 noundef %39) #5
  %41 = getelementptr inbounds ptr, ptr %9, i64 %14
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = zext i32 %.08396 to i64
  %44 = getelementptr inbounds ptr, ptr %40, i64 %43
  store ptr %42, ptr %44, align 8, !tbaa !13
  %45 = load i8, ptr %42, align 4, !tbaa !16
  %46 = and i8 %45, 127
  %47 = icmp eq i8 %46, 5
  br i1 %47, label %48, label %54

48:                                               ; preds = %._crit_edge110
  %49 = getelementptr inbounds i8, ptr %42, i64 1
  %50 = load i8, ptr %49, align 1, !tbaa !20
  %51 = and i8 %50, -4
  %or.cond = icmp eq i8 %51, 4
  br i1 %or.cond, label %52, label %54

52:                                               ; preds = %48
  tail call void @free(ptr noundef nonnull %42) #4
  br label %.sink.split

.sink.split:                                      ; preds = %52, %35
  %.sink121 = phi ptr [ %24, %35 ], [ %41, %52 ]
  %.sink = phi i32 [ -2, %35 ], [ -1, %52 ]
  %.186.ph = phi i32 [ %22, %35 ], [ %.08595, %52 ]
  %.184.ph = phi i32 [ %.08396, %35 ], [ %37, %52 ]
  %.181.ph = phi ptr [ %.08097, %35 ], [ %40, %52 ]
  store ptr null, ptr %.sink121, align 8, !tbaa !13
  %53 = add i32 %.098, %.sink
  br label %54

54:                                               ; preds = %.sink.split, %48, %._crit_edge110
  %.186 = phi i32 [ %.08595, %48 ], [ %.08595, %._crit_edge110 ], [ %.186.ph, %.sink.split ]
  %.184 = phi i32 [ %37, %48 ], [ %37, %._crit_edge110 ], [ %.184.ph, %.sink.split ]
  %.181 = phi ptr [ %40, %48 ], [ %40, %._crit_edge110 ], [ %.181.ph, %.sink.split ]
  %.1 = phi i32 [ %.098, %48 ], [ %.098, %._crit_edge110 ], [ %53, %.sink.split ]
  %55 = add nuw i32 %.186, 1
  %56 = icmp ult i32 %55, %6
  br i1 %56, label %.lr.ph99, label %._crit_edge, !llvm.loop !22

._crit_edge.thread:                               ; preds = %.preheader, %1
  %.082.lcssa114.ph = phi ptr [ %9, %.preheader ], [ null, %1 ]
  tail call void @free(ptr noundef %.082.lcssa114.ph) #4
  br label %._crit_edge105

._crit_edge:                                      ; preds = %54
  tail call void @free(ptr noundef nonnull %9) #4
  %.not107 = icmp eq i32 %.1, 0
  br i1 %.not107, label %._crit_edge105, label %.lr.ph104

.lr.ph104:                                        ; preds = %._crit_edge
  %57 = getelementptr inbounds i8, ptr %0, i64 56
  %58 = load ptr, ptr %57, align 8
  %59 = getelementptr inbounds i8, ptr %58, i64 8
  %wide.trip.count = zext i32 %.1 to i64
  br label %60

60:                                               ; preds = %.lr.ph104, %109
  %indvars.iv = phi i64 [ 0, %.lr.ph104 ], [ %indvars.iv.next, %109 ]
  %61 = getelementptr inbounds ptr, ptr %.181, i64 %indvars.iv
  %62 = load ptr, ptr %61, align 8, !tbaa !13
  %63 = load i8, ptr %62, align 4, !tbaa !16
  %64 = and i8 %63, 127
  switch i8 %64, label %109 [
    i8 33, label %65
    i8 6, label %91
    i8 2, label %71
    i8 3, label %75
    i8 4, label %79
    i8 5, label %87
  ]

65:                                               ; preds = %60
  %66 = getelementptr inbounds i8, ptr %62, i64 12
  %67 = load i32, ptr %66, align 4, !tbaa !23
  %68 = load i32, ptr %59, align 4, !tbaa !24
  %69 = icmp eq i32 %67, %68
  br i1 %69, label %70, label %109

70:                                               ; preds = %65
  tail call void @nus_callback_close_window()
  br label %109

71:                                               ; preds = %60
  %72 = getelementptr inbounds i8, ptr %62, i64 1
  %73 = load i8, ptr %72, align 1, !tbaa !26
  %74 = zext i8 %73 to i32
  tail call void @nus_callback_key(i32 noundef %74, i8 noundef zeroext 1)
  br label %109

75:                                               ; preds = %60
  %76 = getelementptr inbounds i8, ptr %62, i64 1
  %77 = load i8, ptr %76, align 1, !tbaa !26
  %78 = zext i8 %77 to i32
  tail call void @nus_callback_key(i32 noundef %78, i8 noundef zeroext 2)
  br label %109

79:                                               ; preds = %60
  %80 = getelementptr inbounds i8, ptr %62, i64 1
  %81 = load i8, ptr %80, align 1, !tbaa !20
  %82 = zext i8 %81 to i32
  %83 = and i8 %81, -4
  %or.cond90 = icmp eq i8 %83, 4
  br i1 %or.cond90, label %84, label %86

84:                                               ; preds = %79
  %85 = add nsw i32 %82, -4
  tail call void @nus_callback_mouse_scroll(i32 noundef %85)
  br label %109

86:                                               ; preds = %79
  tail call void @nus_callback_mouse_button(i32 noundef %82, i8 noundef zeroext 1)
  br label %109

87:                                               ; preds = %60
  %88 = getelementptr inbounds i8, ptr %62, i64 1
  %89 = load i8, ptr %88, align 1, !tbaa !20
  %90 = zext i8 %89 to i32
  tail call void @nus_callback_mouse_button(i32 noundef %90, i8 noundef zeroext 2)
  br label %109

91:                                               ; preds = %60
  %92 = getelementptr inbounds i8, ptr %62, i64 24
  %93 = load i16, ptr %92, align 4, !tbaa !27
  %94 = sitofp i16 %93 to float
  %95 = load float, ptr @nus_system_events_handle.mouse_position_x, align 4, !tbaa !29
  %96 = fsub float %94, %95
  %97 = getelementptr inbounds i8, ptr %62, i64 26
  %98 = load i16, ptr %97, align 2, !tbaa !31
  %99 = sitofp i16 %98 to float
  %100 = load float, ptr @nus_system_events_handle.mouse_position_y, align 4, !tbaa !29
  %101 = fsub float %99, %100
  tail call void @nus_callback_mouse_motion(float noundef %96, float noundef %101)
  %102 = load ptr, ptr %61, align 8, !tbaa !13
  %103 = getelementptr inbounds i8, ptr %102, i64 24
  %104 = load i16, ptr %103, align 4, !tbaa !27
  %105 = sitofp i16 %104 to float
  store float %105, ptr @nus_system_events_handle.mouse_position_x, align 4, !tbaa !29
  %106 = getelementptr inbounds i8, ptr %102, i64 26
  %107 = load i16, ptr %106, align 2, !tbaa !31
  %108 = sitofp i16 %107 to float
  store float %108, ptr @nus_system_events_handle.mouse_position_y, align 4, !tbaa !29
  br label %109

109:                                              ; preds = %60, %84, %86, %65, %70, %91, %87, %75, %71
  tail call void @free(ptr noundef nonnull %62) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge105, label %60, !llvm.loop !32

._crit_edge105:                                   ; preds = %109, %._crit_edge.thread, %._crit_edge
  %.080.lcssa119 = phi ptr [ null, %._crit_edge.thread ], [ %.181, %._crit_edge ], [ %.181, %109 ]
  tail call void @free(ptr noundef %.080.lcssa119) #4
  ret void
}

declare ptr @xcb_poll_for_event(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @nus_callback_close_window() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @nus_callback_key(i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @nus_callback_mouse_scroll(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @nus_callback_mouse_button(i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @nus_callback_mouse_motion(float noundef, float noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 = { "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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #5 = { nounwind allocsize(1) }

!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, !7, i64 16}
!6 = !{!"NUS_window", !7, i64 0, !10, i64 8, !10, i64 10, !7, i64 16, !7, i64 24, !11, i64 32, !12, i64 36, !7, i64 40, !12, i64 48, !7, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"xcb_intern_atom_cookie_t", !11, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !8, i64 0}
!17 = !{!"", !8, i64 0, !8, i64 1, !10, i64 2, !8, i64 4, !11, i64 32}
!18 = !{!19, !11, i64 4}
!19 = !{!"xcb_key_press_event_t", !8, i64 0, !8, i64 1, !10, i64 2, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !10, i64 20, !10, i64 22, !10, i64 24, !10, i64 26, !10, i64 28, !8, i64 30, !8, i64 31}
!20 = !{!21, !8, i64 1}
!21 = !{!"xcb_button_press_event_t", !8, i64 0, !8, i64 1, !10, i64 2, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !10, i64 20, !10, i64 22, !10, i64 24, !10, i64 26, !10, i64 28, !8, i64 30, !8, i64 31}
!22 = distinct !{!22, !15}
!23 = !{!8, !8, i64 0}
!24 = !{!25, !11, i64 8}
!25 = !{!"xcb_intern_atom_reply_t", !8, i64 0, !8, i64 1, !10, i64 2, !11, i64 4, !11, i64 8}
!26 = !{!19, !8, i64 1}
!27 = !{!28, !10, i64 24}
!28 = !{!"xcb_motion_notify_event_t", !8, i64 0, !8, i64 1, !10, i64 2, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !10, i64 20, !10, i64 22, !10, i64 24, !10, i64 26, !10, i64 28, !8, i64 30, !8, i64 31}
!29 = !{!30, !30, i64 0}
!30 = !{!"float", !8, i64 0}
!31 = !{!28, !10, i64 26}
!32 = distinct !{!32, !15}


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