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

; 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.epoll_event = type <{ i32, %union.epoll_data }>
%union.epoll_data = type { ptr }
%struct.asio_event_t = type { ptr, ptr, i32, i32, i32, i8, i8, i8, i64 }
%struct.asio_backend_t = type { i32, i32, [64 x %struct.epoll_event], [128 x ptr], i8, %struct.messageq_t }
%struct.messageq_t = type { ptr, ptr }

@.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_resubscribe = external hidden unnamed_addr constant [28 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 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

; Function Attrs: nounwind
declare i32 @epoll_ctl(i32 noundef, i32 noundef, i32 noundef, ptr noundef) #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_resubscribe(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %struct.epoll_event, align 1
  %5 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %24, label %8

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

13:                                               ; preds = %8
  %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 !9
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %24, label %18

18:                                               ; preds = %13
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.asio_event_t, ptr %19, i32 0, i32 4
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = and i32 %21, 256
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %25, label %24

24:                                               ; preds = %18, %13, %8, %1
  call void @ponyint_assert_fail(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 158, ptr noundef @__func__.pony_asio_event_resubscribe)
  br label %79

25:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %26 = call ptr (...) @ponyint_asio_get_backend()
  store ptr %26, ptr %3, align 8, !tbaa !5
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  br label %31

30:                                               ; preds = %25
  call void @ponyint_assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i64 noundef 163, ptr noundef @__func__.pony_asio_event_resubscribe)
  br label %31

31:                                               ; preds = %30, %29
  call void @llvm.lifetime.start.p0(i64 12, ptr %4) #4
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.epoll_event, ptr %4, i32 0, i32 1
  store ptr %32, ptr %33, align 1, !tbaa !14
  %34 = getelementptr inbounds %struct.epoll_event, ptr %4, i32 0, i32 0
  store i32 1073741824, ptr %34, align 1, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  store i8 0, ptr %5, align 1, !tbaa !17
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.asio_event_t, ptr %35, i32 0, i32 4
  %37 = load i32, ptr %36, align 8, !tbaa !9
  %38 = and i32 %37, 2
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %49

40:                                               ; preds = %31
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.asio_event_t, ptr %41, i32 0, i32 7
  %43 = load i8, ptr %42, align 2, !tbaa !18, !range !19, !noundef !20
  %44 = trunc i8 %43 to i1
  br i1 %44, label %49, label %45

45:                                               ; preds = %40
  store i8 1, ptr %5, align 1, !tbaa !17
  %46 = getelementptr inbounds %struct.epoll_event, ptr %4, i32 0, i32 0
  %47 = load i32, ptr %46, align 1, !tbaa !15
  %48 = or i32 %47, 4
  store i32 %48, ptr %46, align 1, !tbaa !15
  br label %49

49:                                               ; preds = %45, %40, %31
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.asio_event_t, ptr %50, i32 0, i32 4
  %52 = load i32, ptr %51, align 8, !tbaa !9
  %53 = and i32 %52, 1
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %67

55:                                               ; preds = %49
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.asio_event_t, ptr %56, i32 0, i32 6
  %58 = load i8, ptr %57, align 1, !tbaa !21, !range !19, !noundef !20
  %59 = trunc i8 %58 to i1
  br i1 %59, label %67, label %60

60:                                               ; preds = %55
  store i8 1, ptr %5, align 1, !tbaa !17
  %61 = getelementptr inbounds %struct.epoll_event, ptr %4, i32 0, i32 0
  %62 = load i32, ptr %61, align 1, !tbaa !15
  %63 = or i32 %62, 8192
  store i32 %63, ptr %61, align 1, !tbaa !15
  %64 = getelementptr inbounds %struct.epoll_event, ptr %4, i32 0, i32 0
  %65 = load i32, ptr %64, align 1, !tbaa !15
  %66 = or i32 %65, 1
  store i32 %66, ptr %64, align 1, !tbaa !15
  br label %67

67:                                               ; preds = %60, %55, %49
  %68 = load i8, ptr %5, align 1, !tbaa !17, !range !19, !noundef !20
  %69 = trunc i8 %68 to i1
  br i1 %69, label %70, label %78

70:                                               ; preds = %67
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.asio_backend_t, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 8, !tbaa !22
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.asio_event_t, ptr %74, i32 0, i32 3
  %76 = load i32, ptr %75, align 4, !tbaa !25
  %77 = call i32 @epoll_ctl(i32 noundef %73, i32 noundef 3, i32 noundef %76, ptr noundef %4) #4
  br label %78

78:                                               ; preds = %70, %67
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %79

79:                                               ; preds = %78, %24
  ret void
}

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

declare ptr @ponyint_asio_get_backend(...) #3

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 }

!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 24}
!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 = !{!7, !7, i64 0}
!15 = !{!16, !11, i64 0}
!16 = !{!"epoll_event", !11, i64 0, !7, i64 4}
!17 = !{!12, !12, i64 0}
!18 = !{!10, !12, i64 30}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!10, !12, i64 29}
!22 = !{!23, !11, i64 0}
!23 = !{!"asio_backend_t", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 776, !7, i64 1800, !24, i64 1808}
!24 = !{!"messageq_t", !7, i64 0, !6, i64 8}
!25 = !{!10, !11, i64 20}


; 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.epoll_event = type <{ i32, %union.epoll_data }>
%union.epoll_data = type { ptr }

@.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_resubscribe = external hidden unnamed_addr constant [28 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1

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

; Function Attrs: nounwind
declare i32 @epoll_ctl(i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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_resubscribe(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca %struct.epoll_event, align 4
  %3 = icmp eq ptr %0, null
  br i1 %3, label %9, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i32, ptr %5, align 8, !tbaa !5
  switch i32 %6, label %7 [
    i32 0, label %9
    i32 -1, label %9
  ]

7:                                                ; preds = %4
  %8 = and i32 %6, 256
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %10

9:                                                ; preds = %4, %4, %7, %1
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 158, ptr noundef nonnull @__func__.pony_asio_event_resubscribe) #4
  br label %36

10:                                               ; preds = %7
  %11 = tail call ptr (...) @ponyint_asio_get_backend() #4
  %.not14 = icmp eq ptr %11, null
  br i1 %.not14, label %12, label %13

12:                                               ; preds = %10
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i64 noundef 163, ptr noundef nonnull @__func__.pony_asio_event_resubscribe) #4
  br label %13

13:                                               ; preds = %10, %12
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %2) #4
  %14 = getelementptr inbounds i8, ptr %2, i64 4
  store ptr %0, ptr %14, align 4, !tbaa !13
  store i32 1073741824, ptr %2, align 4, !tbaa !14
  %15 = load i32, ptr %5, align 8, !tbaa !5
  %16 = and i32 %15, 2
  %.not15 = icmp eq i32 %16, 0
  br i1 %.not15, label %22, label %17

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %0, i64 30
  %19 = load i8, ptr %18, align 2, !tbaa !16, !range !17, !noundef !18
  %20 = trunc nuw i8 %19 to i1
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 1073741828, ptr %2, align 4, !tbaa !14
  br label %22

22:                                               ; preds = %21, %17, %13
  %23 = phi i32 [ 1073750017, %17 ], [ 1073750021, %21 ], [ 1073750017, %13 ]
  %.0 = phi i1 [ false, %17 ], [ true, %21 ], [ false, %13 ]
  %24 = and i32 %15, 1
  %.not16 = icmp eq i32 %24, 0
  br i1 %.not16, label %29, label %25

25:                                               ; preds = %22
  %26 = getelementptr inbounds i8, ptr %0, i64 29
  %27 = load i8, ptr %26, align 1, !tbaa !19, !range !17, !noundef !18
  %28 = trunc nuw i8 %27 to i1
  br i1 %28, label %29, label %.thread

.thread:                                          ; preds = %25
  store i32 %23, ptr %2, align 4, !tbaa !14
  br label %30

29:                                               ; preds = %25, %22
  br i1 %.0, label %30, label %35

30:                                               ; preds = %.thread, %29
  %31 = load i32, ptr %11, align 8, !tbaa !20
  %32 = getelementptr inbounds i8, ptr %0, i64 20
  %33 = load i32, ptr %32, align 4, !tbaa !23
  %34 = call i32 @epoll_ctl(i32 noundef %31, i32 noundef 3, i32 noundef %33, ptr noundef nonnull %2) #4
  br label %35

35:                                               ; preds = %30, %29
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %2) #4
  br label %36

36:                                               ; preds = %35, %9
  ret void
}

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

declare ptr @ponyint_asio_get_backend(...) local_unnamed_addr #3

attributes #0 = { mustprogress 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 }

!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, !10, i64 24}
!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 = !{!8, !8, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"epoll_event", !10, i64 0, !8, i64 4}
!16 = !{!6, !11, i64 30}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!6, !11, i64 29}
!20 = !{!21, !10, i64 0}
!21 = !{!"asio_backend_t", !10, i64 0, !10, i64 4, !8, i64 8, !8, i64 776, !8, i64 1800, !22, i64 1808}
!22 = !{!"messageq_t", !8, i64 0, !7, i64 8}
!23 = !{!6, !10, i64 20}


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