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

@g_count = external hidden global i32, align 4
@g_cbs = external hidden global [16 x ptr], align 16
@g_fds = external hidden global [16 x %struct.pollfd], align 16
@.str.2 = external hidden unnamed_addr constant [38 x i8], align 1
@g_entry_removed = external hidden global i8, align 1
@.str.3 = external hidden unnamed_addr constant [39 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #1

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

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

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !11
  br label %11

11:                                               ; preds = %34, %10
  %12 = load i64, ptr %5, align 8, !tbaa !11
  %13 = load i32, ptr @g_count, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = icmp ult i64 %12, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  store i32 2, ptr %6, align 4
  br label %37

17:                                               ; preds = %11
  %18 = load i64, ptr %5, align 8, !tbaa !11
  %19 = getelementptr inbounds [16 x ptr], ptr @g_cbs, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = icmp eq ptr %20, %21
  br i1 %22, label %23, label %33

23:                                               ; preds = %17
  %24 = load i64, ptr %5, align 8, !tbaa !11
  %25 = getelementptr inbounds [16 x %struct.pollfd], ptr @g_fds, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.pollfd, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = icmp eq i32 %27, %28
  br i1 %29, label %30, label %33

30:                                               ; preds = %23
  %31 = load i64, ptr %5, align 8, !tbaa !11
  %32 = getelementptr inbounds [16 x ptr], ptr @g_cbs, i64 0, i64 %31
  store ptr null, ptr %32, align 8, !tbaa !9
  store i8 1, ptr @g_entry_removed, align 1, !tbaa !16
  store i32 1, ptr %6, align 4
  br label %37

33:                                               ; preds = %23, %17
  br label %34

34:                                               ; preds = %33
  %35 = load i64, ptr %5, align 8, !tbaa !11
  %36 = add i64 %35, 1
  store i64 %36, ptr %5, align 8, !tbaa !11
  br label %11, !llvm.loop !18

37:                                               ; preds = %30, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  %38 = load i32, ptr %6, align 4
  switch i32 %38, label %41 [
    i32 2, label %39
    i32 1, label %40
  ]

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

40:                                               ; preds = %37
  ret void

41:                                               ; preds = %37
  unreachable
}

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

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

attributes #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 = { 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { noreturn nounwind }
attributes #5 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"pollfd", !6, i64 0, !15, i64 4, !15, i64 6}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"_Bool", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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.pollfd = type { i32, i16, i16 }

@g_count = external hidden local_unnamed_addr global i32, align 4
@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
@.str.2 = external hidden unnamed_addr constant [38 x i8], align 1
@g_entry_removed = external hidden local_unnamed_addr global i8, align 1
@.str.3 = external hidden unnamed_addr constant [39 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @net_remove_handler(i32 noundef %0, ptr noundef readnone %1) local_unnamed_addr #2 {
  %3 = icmp eq ptr %1, null
  br i1 %3, label %6, label %.preheader

.preheader:                                       ; preds = %2
  %4 = load i32, ptr @g_count, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

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

.lr.ph:                                           ; preds = %.preheader, %14
  %.0813 = phi i64 [ %15, %14 ], [ 0, %.preheader ]
  %7 = getelementptr inbounds [16 x ptr], ptr @g_cbs, i64 0, i64 %.0813
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp eq ptr %8, %1
  br i1 %9, label %10, label %14

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds [16 x %struct.pollfd], ptr @g_fds, i64 0, i64 %.0813
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp eq i32 %12, %0
  br i1 %13, label %16, label %14

14:                                               ; preds = %.lr.ph, %10
  %15 = add nuw i64 %.0813, 1
  %exitcond.not = icmp eq i64 %15, %5
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

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

16:                                               ; preds = %10
  %17 = getelementptr inbounds [16 x ptr], ptr @g_cbs, i64 0, i64 %.0813
  store ptr null, ptr %17, align 8, !tbaa !9
  store i8 1, ptr @g_entry_removed, align 1, !tbaa !16
  ret void
}

attributes #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 = { 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 #2 = { 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 #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 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !17, i64 0}
!17 = !{!"_Bool", !7, i64 0}


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