; LLVM IR from kala13x/libxutils :: src/net (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.XEvents = type { ptr, i32, ptr, ptr, i32, i32, i8, %struct.XHash }
%struct.XHash = type { ptr, ptr, i64, [32 x %struct.xlist] }
%struct.xlist = type { ptr, ptr, %struct.xlist_data, i8 }
%struct.xlist_data = type { ptr, ptr, ptr, i64 }
%struct.epoll_event = type <{ i32, %union.epoll_data }>
%union.epoll_data = type { ptr }
%struct.XEventData = type { ptr, i32, i8, i32, i32, i32 }

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

; 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 i32 @XEvents_Service(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %2
  store i32 10, ptr %3, align 4
  br label %99

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.XEvents, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.XEvents, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.XEvents, ptr %22, i32 0, i32 5
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = call i32 @epoll_wait(i32 noundef %18, ptr noundef %21, i32 noundef %24, i32 noundef %25)
  store i32 %26, ptr %7, align 4, !tbaa !9
  %27 = call ptr @__errno_location() #5
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = icmp eq i32 %28, 4
  br i1 %29, label %30, label %33

30:                                               ; preds = %15
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call i32 @XEvents_InterruptCb(ptr noundef %31)
  store i32 %32, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %98

33:                                               ; preds = %15
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store i32 5, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %98

37:                                               ; preds = %33
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %41, label %40

40:                                               ; preds = %37
  store i32 11, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %98

41:                                               ; preds = %37
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %90, %43
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %48, label %93

48:                                               ; preds = %44
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.XEvents, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds %struct.epoll_event, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct.epoll_event, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 1, !tbaa !17
  %57 = icmp eq ptr %56, null
  br i1 %57, label %58, label %59

58:                                               ; preds = %48
  br label %90

59:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.XEvents, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds %struct.epoll_event, ptr %62, i64 %64
  %66 = getelementptr inbounds %struct.epoll_event, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 1, !tbaa !17
  store ptr %67, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.XEvents, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !15
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds %struct.epoll_event, ptr %70, i64 %72
  %74 = getelementptr inbounds %struct.epoll_event, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 1, !tbaa !18
  store i32 %75, ptr %11, align 4, !tbaa !9
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.XEventData, ptr %78, i32 0, i32 3
  %80 = load i32, ptr %79, align 8, !tbaa !20
  %81 = load i32, ptr %11, align 4, !tbaa !9
  %82 = call i32 @XEvents_ServiceCb(ptr noundef %76, ptr noundef %77, i32 noundef %80, i32 noundef %81)
  store i32 %82, ptr %8, align 4, !tbaa !9
  %83 = load i32, ptr %8, align 4, !tbaa !9
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %86

85:                                               ; preds = %59
  store i32 2, ptr %9, align 4
  br label %87

86:                                               ; preds = %59
  store i32 0, ptr %9, align 4
  br label %87

87:                                               ; preds = %86, %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %88 = load i32, ptr %9, align 4
  switch i32 %88, label %101 [
    i32 0, label %89
    i32 2, label %93
  ]

89:                                               ; preds = %87
  br label %90

90:                                               ; preds = %89, %58
  %91 = load i32, ptr %6, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %6, align 4, !tbaa !9
  br label %44, !llvm.loop !22

93:                                               ; preds = %87, %44
  %94 = load i32, ptr %8, align 4, !tbaa !9
  %95 = icmp eq i32 %94, 4
  %96 = zext i1 %95 to i64
  %97 = select i1 %95, i32 12, i32 11
  store i32 %97, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %98

98:                                               ; preds = %93, %40, %36, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %99

99:                                               ; preds = %98, %14
  %100 = load i32, ptr %3, align 4
  ret i32 %100

101:                                              ; preds = %87
  unreachable
}

declare i32 @epoll_wait(i32 noundef, ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

; Function Attrs: nounwind uwtable
declare hidden i32 @XEvents_InterruptCb(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @XEvents_ServiceCb(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 willreturn memory(none) "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 }
attributes #5 = { nounwind willreturn memory(none) }

!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 8}
!12 = !{!"XEvents", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !7, i64 40, !13, i64 48}
!13 = !{!"XHash", !6, i64 0, !6, i64 8, !14, i64 16, !7, i64 24}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !10, i64 36}
!17 = !{!7, !7, i64 0}
!18 = !{!19, !10, i64 0}
!19 = !{!"epoll_event", !10, i64 0, !7, i64 4}
!20 = !{!21, !10, i64 16}
!21 = !{!"XEventData", !6, i64 0, !10, i64 8, !7, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; 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
define dso_local i32 @XEvents_Service(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %._crit_edge.thread, label %3

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %0, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %0, i64 36
  %8 = load i32, ptr %7, align 4, !tbaa !14
  %9 = tail call i32 @epoll_wait(i32 noundef %5, ptr noundef %6, i32 noundef %8, i32 noundef %1) #3
  %10 = tail call ptr @__errno_location() #4
  %11 = load i32, ptr %10, align 4, !tbaa !15
  %12 = icmp eq i32 %11, 4
  br i1 %12, label %13, label %15

13:                                               ; preds = %3
  %14 = tail call i32 @XEvents_InterruptCb(ptr noundef nonnull %0)
  br label %._crit_edge.thread

15:                                               ; preds = %3
  %16 = icmp slt i32 %9, 0
  br i1 %16, label %._crit_edge.thread, label %17

17:                                               ; preds = %15
  %.not31 = icmp eq i32 %9, 0
  br i1 %.not31, label %._crit_edge.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %17
  %wide.trip.count = zext nneg i32 %9 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %28
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %28 ]
  %18 = load ptr, ptr %0, align 8, !tbaa !13
  %19 = getelementptr inbounds %struct.epoll_event, ptr %18, i64 %indvars.iv
  %20 = getelementptr inbounds i8, ptr %19, i64 4
  %21 = load ptr, ptr %20, align 1, !tbaa !16
  %22 = icmp eq ptr %21, null
  br i1 %22, label %28, label %23

23:                                               ; preds = %.lr.ph
  %24 = load i32, ptr %19, align 1, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %21, i64 16
  %26 = load i32, ptr %25, align 8, !tbaa !19
  %27 = tail call i32 @XEvents_ServiceCb(ptr noundef nonnull %0, ptr noundef nonnull %21, i32 noundef %26, i32 noundef %24)
  %.fr = freeze i32 %27
  %.not32 = icmp eq i32 %.fr, 0
  br i1 %.not32, label %28, label %._crit_edge

28:                                               ; preds = %23, %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.thread, label %.lr.ph, !llvm.loop !21

._crit_edge:                                      ; preds = %23
  %29 = icmp eq i32 %.fr, 4
  %spec.select = select i1 %29, i32 12, i32 11
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %28, %._crit_edge, %13, %15, %17, %2
  %.1 = phi i32 [ 10, %2 ], [ %14, %13 ], [ 5, %15 ], [ 11, %17 ], [ %spec.select, %._crit_edge ], [ 11, %28 ]
  ret i32 %.1
}

declare i32 @epoll_wait(i32 noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare hidden i32 @XEvents_ServiceCb(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 }
attributes #4 = { nounwind willreturn memory(none) }

!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 8}
!6 = !{!"XEvents", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36, !8, i64 40, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"XHash", !7, i64 0, !7, i64 8, !12, i64 16, !8, i64 24}
!12 = !{!"long", !8, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 36}
!15 = !{!10, !10, i64 0}
!16 = !{!8, !8, i64 0}
!17 = !{!18, !10, i64 0}
!18 = !{!"epoll_event", !10, i64 0, !8, i64 4}
!19 = !{!20, !10, i64 16}
!20 = !{!"XEventData", !7, i64 0, !10, i64 8, !8, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass