; 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.epoll_event = type <{ i32, %union.epoll_data }>
%union.epoll_data = type { ptr }
%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: 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_Add(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.epoll_event, align 1
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %12, %3
  store i32 10, ptr %4, align 4
  br label %72

16:                                               ; preds = %12
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.XEventData, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp ne i32 %19, -1
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 10, ptr %4, align 4
  br label %72

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 12, ptr %8) #4
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.epoll_event, ptr %8, i32 0, i32 1
  store ptr %23, ptr %24, align 1, !tbaa !13
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = getelementptr inbounds %struct.epoll_event, ptr %8, i32 0, i32 0
  store i32 %25, ptr %26, align 1, !tbaa !14
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.XEvents, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !16
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.XEventData, ptr %30, i32 0, i32 3
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %33 = call i32 @epoll_ctl(i32 noundef %29, i32 noundef 1, i32 noundef %32, ptr noundef %8) #4
  %34 = icmp slt i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %22
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %71

36:                                               ; preds = %22
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.XEvents, ptr %37, i32 0, i32 4
  %39 = load i32, ptr %38, align 8, !tbaa !20
  %40 = add i32 %39, 1
  store i32 %40, ptr %38, align 8, !tbaa !20
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.XEvents, ptr %41, i32 0, i32 6
  %43 = load i8, ptr %42, align 8, !tbaa !21
  %44 = zext i8 %43 to i32
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %67

46:                                               ; preds = %36
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.XEvents, ptr %47, i32 0, i32 7
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.XEventData, ptr %50, i32 0, i32 3
  %52 = load i32, ptr %51, align 8, !tbaa !11
  %53 = call i32 @XHash_Insert(ptr noundef %48, ptr noundef %49, i64 noundef 0, i32 noundef %52)
  %54 = icmp slt i32 %53, 0
  br i1 %54, label %55, label %67

55:                                               ; preds = %46
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.XEvents, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 8, !tbaa !16
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.XEventData, ptr %59, i32 0, i32 3
  %61 = load i32, ptr %60, align 8, !tbaa !11
  %62 = call i32 @epoll_ctl(i32 noundef %58, i32 noundef 2, i32 noundef %61, ptr noundef null) #4
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.XEvents, ptr %63, i32 0, i32 4
  %65 = load i32, ptr %64, align 8, !tbaa !20
  %66 = add i32 %65, -1
  store i32 %66, ptr %64, align 8, !tbaa !20
  store i32 9, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %71

67:                                               ; preds = %46, %36
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.XEventData, ptr %69, i32 0, i32 1
  store i32 %68, ptr %70, align 8, !tbaa !22
  store i32 11, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %71

71:                                               ; preds = %67, %55, %35
  call void @llvm.lifetime.end.p0(i64 12, ptr %8) #4
  br label %72

72:                                               ; preds = %71, %21, %15
  %73 = load i32, ptr %4, align 4
  ret i32 %73
}

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

declare i32 @XHash_Insert(ptr noundef, ptr noundef, i64 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 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"epoll_event", !10, i64 0, !7, i64 4}
!16 = !{!17, !10, i64 8}
!17 = !{!"XEvents", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !7, i64 40, !18, i64 48}
!18 = !{!"XHash", !6, i64 0, !6, i64 8, !19, i64 16, !7, i64 24}
!19 = !{!"long", !7, i64 0}
!20 = !{!17, !10, i64 32}
!21 = !{!17, !7, i64 40}
!22 = !{!12, !10, i64 8}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; 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 range(i32 1, 12) i32 @XEvents_Add(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.epoll_event, align 4
  %5 = icmp ne ptr %0, null
  %6 = icmp ne ptr %1, null
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %7, label %36

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %.not = icmp eq i32 %9, -1
  br i1 %.not, label %36, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #4
  %11 = getelementptr inbounds i8, ptr %4, i64 4
  store ptr %1, ptr %11, align 4, !tbaa !11
  store i32 %2, ptr %4, align 4, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = call i32 @epoll_ctl(i32 noundef %13, i32 noundef 1, i32 noundef %9, ptr noundef nonnull %4) #4
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %35, label %16

16:                                               ; preds = %10
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  %18 = load i32, ptr %17, align 8, !tbaa !18
  %19 = add i32 %18, 1
  store i32 %19, ptr %17, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %0, i64 40
  %21 = load i8, ptr %20, align 8, !tbaa !19
  %.not20 = icmp eq i8 %21, 0
  br i1 %.not20, label %33, label %22

22:                                               ; preds = %16
  %23 = getelementptr inbounds i8, ptr %0, i64 48
  %24 = load i32, ptr %8, align 8, !tbaa !5
  %25 = call i32 @XHash_Insert(ptr noundef nonnull %23, ptr noundef nonnull %1, i64 noundef 0, i32 noundef %24) #4
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %27, label %33

27:                                               ; preds = %22
  %28 = load i32, ptr %12, align 8, !tbaa !14
  %29 = load i32, ptr %8, align 8, !tbaa !5
  %30 = call i32 @epoll_ctl(i32 noundef %28, i32 noundef 2, i32 noundef %29, ptr noundef null) #4
  %31 = load i32, ptr %17, align 8, !tbaa !18
  %32 = add i32 %31, -1
  store i32 %32, ptr %17, align 8, !tbaa !18
  br label %35

33:                                               ; preds = %22, %16
  %34 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %2, ptr %34, align 8, !tbaa !20
  br label %35

35:                                               ; preds = %10, %33, %27
  %.0 = phi i32 [ 9, %27 ], [ 11, %33 ], [ 1, %10 ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #4
  br label %36

36:                                               ; preds = %7, %3, %35
  %.1 = phi i32 [ %.0, %35 ], [ 10, %3 ], [ 10, %7 ]
  ret i32 %.1
}

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

declare i32 @XHash_Insert(ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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, !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 = !{!8, !8, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"epoll_event", !10, i64 0, !8, i64 4}
!14 = !{!15, !10, i64 8}
!15 = !{!"XEvents", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36, !8, i64 40, !16, i64 48}
!16 = !{!"XHash", !7, i64 0, !7, i64 8, !17, i64 16, !8, i64 24}
!17 = !{!"long", !8, i64 0}
!18 = !{!15, !10, i64 32}
!19 = !{!15, !8, i64 40}
!20 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass