; LLVM IR from asllop/AppOS :: event (event_internal)

; 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.QueueStruct = type { ptr, i64, i32, i32, i32 }

@queueArray = external hidden global [128 x %struct.QueueStruct], align 16
@.str = external hidden unnamed_addr constant [42 x i8], align 1

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

2:                                                ; preds = %41, %0
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 128
  br i1 %4, label %6, label %5

5:                                                ; preds = %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %44

6:                                                ; preds = %2
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [128 x %struct.QueueStruct], ptr @queueArray, i64 0, i64 %8
  %10 = getelementptr inbounds %struct.QueueStruct, ptr %9, i32 0, i32 4
  store i32 0, ptr %10, align 8, !tbaa !9
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [128 x %struct.QueueStruct], ptr @queueArray, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.QueueStruct, ptr %13, i32 0, i32 2
  store i32 0, ptr %14, align 16, !tbaa !13
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [128 x %struct.QueueStruct], ptr @queueArray, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.QueueStruct, ptr %17, i32 0, i32 3
  store i32 0, ptr %18, align 4, !tbaa !14
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [128 x %struct.QueueStruct], ptr @queueArray, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.QueueStruct, ptr %21, i32 0, i32 1
  store i64 8192, ptr %22, align 8, !tbaa !15
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [128 x %struct.QueueStruct], ptr @queueArray, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.QueueStruct, ptr %25, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = call ptr @core_malloc(i64 noundef %27)
  %29 = load i32, ptr %1, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [128 x %struct.QueueStruct], ptr @queueArray, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.QueueStruct, ptr %31, i32 0, i32 0
  store ptr %28, ptr %32, align 16, !tbaa !16
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [128 x %struct.QueueStruct], ptr @queueArray, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.QueueStruct, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 16, !tbaa !16
  %38 = icmp ne ptr %37, null
  br i1 %38, label %40, label %39

39:                                               ; preds = %6
  call void @core_fatal(ptr noundef @.str)
  br label %40

40:                                               ; preds = %39, %6
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %1, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %1, align 4, !tbaa !5
  br label %2, !llvm.loop !17

44:                                               ; preds = %5
  ret void
}

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

declare ptr @core_malloc(i64 noundef) #2

declare void @core_fatal(ptr noundef) #2

; 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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"QueueStruct", !11, i64 0, !12, i64 8, !6, i64 16, !6, i64 20, !6, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !6, i64 20}
!15 = !{!10, !12, i64 8}
!16 = !{!10, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.QueueStruct = type { ptr, i64, i32, i32, i32 }

@queueArray = external hidden local_unnamed_addr global [128 x %struct.QueueStruct], align 16
@.str = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @event_init() local_unnamed_addr #0 {
  br label %2

1:                                                ; preds = %10
  ret void

2:                                                ; preds = %0, %10
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %10 ]
  %3 = getelementptr inbounds [128 x %struct.QueueStruct], ptr @queueArray, i64 0, i64 %indvars.iv
  %4 = getelementptr inbounds i8, ptr %3, i64 24
  store i32 0, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 0, ptr %5, align 16, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %3, i64 20
  store i32 0, ptr %6, align 4, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  store i64 8192, ptr %7, align 8, !tbaa !14
  %8 = tail call ptr @core_malloc(i64 noundef 8192) #2
  store ptr %8, ptr %3, align 16, !tbaa !15
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %9, label %10

9:                                                ; preds = %2
  tail call void @core_fatal(ptr noundef nonnull @.str) #2
  br label %10

10:                                               ; preds = %2, %9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 128
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !16
}

declare ptr @core_malloc(i64 noundef) local_unnamed_addr #1

declare void @core_fatal(ptr noundef) local_unnamed_addr #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 = { "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 }

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


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