; 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.XEventData = type { ptr, i32, i8, i32, i32, i32 }
%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 }

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

; Function Attrs: nounwind uwtable
declare hidden void @XEvents_ClearCb(ptr noundef, ptr noundef, i32 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
declare i32 @epoll_ctl(i32 noundef, i32 noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @XEvents_Delete(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  store i32 11, ptr %3, align 4
  br label %69

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 -1, ptr %6, align 4, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.XEventData, ptr %15, i32 0, i32 3
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp sge i32 %17, 0
  br i1 %18, label %19, label %40

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.XEvents, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !13
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.XEventData, ptr %23, i32 0, i32 3
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = call i32 @epoll_ctl(i32 noundef %22, i32 noundef 2, i32 noundef %25, ptr noundef null) #4
  store i32 %26, ptr %6, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp sge i32 %27, 0
  br i1 %28, label %29, label %39

29:                                               ; preds = %19
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.XEvents, ptr %30, i32 0, i32 4
  %32 = load i32, ptr %31, align 8, !tbaa !17
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %39

34:                                               ; preds = %29
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XEvents, ptr %35, i32 0, i32 4
  %37 = load i32, ptr %36, align 8, !tbaa !17
  %38 = add i32 %37, -1
  store i32 %38, ptr %36, align 8, !tbaa !17
  br label %39

39:                                               ; preds = %34, %29, %19
  br label %40

40:                                               ; preds = %39, %14
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.XEvents, ptr %41, i32 0, i32 6
  %43 = load i8, ptr %42, align 8, !tbaa !18
  %44 = icmp ne i8 %43, 0
  br i1 %44, label %45, label %58

45:                                               ; preds = %40
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.XEventData, ptr %46, i32 0, i32 3
  %48 = load i32, ptr %47, align 8, !tbaa !11
  %49 = icmp eq i32 %48, -1
  br i1 %49, label %58, label %50

50:                                               ; preds = %45
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.XEvents, ptr %51, i32 0, i32 7
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.XEventData, ptr %53, i32 0, i32 3
  %55 = load i32, ptr %54, align 8, !tbaa !11
  %56 = call i32 @XHash_Delete(ptr noundef %52, i32 noundef %55)
  %57 = icmp slt i32 %56, 0
  br i1 %57, label %58, label %64

58:                                               ; preds = %50, %45, %40
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.XEventData, ptr %61, i32 0, i32 3
  %63 = load i32, ptr %62, align 8, !tbaa !11
  call void @XEvents_ClearCb(ptr noundef %59, ptr noundef %60, i32 noundef %63)
  br label %64

64:                                               ; preds = %58, %50
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = icmp slt i32 %65, 0
  %67 = zext i1 %66 to i64
  %68 = select i1 %66, i32 1, i32 11
  store i32 %68, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %69

69:                                               ; preds = %64, %13, %9
  %70 = load i32, ptr %3, align 4
  ret i32 %70
}

declare i32 @XHash_Delete(ptr noundef, i32 noundef) #3

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 = { 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 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"XEventData", !6, i64 0, !10, i64 8, !7, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!13 = !{!14, !10, i64 8}
!14 = !{!"XEvents", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !7, i64 40, !15, i64 48}
!15 = !{!"XHash", !6, i64 0, !6, i64 8, !16, i64 16, !7, i64 24}
!16 = !{!"long", !7, i64 0}
!17 = !{!14, !10, i64 32}
!18 = !{!14, !7, i64 40}


; 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"

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 1, 12) i32 @XEvents_Delete(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %29, label %3

3:                                                ; preds = %2
  %.not23 = icmp eq ptr %1, null
  br i1 %.not23, label %29, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i32 %6, -1
  br i1 %7, label %8, label %18

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = tail call i32 @epoll_ctl(i32 noundef %10, i32 noundef 2, i32 noundef %6, ptr noundef null) #3
  %12 = icmp sgt i32 %11, -1
  br i1 %12, label %13, label %thread-pre-split

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = load i32, ptr %14, align 8, !tbaa !15
  %.not24 = icmp eq i32 %15, 0
  br i1 %.not24, label %thread-pre-split, label %16

16:                                               ; preds = %13
  %17 = add i32 %15, -1
  store i32 %17, ptr %14, align 8, !tbaa !15
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %16, %13, %8
  %.0.ph = phi i32 [ 1, %8 ], [ 11, %13 ], [ 11, %16 ]
  %.pre26.pr = load i32, ptr %5, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %thread-pre-split, %4
  %.pre26 = phi i32 [ %.pre26.pr, %thread-pre-split ], [ %6, %4 ]
  %.0 = phi i32 [ %.0.ph, %thread-pre-split ], [ 1, %4 ]
  %19 = getelementptr inbounds i8, ptr %0, i64 40
  %20 = load i8, ptr %19, align 8, !tbaa !16
  %.not25 = icmp eq i8 %20, 0
  br i1 %.not25, label %27, label %21

21:                                               ; preds = %18
  %22 = icmp eq i32 %.pre26, -1
  br i1 %22, label %27, label %23

23:                                               ; preds = %21
  %24 = getelementptr inbounds i8, ptr %0, i64 48
  %25 = tail call i32 @XHash_Delete(ptr noundef nonnull %24, i32 noundef %.pre26) #3
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %._crit_edge, label %29

._crit_edge:                                      ; preds = %23
  %.pre = load i32, ptr %5, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %._crit_edge, %21, %18
  %28 = phi i32 [ %.pre, %._crit_edge ], [ -1, %21 ], [ %.pre26, %18 ]
  tail call void @XEvents_ClearCb(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %28)
  br label %29

29:                                               ; preds = %23, %27, %3, %2
  %.016 = phi i32 [ 10, %2 ], [ 11, %3 ], [ %.0, %27 ], [ %.0, %23 ]
  ret i32 %.016
}

declare i32 @XHash_Delete(ptr noundef, i32 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 = { 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 = { "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, !10, i64 16}
!6 = !{!"XEventData", !7, i64 0, !10, i64 8, !8, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"XEvents", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36, !8, i64 40, !13, i64 48}
!13 = !{!"XHash", !7, i64 0, !7, i64 8, !14, i64 16, !8, i64 24}
!14 = !{!"long", !8, i64 0}
!15 = !{!12, !10, i64 32}
!16 = !{!12, !8, i64 40}


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