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

; Function Attrs: nounwind uwtable
define dso_local i32 @XEvents_Create(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, i8 noundef zeroext %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i8 %4, ptr %11, align 1, !tbaa !11
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %5
  store i32 10, ptr %6, align 4
  br label %115

17:                                               ; preds = %5
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 3, ptr %6, align 4
  br label %115

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %22 = call i64 @sysconf(i32 noundef 4) #5
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr %12, align 4, !tbaa !9
  %24 = load i32, ptr %12, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %41

26:                                               ; preds = %21
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %41

29:                                               ; preds = %26
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = load i32, ptr %12, align 4, !tbaa !9
  %32 = icmp ugt i32 %30, %31
  br i1 %32, label %33, label %35

33:                                               ; preds = %29
  %34 = load i32, ptr %12, align 4, !tbaa !9
  br label %37

35:                                               ; preds = %29
  %36 = load i32, ptr %8, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %35, %33
  %38 = phi i32 [ %34, %33 ], [ %36, %35 ]
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.XEvents, ptr %39, i32 0, i32 5
  store i32 %38, ptr %40, align 4, !tbaa !12
  br label %58

41:                                               ; preds = %26, %21
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %41
  %45 = load i32, ptr %12, align 4, !tbaa !9
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.XEvents, ptr %46, i32 0, i32 5
  store i32 %45, ptr %47, align 4, !tbaa !12
  br label %57

48:                                               ; preds = %41
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %55

51:                                               ; preds = %48
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.XEvents, ptr %53, i32 0, i32 5
  store i32 %52, ptr %54, align 4, !tbaa !12
  br label %56

55:                                               ; preds = %48
  store i32 4, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %114

56:                                               ; preds = %51
  br label %57

57:                                               ; preds = %56, %44
  br label %58

58:                                               ; preds = %57, %37
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.XEvents, ptr %60, i32 0, i32 2
  store ptr %59, ptr %61, align 8, !tbaa !16
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.XEvents, ptr %63, i32 0, i32 3
  store ptr %62, ptr %64, align 8, !tbaa !17
  %65 = load i8, ptr %11, align 1, !tbaa !11
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.XEvents, ptr %66, i32 0, i32 6
  store i8 %65, ptr %67, align 8, !tbaa !18
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.XEvents, ptr %68, i32 0, i32 4
  store i32 0, ptr %69, align 8, !tbaa !19
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.XEvents, ptr %70, i32 0, i32 6
  %72 = load i8, ptr %71, align 8, !tbaa !18
  %73 = zext i8 %72 to i32
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %84

75:                                               ; preds = %58
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.XEvents, ptr %76, i32 0, i32 7
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = call i32 @XHash_Init(ptr noundef %77, ptr noundef @XEvents_ClearCb, ptr noundef %78)
  %80 = icmp slt i32 %79, 0
  br i1 %80, label %81, label %84

81:                                               ; preds = %75
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.XEvents, ptr %82, i32 0, i32 6
  store i8 0, ptr %83, align 8, !tbaa !18
  store i32 7, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %114

84:                                               ; preds = %75, %58
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.XEvents, ptr %85, i32 0, i32 5
  %87 = load i32, ptr %86, align 4, !tbaa !12
  %88 = zext i32 %87 to i64
  %89 = call noalias ptr @calloc(i64 noundef %88, i64 noundef 12) #6
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.XEvents, ptr %90, i32 0, i32 0
  store ptr %89, ptr %91, align 8, !tbaa !20
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.XEvents, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !20
  %95 = icmp eq ptr %94, null
  br i1 %95, label %96, label %98

96:                                               ; preds = %84
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  call void @XEvents_DestroyMap(ptr noundef %97)
  store i32 7, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %114

98:                                               ; preds = %84
  %99 = call i32 @epoll_create1(i32 noundef 0) #5
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.XEvents, ptr %100, i32 0, i32 1
  store i32 %99, ptr %101, align 8, !tbaa !21
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.XEvents, ptr %102, i32 0, i32 1
  %104 = load i32, ptr %103, align 8, !tbaa !21
  %105 = icmp slt i32 %104, 0
  br i1 %105, label %106, label %113

106:                                              ; preds = %98
  %107 = load ptr, ptr %7, align 8, !tbaa !5
  call void @XEvents_DestroyMap(ptr noundef %107)
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.XEvents, ptr %108, i32 0, i32 0
  %110 = load ptr, ptr %109, align 8, !tbaa !20
  call void @free(ptr noundef %110) #5
  %111 = load ptr, ptr %7, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.XEvents, ptr %111, i32 0, i32 0
  store ptr null, ptr %112, align 8, !tbaa !20
  store i32 8, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %114

113:                                              ; preds = %98
  store i32 11, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %114

114:                                              ; preds = %113, %106, %96, %81, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %115

115:                                              ; preds = %114, %20, %16
  %116 = load i32, ptr %6, align 4
  ret i32 %116
}

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

; Function Attrs: nounwind
declare i64 @sysconf(i32 noundef) #2

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

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #4

; Function Attrs: nounwind uwtable
declare hidden void @XEvents_DestroyMap(ptr noundef) #0

; Function Attrs: nounwind
declare i32 @epoll_create1(i32 noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

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 = { "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 allocsize(0,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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0,1) }

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 3, 12) i32 @XEvents_Create(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, i8 noundef zeroext %4) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %39, label %6

6:                                                ; preds = %5
  %.not42 = icmp eq ptr %3, null
  br i1 %.not42, label %39, label %7

7:                                                ; preds = %6
  %8 = tail call i64 @sysconf(i32 noundef 4) #6
  %9 = trunc i64 %8 to i32
  %10 = icmp ne i32 %9, 0
  %11 = icmp ne i32 %1, 0
  %or.cond = and i1 %11, %10
  br i1 %or.cond, label %12, label %14

12:                                               ; preds = %7
  %13 = tail call i32 @llvm.umin.i32(i32 %9, i32 %1)
  br label %16

14:                                               ; preds = %7
  %15 = or i32 %9, %1
  %brmerge.not = icmp eq i32 %15, 0
  %.mux = select i1 %10, i32 %9, i32 %1
  br i1 %brmerge.not, label %39, label %16

16:                                               ; preds = %14, %12
  %.sink = phi i32 [ %13, %12 ], [ %.mux, %14 ]
  %17 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 %.sink, ptr %17, align 4, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %3, ptr %18, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %2, ptr %19, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %0, i64 40
  store i8 %4, ptr %20, align 8, !tbaa !15
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 0, ptr %21, align 8, !tbaa !16
  %.not43 = icmp eq i8 %4, 0
  br i1 %.not43, label %27, label %22

22:                                               ; preds = %16
  %23 = getelementptr inbounds i8, ptr %0, i64 48
  %24 = tail call i32 @XHash_Init(ptr noundef nonnull %23, ptr noundef nonnull @XEvents_ClearCb, ptr noundef nonnull %0) #6
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %26, label %._crit_edge

._crit_edge:                                      ; preds = %22
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 36
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !5
  br label %27

26:                                               ; preds = %22
  store i8 0, ptr %20, align 8, !tbaa !15
  br label %39

27:                                               ; preds = %._crit_edge, %16
  %28 = phi i32 [ %.pre, %._crit_edge ], [ %.sink, %16 ]
  %29 = zext i32 %28 to i64
  %30 = tail call noalias ptr @calloc(i64 noundef %29, i64 noundef 12) #7
  store ptr %30, ptr %0, align 8, !tbaa !17
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  tail call void @XEvents_DestroyMap(ptr noundef nonnull %0)
  br label %39

33:                                               ; preds = %27
  %34 = tail call i32 @epoll_create1(i32 noundef 0) #6
  %35 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %34, ptr %35, align 8, !tbaa !18
  %36 = icmp slt i32 %34, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %33
  tail call void @XEvents_DestroyMap(ptr noundef nonnull %0)
  %38 = load ptr, ptr %0, align 8, !tbaa !17
  tail call void @free(ptr noundef %38) #6
  store ptr null, ptr %0, align 8, !tbaa !17
  br label %39

39:                                               ; preds = %14, %26, %32, %37, %33, %6, %5
  %.1 = phi i32 [ 10, %5 ], [ 3, %6 ], [ 7, %26 ], [ 7, %32 ], [ 8, %37 ], [ 11, %33 ], [ 4, %14 ]
  ret i32 %.1
}

; Function Attrs: nounwind
declare i64 @sysconf(i32 noundef) local_unnamed_addr #1

declare i32 @XHash_Init(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind
declare i32 @epoll_create1(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #5

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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }

!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 36}
!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 16}
!14 = !{!6, !7, i64 24}
!15 = !{!6, !8, i64 40}
!16 = !{!6, !10, i64 32}
!17 = !{!6, !7, i64 0}
!18 = !{!6, !10, i64 8}


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