; LLVM IR from uNetworking/uSockets :: src/eventing (epoll_kqueue)

; 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.us_poll_t = type { %struct.anon, [12 x i8] }
%struct.anon = type { i32 }
%struct.us_loop_t = type { %struct.us_internal_loop_data_t, i32, i32, i32, i32, [1024 x %struct.epoll_event], [8 x i8] }
%struct.us_internal_loop_data_t = type { ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i64 }

; Function Attrs: nounwind uwtable
declare dso_local i32 @us_internal_poll_type(ptr noundef) #0

; 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

; Function Attrs: nounwind uwtable
define dso_local void @us_poll_start(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.epoll_event, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call i32 @us_internal_poll_type(ptr noundef %8)
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = and i32 %10, 1
  %12 = icmp ne i32 %11, 0
  %13 = zext i1 %12 to i64
  %14 = select i1 %12, i32 8, i32 0
  %15 = or i32 %9, %14
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = and i32 %16, 4
  %18 = icmp ne i32 %17, 0
  %19 = zext i1 %18 to i64
  %20 = select i1 %18, i32 4, i32 0
  %21 = or i32 %15, %20
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.us_poll_t, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 16
  %25 = and i32 %21, 15
  %26 = shl i32 %25, 28
  %27 = and i32 %24, 268435455
  %28 = or i32 %27, %26
  store i32 %28, ptr %23, align 16
  call void @llvm.lifetime.start.p0(i64 12, ptr %7) #3
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = getelementptr inbounds %struct.epoll_event, ptr %7, i32 0, i32 0
  store i32 %29, ptr %30, align 1, !tbaa !11
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.epoll_event, ptr %7, i32 0, i32 1
  store ptr %31, ptr %32, align 1, !tbaa !13
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.us_loop_t, ptr %33, i32 0, i32 4
  %35 = load i32, ptr %34, align 4, !tbaa !14
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.us_poll_t, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 16
  %39 = shl i32 %38, 4
  %40 = ashr i32 %39, 4
  %41 = call i32 @epoll_ctl(i32 noundef %35, i32 noundef 1, i32 noundef %40, ptr noundef %7) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %7) #3
  ret void
}

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

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 "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, !10, i64 0}
!12 = !{!"epoll_event", !10, i64 0, !7, i64 4}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 116}
!15 = !{!"us_loop_t", !16, i64 0, !10, i64 104, !10, i64 108, !10, i64 112, !10, i64 116, !7, i64 120}
!16 = !{!"us_internal_loop_data_t", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !17, i64 96}
!17 = !{!"long long", !7, 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"

%struct.epoll_event = type <{ i32, %union.epoll_data }>
%union.epoll_data = type { ptr }

; Function Attrs: nounwind uwtable
declare dso_local i32 @us_internal_poll_type(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @us_poll_start(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.epoll_event, align 4
  %5 = tail call i32 @us_internal_poll_type(ptr noundef %0)
  %6 = shl i32 %2, 3
  %7 = or i32 %5, %6
  %8 = and i32 %2, 4
  %9 = load i32, ptr %0, align 16
  %.masked = and i32 %7, 15
  %10 = or i32 %.masked, %8
  %11 = shl nuw i32 %10, 28
  %12 = and i32 %9, 268435455
  %13 = or disjoint i32 %11, %12
  store i32 %13, ptr %0, align 16
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #3
  store i32 %2, ptr %4, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %4, i64 4
  store ptr %0, ptr %14, align 4, !tbaa !10
  %15 = getelementptr inbounds i8, ptr %1, i64 116
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = shl i32 %9, 4
  %18 = ashr exact i32 %17, 4
  %19 = call i32 @epoll_ctl(i32 noundef %16, i32 noundef 1, i32 noundef %18, ptr noundef nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #3
  ret void
}

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !7, i64 0}
!6 = !{!"epoll_event", !7, i64 0, !8, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !7, i64 116}
!12 = !{!"us_loop_t", !13, i64 0, !7, i64 104, !7, i64 108, !7, i64 112, !7, i64 116, !8, i64 120}
!13 = !{!"us_internal_loop_data_t", !14, i64 0, !14, i64 8, !7, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !7, i64 88, !15, i64 96}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"long long", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass