; 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_poll_events(ptr noundef) #0

; 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_change(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 i32, align 4
  %8 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call i32 @us_poll_events(ptr noundef %9)
  store i32 %10, ptr %7, align 4, !tbaa !9
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp ne i32 %11, %12
  br i1 %13, label %14, label %49

14:                                               ; preds = %3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call i32 @us_internal_poll_type(ptr noundef %15)
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = and i32 %17, 1
  %19 = icmp ne i32 %18, 0
  %20 = zext i1 %19 to i64
  %21 = select i1 %19, i32 8, i32 0
  %22 = or i32 %16, %21
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = and i32 %23, 4
  %25 = icmp ne i32 %24, 0
  %26 = zext i1 %25 to i64
  %27 = select i1 %25, i32 4, i32 0
  %28 = or i32 %22, %27
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.us_poll_t, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 16
  %32 = and i32 %28, 15
  %33 = shl i32 %32, 28
  %34 = and i32 %31, 268435455
  %35 = or i32 %34, %33
  store i32 %35, ptr %30, align 16
  call void @llvm.lifetime.start.p0(i64 12, ptr %8) #3
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = getelementptr inbounds %struct.epoll_event, ptr %8, i32 0, i32 0
  store i32 %36, ptr %37, align 1, !tbaa !11
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.epoll_event, ptr %8, i32 0, i32 1
  store ptr %38, ptr %39, align 1, !tbaa !13
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.us_loop_t, ptr %40, i32 0, i32 4
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.us_poll_t, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 16
  %46 = shl i32 %45, 4
  %47 = ashr i32 %46, 4
  %48 = call i32 @epoll_ctl(i32 noundef %42, i32 noundef 3, i32 noundef %47, ptr noundef %8) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %8) #3
  br label %49

49:                                               ; preds = %14, %3
  call void @llvm.lifetime.end.p0(i64 4, 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_poll_events(ptr noundef) local_unnamed_addr #0

; 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_change(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_poll_events(ptr noundef %0)
  %.not = icmp eq i32 %5, %2
  br i1 %.not, label %22, label %6

6:                                                ; preds = %3
  %7 = tail call i32 @us_internal_poll_type(ptr noundef %0)
  %8 = shl i32 %2, 3
  %9 = or i32 %7, %8
  %10 = and i32 %2, 4
  %11 = load i32, ptr %0, align 16
  %.masked = and i32 %9, 15
  %12 = or i32 %.masked, %10
  %13 = shl nuw i32 %12, 28
  %14 = and i32 %11, 268435455
  %15 = or disjoint i32 %13, %14
  store i32 %15, 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
  %16 = getelementptr inbounds i8, ptr %4, i64 4
  store ptr %0, ptr %16, align 4, !tbaa !10
  %17 = getelementptr inbounds i8, ptr %1, i64 116
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = shl i32 %11, 4
  %20 = ashr exact i32 %19, 4
  %21 = call i32 @epoll_ctl(i32 noundef %18, i32 noundef 3, i32 noundef %20, ptr noundef nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #3
  br label %22

22:                                               ; preds = %6, %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