; LLVM IR from ponylang/ponyc :: src/libponyrt/asio (event)

; 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._pony_type_t = type { i32, i32, i64, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i8, ptr, ptr, ptr }
%struct.asio_event_t = type { ptr, ptr, i32, i32, i32, i8, i8, i8, i64 }
%struct.pony_actor_t = type { ptr, %struct.messageq_t, i8, [39 x i8], %struct.heap_t, i64, i8, i32, %struct.gc_t, [16 x i8] }
%struct.messageq_t = type { ptr, ptr }
%struct.heap_t = type { [5 x ptr], [5 x ptr], ptr, [4 x ptr], i64, i64 }
%struct.gc_t = type { i32, i32, i64, %struct.objectmap_t, %struct.actormap_t, ptr }
%struct.objectmap_t = type { %struct.hashmap_t }
%struct.hashmap_t = type { i64, i64, ptr, ptr }
%struct.actormap_t = type { %struct.hashmap_t }

; Function Attrs: nounwind uwtable
define dso_local ptr @pony_asio_event_create(ptr noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3, i1 noundef zeroext %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i8, align 1
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !11
  %17 = zext i1 %4 to i8
  store i8 %17, ptr %11, align 1, !tbaa !13
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %23, label %20

20:                                               ; preds = %5
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %23, label %24

23:                                               ; preds = %20, %5
  store ptr null, ptr %6, align 8
  br label %77

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %26, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._pony_type_t, ptr %27, i32 0, i32 14
  %29 = load i32, ptr %28, align 8, !tbaa !15
  store i32 %29, ptr %13, align 4, !tbaa !9
  %30 = load i32, ptr %13, align 4, !tbaa !9
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %33

32:                                               ; preds = %24
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %76

33:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %34 = call noalias ptr @ponyint_pool_alloc(i64 noundef 1)
  store ptr %34, ptr %15, align 8, !tbaa !5
  %35 = load ptr, ptr %15, align 8, !tbaa !5
  %36 = load ptr, ptr %15, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.asio_event_t, ptr %36, i32 0, i32 0
  store ptr %35, ptr %37, align 8, !tbaa !17
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load ptr, ptr %15, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.asio_event_t, ptr %39, i32 0, i32 1
  store ptr %38, ptr %40, align 8, !tbaa !19
  %41 = load i32, ptr %13, align 4, !tbaa !9
  %42 = load ptr, ptr %15, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.asio_event_t, ptr %42, i32 0, i32 2
  store i32 %41, ptr %43, align 8, !tbaa !20
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = load ptr, ptr %15, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.asio_event_t, ptr %45, i32 0, i32 3
  store i32 %44, ptr %46, align 4, !tbaa !21
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = load ptr, ptr %15, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.asio_event_t, ptr %48, i32 0, i32 4
  store i32 %47, ptr %49, align 8, !tbaa !22
  %50 = load i8, ptr %11, align 1, !tbaa !13, !range !23, !noundef !24
  %51 = trunc i8 %50 to i1
  %52 = load ptr, ptr %15, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.asio_event_t, ptr %52, i32 0, i32 5
  %54 = zext i1 %51 to i8
  store i8 %54, ptr %53, align 4, !tbaa !25
  %55 = load i64, ptr %10, align 8, !tbaa !11
  %56 = load ptr, ptr %15, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.asio_event_t, ptr %56, i32 0, i32 8
  store i64 %55, ptr %57, align 8, !tbaa !26
  %58 = load ptr, ptr %15, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.asio_event_t, ptr %58, i32 0, i32 7
  store i8 0, ptr %59, align 2, !tbaa !27
  %60 = load ptr, ptr %15, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.asio_event_t, ptr %60, i32 0, i32 6
  store i8 0, ptr %61, align 1, !tbaa !28
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.pony_actor_t, ptr %62, i32 0, i32 7
  %64 = load i32, ptr %63, align 4, !tbaa !29
  %65 = add i32 %64, 1
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.pony_actor_t, ptr %66, i32 0, i32 7
  store i32 %65, ptr %67, align 4, !tbaa !29
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %68 = call ptr (...) @pony_ctx()
  store ptr %68, ptr %16, align 8, !tbaa !5
  %69 = load ptr, ptr %16, align 8, !tbaa !5
  call void @pony_gc_send(ptr noundef %69)
  %70 = load ptr, ptr %16, align 8, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  call void @pony_traceknown(ptr noundef %70, ptr noundef %71, ptr noundef %72, i32 noundef 2)
  %73 = load ptr, ptr %16, align 8, !tbaa !5
  call void @pony_send_done(ptr noundef %73)
  %74 = load ptr, ptr %15, align 8, !tbaa !5
  call void @pony_asio_event_subscribe(ptr noundef %74)
  %75 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %75, ptr %6, align 8
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %76

76:                                               ; preds = %33, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %77

77:                                               ; preds = %76, %23
  %78 = load ptr, ptr %6, align 8
  ret ptr %78
}

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

declare noalias ptr @ponyint_pool_alloc(i64 noundef) #2

declare ptr @pony_ctx(...) #2

declare void @pony_gc_send(ptr noundef) #2

declare void @pony_traceknown(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

declare void @pony_send_done(ptr noundef) #2

declare void @pony_asio_event_subscribe(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 = !{!"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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!16, !10, i64 96}
!16 = !{!"_pony_type_t", !10, i64 0, !10, i64 4, !12, i64 8, !10, i64 16, !10, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !10, i64 96, !14, i64 100, !6, i64 104, !6, i64 112, !6, i64 120}
!17 = !{!18, !6, i64 0}
!18 = !{!"asio_event_t", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !14, i64 28, !14, i64 29, !14, i64 30, !12, i64 32}
!19 = !{!18, !6, i64 8}
!20 = !{!18, !10, i64 16}
!21 = !{!18, !10, i64 20}
!22 = !{!18, !10, i64 24}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = !{!18, !14, i64 28}
!26 = !{!18, !12, i64 32}
!27 = !{!18, !14, i64 30}
!28 = !{!18, !14, i64 29}
!29 = !{!30, !10, i64 212}
!30 = !{!"pony_actor_t", !6, i64 0, !31, i64 8, !7, i64 24, !32, i64 64, !12, i64 200, !7, i64 208, !10, i64 212, !33, i64 216}
!31 = !{!"messageq_t", !7, i64 0, !6, i64 8}
!32 = !{!"heap_t", !7, i64 0, !7, i64 40, !6, i64 80, !7, i64 88, !12, i64 120, !12, i64 128}
!33 = !{!"gc_t", !10, i64 0, !10, i64 4, !12, i64 8, !34, i64 16, !36, i64 48, !6, i64 80}
!34 = !{!"objectmap_t", !35, i64 0}
!35 = !{!"hashmap_t", !12, i64 0, !12, i64 8, !6, i64 16, !6, i64 24}
!36 = !{!"actormap_t", !35, 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"

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @pony_asio_event_create(ptr noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3, i1 noundef zeroext %4) local_unnamed_addr #0 {
  %6 = zext i1 %4 to i8
  %7 = add i32 %2, 1
  %or.cond = icmp ult i32 %7, 2
  br i1 %or.cond, label %27, label %8

8:                                                ; preds = %5
  %9 = load ptr, ptr %0, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 96
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = icmp eq i32 %11, -1
  br i1 %12, label %27, label %13

13:                                               ; preds = %8
  %14 = tail call noalias ptr @ponyint_pool_alloc(i64 noundef 1) #2
  store ptr %14, ptr %14, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr %0, ptr %15, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %14, i64 16
  store i32 %11, ptr %16, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %14, i64 20
  store i32 %1, ptr %17, align 4, !tbaa !18
  %18 = getelementptr inbounds i8, ptr %14, i64 24
  store i32 %2, ptr %18, align 8, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %14, i64 28
  store i8 %6, ptr %19, align 4, !tbaa !20
  %20 = getelementptr inbounds i8, ptr %14, i64 32
  store i64 %3, ptr %20, align 8, !tbaa !21
  %21 = getelementptr inbounds i8, ptr %14, i64 30
  store i8 0, ptr %21, align 2, !tbaa !22
  %22 = getelementptr inbounds i8, ptr %14, i64 29
  store i8 0, ptr %22, align 1, !tbaa !23
  %23 = getelementptr inbounds i8, ptr %0, i64 212
  %24 = load i32, ptr %23, align 4, !tbaa !24
  %25 = add i32 %24, 1
  store i32 %25, ptr %23, align 4, !tbaa !24
  %26 = tail call ptr (...) @pony_ctx() #2
  tail call void @pony_gc_send(ptr noundef %26) #2
  tail call void @pony_traceknown(ptr noundef %26, ptr noundef nonnull %0, ptr noundef nonnull %9, i32 noundef 2) #2
  tail call void @pony_send_done(ptr noundef %26) #2
  tail call void @pony_asio_event_subscribe(ptr noundef nonnull %14) #2
  br label %27

27:                                               ; preds = %13, %8, %5
  %.1 = phi ptr [ null, %5 ], [ %14, %13 ], [ null, %8 ]
  ret ptr %.1
}

declare noalias ptr @ponyint_pool_alloc(i64 noundef) local_unnamed_addr #1

declare ptr @pony_ctx(...) local_unnamed_addr #1

declare void @pony_gc_send(ptr noundef) local_unnamed_addr #1

declare void @pony_traceknown(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @pony_send_done(ptr noundef) local_unnamed_addr #1

declare void @pony_asio_event_subscribe(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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 96}
!10 = !{!"_pony_type_t", !11, i64 0, !11, i64 4, !12, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !11, i64 96, !13, i64 100, !6, i64 104, !6, i64 112, !6, i64 120}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"asio_event_t", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !13, i64 28, !13, i64 29, !13, i64 30, !12, i64 32}
!16 = !{!15, !6, i64 8}
!17 = !{!15, !11, i64 16}
!18 = !{!15, !11, i64 20}
!19 = !{!15, !11, i64 24}
!20 = !{!15, !13, i64 28}
!21 = !{!15, !12, i64 32}
!22 = !{!15, !13, i64 30}
!23 = !{!15, !13, i64 29}
!24 = !{!25, !11, i64 212}
!25 = !{!"pony_actor_t", !6, i64 0, !26, i64 8, !7, i64 24, !27, i64 64, !12, i64 200, !7, i64 208, !11, i64 212, !28, i64 216}
!26 = !{!"messageq_t", !7, i64 0, !6, i64 8}
!27 = !{!"heap_t", !7, i64 0, !7, i64 40, !6, i64 80, !7, i64 88, !12, i64 120, !12, i64 128}
!28 = !{!"gc_t", !11, i64 0, !11, i64 4, !12, i64 8, !29, i64 16, !31, i64 48, !6, i64 80}
!29 = !{!"objectmap_t", !30, i64 0}
!30 = !{!"hashmap_t", !12, i64 0, !12, i64 8, !6, i64 16, !6, i64 24}
!31 = !{!"actormap_t", !30, i64 0}


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