; LLVM IR from mwarning/KadNode :: src (net)

; 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.pollfd = type { i32, i16, i16 }

@.str = external hidden unnamed_addr constant [36 x i8], align 1
@g_count = external hidden global i32, align 4
@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1
@g_cbs = external hidden global [16 x ptr], align 16
@g_fds = external hidden global [16 x %struct.pollfd], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @net_set_nonblocking(i32 noundef) #0

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

7:                                                ; preds = %2
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef @.str)
  call void @exit(i32 noundef 1) #3
  unreachable

8:                                                ; preds = %2
  %9 = load i32, ptr @g_count, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = icmp eq i64 %10, 16
  br i1 %11, label %12, label %13

12:                                               ; preds = %8
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef @.str.1)
  call void @exit(i32 noundef 1) #3
  unreachable

13:                                               ; preds = %8
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp sge i32 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %13
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = call i32 @net_set_nonblocking(i32 noundef %17)
  br label %19

19:                                               ; preds = %16, %13
  %20 = load ptr, ptr %4, align 8, !tbaa !9
  %21 = load i32, ptr @g_count, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [16 x ptr], ptr @g_cbs, i64 0, i64 %22
  store ptr %20, ptr %23, align 8, !tbaa !9
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = load i32, ptr @g_count, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [16 x %struct.pollfd], ptr @g_fds, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.pollfd, ptr %27, i32 0, i32 0
  store i32 %24, ptr %28, align 8, !tbaa !11
  %29 = load i32, ptr @g_count, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [16 x %struct.pollfd], ptr @g_fds, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.pollfd, ptr %31, i32 0, i32 1
  store i16 1, ptr %32, align 4, !tbaa !14
  %33 = load i32, ptr @g_count, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr @g_count, align 4, !tbaa !5
  ret void
}

declare void @log_print(i32 noundef, ptr noundef, ...) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 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 = { "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 = { noreturn 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 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"pollfd", !6, i64 0, !13, i64 4, !13, i64 6}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 4}


; 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.pollfd = type { i32, i16, i16 }

@.str = external hidden unnamed_addr constant [36 x i8], align 1
@g_count = external hidden local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1
@g_cbs = external hidden local_unnamed_addr global [16 x ptr], align 16
@g_fds = external hidden local_unnamed_addr global [16 x %struct.pollfd], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @net_set_nonblocking(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @net_add_handler(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %1, null
  br i1 %3, label %4, label %5

4:                                                ; preds = %2
  tail call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef nonnull @.str) #3
  tail call void @exit(i32 noundef 1) #4
  unreachable

5:                                                ; preds = %2
  %6 = load i32, ptr @g_count, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 16
  br i1 %7, label %8, label %9

8:                                                ; preds = %5
  tail call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef nonnull @.str.1) #3
  tail call void @exit(i32 noundef 1) #4
  unreachable

9:                                                ; preds = %5
  %10 = icmp sgt i32 %0, -1
  br i1 %10, label %11, label %13

11:                                               ; preds = %9
  %12 = tail call i32 @net_set_nonblocking(i32 noundef %0)
  %.pre = load i32, ptr @g_count, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %11, %9
  %14 = phi i32 [ %.pre, %11 ], [ %6, %9 ]
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [16 x ptr], ptr @g_cbs, i64 0, i64 %15
  store ptr %1, ptr %16, align 8, !tbaa !9
  %17 = getelementptr inbounds [16 x %struct.pollfd], ptr @g_fds, i64 0, i64 %15
  store i32 %0, ptr %17, align 8, !tbaa !11
  %18 = getelementptr inbounds [16 x %struct.pollfd], ptr @g_fds, i64 0, i64 %15, i32 1
  store i16 1, ptr %18, align 4, !tbaa !14
  %19 = add nsw i32 %14, 1
  store i32 %19, ptr @g_count, align 4, !tbaa !5
  ret void
}

declare void @log_print(i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(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 = { "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 = { noreturn 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 }
attributes #4 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"pollfd", !6, i64 0, !13, i64 4, !13, i64 6}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 4}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass