; 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.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 }

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@__func__.pony_asio_event_destroy = external hidden unnamed_addr constant [24 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [32 x 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 ptr @pony_ctx(...) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @pony_asio_event_destroy(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %18, label %7

7:                                                ; preds = %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.asio_event_t, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = icmp ne ptr %10, %11
  br i1 %12, label %18, label %13

13:                                               ; preds = %7
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.asio_event_t, ptr %14, i32 0, i32 4
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %13, %7, %1
  call void @ponyint_assert_fail(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 49, ptr noundef @__func__.pony_asio_event_destroy)
  br label %63

19:                                               ; preds = %13
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.asio_event_t, ptr %20, i32 0, i32 5
  %22 = load i8, ptr %21, align 4, !tbaa !15, !range !16, !noundef !17
  %23 = trunc i8 %22 to i1
  br i1 %23, label %24, label %33

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %25 = call i64 (...) @ponyint_asio_noisy_remove()
  store i64 %25, ptr %3, align 8, !tbaa !18
  %26 = load i64, ptr %3, align 8, !tbaa !18
  %27 = icmp eq i64 %26, 1
  br i1 %27, label %28, label %30

28:                                               ; preds = %24
  %29 = call i32 (...) @pony_scheduler_index()
  call void @ponyint_sched_unnoisy_asio(i32 noundef %29)
  br label %30

30:                                               ; preds = %28, %24
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.asio_event_t, ptr %31, i32 0, i32 5
  store i8 0, ptr %32, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %33

33:                                               ; preds = %30, %19
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.asio_event_t, ptr %34, i32 0, i32 4
  store i32 -1, ptr %35, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %36 = call ptr (...) @pony_ctx()
  store ptr %36, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  call void @pony_gc_recv(ptr noundef %37)
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.asio_event_t, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !19
  call void @pony_traceunknown(ptr noundef %38, ptr noundef %41, i32 noundef 2)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  call void @pony_recv_done(ptr noundef %42)
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.asio_event_t, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !19
  %46 = getelementptr inbounds %struct.pony_actor_t, ptr %45, i32 0, i32 7
  %47 = load i32, ptr %46, align 4, !tbaa !20
  %48 = icmp ugt i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %33
  br label %51

50:                                               ; preds = %33
  call void @ponyint_assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i64 noundef 73, ptr noundef @__func__.pony_asio_event_destroy)
  br label %51

51:                                               ; preds = %50, %49
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.asio_event_t, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !19
  %55 = getelementptr inbounds %struct.pony_actor_t, ptr %54, i32 0, i32 7
  %56 = load i32, ptr %55, align 4, !tbaa !20
  %57 = sub i32 %56, 1
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.asio_event_t, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !19
  %61 = getelementptr inbounds %struct.pony_actor_t, ptr %60, i32 0, i32 7
  store i32 %57, ptr %61, align 4, !tbaa !20
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  call void @ponyint_pool_free(i64 noundef 1, ptr noundef %62)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %63

63:                                               ; preds = %51, %18
  ret void
}

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

declare i64 @ponyint_asio_noisy_remove(...) #1

declare void @ponyint_sched_unnoisy_asio(i32 noundef) #1

declare i32 @pony_scheduler_index(...) #1

declare void @pony_gc_recv(ptr noundef) #1

declare void @pony_traceunknown(ptr noundef, ptr noundef, i32 noundef) #1

declare void @pony_recv_done(ptr noundef) #1

declare void @ponyint_pool_free(i64 noundef, ptr noundef) #1

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

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@__func__.pony_asio_event_destroy = external hidden unnamed_addr constant [24 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [32 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @pony_asio_event_destroy(ptr noundef %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %8, label %3

3:                                                ; preds = %1
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %4, %0
  br i1 %.not, label %5, label %8

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i32, ptr %6, align 8, !tbaa !13
  %.not15 = icmp eq i32 %7, 0
  br i1 %.not15, label %9, label %8

8:                                                ; preds = %5, %3, %1
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 49, ptr noundef nonnull @__func__.pony_asio_event_destroy) #2
  br label %32

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 28
  %11 = load i8, ptr %10, align 4, !tbaa !14, !range !15, !noundef !16
  %12 = trunc nuw i8 %11 to i1
  br i1 %12, label %13, label %19

13:                                               ; preds = %9
  %14 = tail call i64 (...) @ponyint_asio_noisy_remove() #2
  %15 = icmp eq i64 %14, 1
  br i1 %15, label %16, label %18

16:                                               ; preds = %13
  %17 = tail call i32 (...) @pony_scheduler_index() #2
  tail call void @ponyint_sched_unnoisy_asio(i32 noundef %17) #2
  br label %18

18:                                               ; preds = %16, %13
  store i8 0, ptr %10, align 4, !tbaa !14
  br label %19

19:                                               ; preds = %18, %9
  store i32 -1, ptr %6, align 8, !tbaa !13
  %20 = tail call ptr (...) @pony_ctx() #2
  tail call void @pony_gc_recv(ptr noundef %20) #2
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  tail call void @pony_traceunknown(ptr noundef %20, ptr noundef %22, i32 noundef 2) #2
  tail call void @pony_recv_done(ptr noundef %20) #2
  %23 = load ptr, ptr %21, align 8, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %23, i64 212
  %25 = load i32, ptr %24, align 4, !tbaa !18
  %.not16 = icmp eq i32 %25, 0
  br i1 %.not16, label %26, label %27

26:                                               ; preds = %19
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i64 noundef 73, ptr noundef nonnull @__func__.pony_asio_event_destroy) #2
  %.pre = load ptr, ptr %21, align 8, !tbaa !17
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.pre, i64 212
  %.pre17 = load i32, ptr %.phi.trans.insert, align 4, !tbaa !18
  br label %27

27:                                               ; preds = %19, %26
  %28 = phi i32 [ %25, %19 ], [ %.pre17, %26 ]
  %29 = phi ptr [ %23, %19 ], [ %.pre, %26 ]
  %30 = getelementptr inbounds i8, ptr %29, i64 212
  %31 = add i32 %28, -1
  store i32 %31, ptr %30, align 4, !tbaa !18
  tail call void @ponyint_pool_free(i64 noundef 1, ptr noundef nonnull %0) #2
  br label %32

32:                                               ; preds = %27, %8
  ret void
}

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

declare i64 @ponyint_asio_noisy_remove(...) local_unnamed_addr #0

declare void @ponyint_sched_unnoisy_asio(i32 noundef) local_unnamed_addr #0

declare i32 @pony_scheduler_index(...) local_unnamed_addr #0

declare void @pony_gc_recv(ptr noundef) local_unnamed_addr #0

declare void @pony_traceunknown(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare void @pony_recv_done(ptr noundef) local_unnamed_addr #0

declare void @ponyint_pool_free(i64 noundef, ptr noundef) local_unnamed_addr #0

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 = { 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 }

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


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