; 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_event_handler = type { [1 x %struct.anon], [348 x %struct.anon.0], [348 x %struct.anon.1], [3 x %struct.anon.2], [3 x %struct.anon.3], [1 x %struct.anon.4], [4 x %struct.anon.5] }
%struct.anon = type { ptr, i32 }
%struct.anon.0 = type { ptr, i32 }
%struct.anon.1 = type { ptr, i32 }
%struct.anon.2 = type { ptr, i32 }
%struct.anon.3 = type { ptr, i32 }
%struct.anon.4 = type { ptr, i32 }
%struct.anon.5 = type { ptr, i32 }

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

4:                                                ; preds = %21, %1
  %5 = load i16, ptr %3, align 2, !tbaa !9
  %6 = sext i16 %5 to i32
  %7 = icmp slt i32 %6, 1
  br i1 %7, label %8, label %24

8:                                                ; preds = %4
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.NUS_event_handler, ptr %9, i32 0, i32 0
  %11 = load i16, ptr %3, align 2, !tbaa !9
  %12 = sext i16 %11 to i64
  %13 = getelementptr inbounds [1 x %struct.anon], ptr %10, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.anon, ptr %13, i32 0, i32 0
  store ptr null, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.NUS_event_handler, ptr %15, i32 0, i32 0
  %17 = load i16, ptr %3, align 2, !tbaa !9
  %18 = sext i16 %17 to i64
  %19 = getelementptr inbounds [1 x %struct.anon], ptr %16, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.anon, ptr %19, i32 0, i32 1
  store i32 0, ptr %20, align 8, !tbaa !14
  br label %21

21:                                               ; preds = %8
  %22 = load i16, ptr %3, align 2, !tbaa !9
  %23 = add i16 %22, 1
  store i16 %23, ptr %3, align 2, !tbaa !9
  br label %4, !llvm.loop !15

24:                                               ; preds = %4
  store i16 0, ptr %3, align 2, !tbaa !9
  br label %25

25:                                               ; preds = %54, %24
  %26 = load i16, ptr %3, align 2, !tbaa !9
  %27 = sext i16 %26 to i32
  %28 = icmp slt i32 %27, 348
  br i1 %28, label %29, label %57

29:                                               ; preds = %25
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.NUS_event_handler, ptr %30, i32 0, i32 1
  %32 = load i16, ptr %3, align 2, !tbaa !9
  %33 = sext i16 %32 to i64
  %34 = getelementptr inbounds [348 x %struct.anon.0], ptr %31, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.anon.0, ptr %34, i32 0, i32 0
  store ptr null, ptr %35, align 8, !tbaa !11
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.NUS_event_handler, ptr %36, i32 0, i32 1
  %38 = load i16, ptr %3, align 2, !tbaa !9
  %39 = sext i16 %38 to i64
  %40 = getelementptr inbounds [348 x %struct.anon.0], ptr %37, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.anon.0, ptr %40, i32 0, i32 1
  store i32 0, ptr %41, align 8, !tbaa !14
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.NUS_event_handler, ptr %42, i32 0, i32 2
  %44 = load i16, ptr %3, align 2, !tbaa !9
  %45 = sext i16 %44 to i64
  %46 = getelementptr inbounds [348 x %struct.anon.1], ptr %43, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.anon.1, ptr %46, i32 0, i32 0
  store ptr null, ptr %47, align 8, !tbaa !11
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.NUS_event_handler, ptr %48, i32 0, i32 2
  %50 = load i16, ptr %3, align 2, !tbaa !9
  %51 = sext i16 %50 to i64
  %52 = getelementptr inbounds [348 x %struct.anon.1], ptr %49, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.anon.1, ptr %52, i32 0, i32 1
  store i32 0, ptr %53, align 8, !tbaa !14
  br label %54

54:                                               ; preds = %29
  %55 = load i16, ptr %3, align 2, !tbaa !9
  %56 = add i16 %55, 1
  store i16 %56, ptr %3, align 2, !tbaa !9
  br label %25, !llvm.loop !17

57:                                               ; preds = %25
  store i16 0, ptr %3, align 2, !tbaa !9
  br label %58

58:                                               ; preds = %87, %57
  %59 = load i16, ptr %3, align 2, !tbaa !9
  %60 = sext i16 %59 to i32
  %61 = icmp slt i32 %60, 3
  br i1 %61, label %62, label %90

62:                                               ; preds = %58
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.NUS_event_handler, ptr %63, i32 0, i32 3
  %65 = load i16, ptr %3, align 2, !tbaa !9
  %66 = sext i16 %65 to i64
  %67 = getelementptr inbounds [3 x %struct.anon.2], ptr %64, i64 0, i64 %66
  %68 = getelementptr inbounds %struct.anon.2, ptr %67, i32 0, i32 0
  store ptr null, ptr %68, align 8, !tbaa !11
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.NUS_event_handler, ptr %69, i32 0, i32 3
  %71 = load i16, ptr %3, align 2, !tbaa !9
  %72 = sext i16 %71 to i64
  %73 = getelementptr inbounds [3 x %struct.anon.2], ptr %70, i64 0, i64 %72
  %74 = getelementptr inbounds %struct.anon.2, ptr %73, i32 0, i32 1
  store i32 0, ptr %74, align 8, !tbaa !14
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.NUS_event_handler, ptr %75, i32 0, i32 4
  %77 = load i16, ptr %3, align 2, !tbaa !9
  %78 = sext i16 %77 to i64
  %79 = getelementptr inbounds [3 x %struct.anon.3], ptr %76, i64 0, i64 %78
  %80 = getelementptr inbounds %struct.anon.3, ptr %79, i32 0, i32 0
  store ptr null, ptr %80, align 8, !tbaa !11
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.NUS_event_handler, ptr %81, i32 0, i32 4
  %83 = load i16, ptr %3, align 2, !tbaa !9
  %84 = sext i16 %83 to i64
  %85 = getelementptr inbounds [3 x %struct.anon.3], ptr %82, i64 0, i64 %84
  %86 = getelementptr inbounds %struct.anon.3, ptr %85, i32 0, i32 1
  store i32 0, ptr %86, align 8, !tbaa !14
  br label %87

87:                                               ; preds = %62
  %88 = load i16, ptr %3, align 2, !tbaa !9
  %89 = add i16 %88, 1
  store i16 %89, ptr %3, align 2, !tbaa !9
  br label %58, !llvm.loop !18

90:                                               ; preds = %58
  store i16 0, ptr %3, align 2, !tbaa !9
  br label %91

91:                                               ; preds = %108, %90
  %92 = load i16, ptr %3, align 2, !tbaa !9
  %93 = sext i16 %92 to i32
  %94 = icmp slt i32 %93, 4
  br i1 %94, label %95, label %111

95:                                               ; preds = %91
  %96 = load ptr, ptr %2, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.NUS_event_handler, ptr %96, i32 0, i32 6
  %98 = load i16, ptr %3, align 2, !tbaa !9
  %99 = sext i16 %98 to i64
  %100 = getelementptr inbounds [4 x %struct.anon.5], ptr %97, i64 0, i64 %99
  %101 = getelementptr inbounds %struct.anon.5, ptr %100, i32 0, i32 0
  store ptr null, ptr %101, align 8, !tbaa !11
  %102 = load ptr, ptr %2, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.NUS_event_handler, ptr %102, i32 0, i32 6
  %104 = load i16, ptr %3, align 2, !tbaa !9
  %105 = sext i16 %104 to i64
  %106 = getelementptr inbounds [4 x %struct.anon.5], ptr %103, i64 0, i64 %105
  %107 = getelementptr inbounds %struct.anon.5, ptr %106, i32 0, i32 1
  store i32 0, ptr %107, align 8, !tbaa !14
  br label %108

108:                                              ; preds = %95
  %109 = load i16, ptr %3, align 2, !tbaa !9
  %110 = add i16 %109, 1
  store i16 %110, ptr %3, align 2, !tbaa !9
  br label %91, !llvm.loop !19

111:                                              ; preds = %91
  store i16 0, ptr %3, align 2, !tbaa !9
  br label %112

112:                                              ; preds = %129, %111
  %113 = load i16, ptr %3, align 2, !tbaa !9
  %114 = sext i16 %113 to i32
  %115 = icmp slt i32 %114, 1
  br i1 %115, label %116, label %132

116:                                              ; preds = %112
  %117 = load ptr, ptr %2, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.NUS_event_handler, ptr %117, i32 0, i32 5
  %119 = load i16, ptr %3, align 2, !tbaa !9
  %120 = sext i16 %119 to i64
  %121 = getelementptr inbounds [1 x %struct.anon.4], ptr %118, i64 0, i64 %120
  %122 = getelementptr inbounds %struct.anon.4, ptr %121, i32 0, i32 0
  store ptr null, ptr %122, align 8, !tbaa !11
  %123 = load ptr, ptr %2, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.NUS_event_handler, ptr %123, i32 0, i32 5
  %125 = load i16, ptr %3, align 2, !tbaa !9
  %126 = sext i16 %125 to i64
  %127 = getelementptr inbounds [1 x %struct.anon.4], ptr %124, i64 0, i64 %126
  %128 = getelementptr inbounds %struct.anon.4, ptr %127, i32 0, i32 1
  store i32 0, ptr %128, align 8, !tbaa !14
  br label %129

129:                                              ; preds = %116
  %130 = load i16, ptr %3, align 2, !tbaa !9
  %131 = add i16 %130, 1
  store i16 %131, ptr %3, align 2, !tbaa !9
  br label %112, !llvm.loop !20

132:                                              ; preds = %112
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #2
  ret i32 1
}

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

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

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !13, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !16}
!20 = distinct !{!20, !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.anon.0 = type { ptr, i32 }
%struct.anon.1 = type { ptr, i32 }

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local noundef i32 @nus_event_handler_build(ptr nocapture noundef writeonly %0) local_unnamed_addr #0 {
.split:
  store ptr null, ptr %0, align 8, !tbaa !5
  %1 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 0, ptr %1, align 8, !tbaa !11
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = getelementptr inbounds i8, ptr %0, i64 5584
  br label %4

4:                                                ; preds = %4, %.split
  %indvars.iv = phi i64 [ 0, %.split ], [ %indvars.iv.next.1, %4 ]
  %5 = getelementptr inbounds [348 x %struct.anon.0], ptr %2, i64 0, i64 %indvars.iv
  store ptr null, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 0, ptr %6, align 8, !tbaa !11
  %7 = getelementptr inbounds [348 x %struct.anon.1], ptr %3, i64 0, i64 %indvars.iv
  store ptr null, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  store i32 0, ptr %8, align 8, !tbaa !11
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %9 = getelementptr inbounds [348 x %struct.anon.0], ptr %2, i64 0, i64 %indvars.iv.next
  store ptr null, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  store i32 0, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds [348 x %struct.anon.1], ptr %3, i64 0, i64 %indvars.iv.next
  store ptr null, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  store i32 0, ptr %12, align 8, !tbaa !11
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 348
  br i1 %exitcond.not.1, label %.preheader.split, label %4, !llvm.loop !12

.preheader.split:                                 ; preds = %4
  %13 = getelementptr inbounds i8, ptr %0, i64 11152
  %14 = getelementptr inbounds i8, ptr %0, i64 11200
  store ptr null, ptr %13, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 11160
  store i32 0, ptr %15, align 8, !tbaa !11
  store ptr null, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 11208
  store i32 0, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %0, i64 11168
  store ptr null, ptr %17, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 11176
  store i32 0, ptr %18, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %0, i64 11216
  store ptr null, ptr %19, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %0, i64 11224
  store i32 0, ptr %20, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %0, i64 11184
  store ptr null, ptr %21, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %0, i64 11192
  store i32 0, ptr %22, align 8, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %0, i64 11232
  store ptr null, ptr %23, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %0, i64 11240
  store i32 0, ptr %24, align 8, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %0, i64 11264
  store ptr null, ptr %25, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %0, i64 11272
  store i32 0, ptr %26, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %0, i64 11280
  store ptr null, ptr %27, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %0, i64 11288
  store i32 0, ptr %28, align 8, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %0, i64 11296
  store ptr null, ptr %29, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %0, i64 11304
  store i32 0, ptr %30, align 8, !tbaa !11
  %31 = getelementptr inbounds i8, ptr %0, i64 11312
  store ptr null, ptr %31, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %0, i64 11320
  store i32 0, ptr %32, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %0, i64 11248
  store ptr null, ptr %33, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %0, i64 11256
  store i32 0, ptr %34, align 8, !tbaa !11
  ret i32 1
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: write) 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" }

!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 0}
!6 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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