; LLVM IR from uNetworking/uSockets :: src (loop)

; 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.us_loop_t = type { %struct.us_internal_loop_data_t, i32, i32, i32, i32, [1024 x %struct.epoll_event], [8 x i8] }
%struct.us_internal_loop_data_t = type { ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i64 }
%struct.epoll_event = type <{ i32, %union.epoll_data }>
%union.epoll_data = type { ptr }
%struct.us_socket_t = type { %struct.us_poll_t, i8, i8, i16, ptr, ptr, ptr }
%struct.us_poll_t = type { %struct.anon, [12 x i8] }
%struct.anon = type { i32 }
%struct.us_socket_context_t = type { ptr, i32, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, [8 x i8] }

; 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 void @us_internal_handle_low_priority_sockets(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.us_loop_t, ptr %5, i32 0, i32 0
  store ptr %6, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %7, i32 0, i32 11
  store i32 5, ptr %8, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %9, i32 0, i32 10
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  store ptr %11, ptr %4, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %56, %1
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %20

15:                                               ; preds = %12
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %16, i32 0, i32 11
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = icmp sgt i32 %18, 0
  br label %20

20:                                               ; preds = %15, %12
  %21 = phi i1 [ false, %12 ], [ %19, %15 ]
  br i1 %21, label %22, label %64

22:                                               ; preds = %20
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.us_socket_t, ptr %23, i32 0, i32 6
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %26, i32 0, i32 10
  store ptr %25, ptr %27, align 8, !tbaa !13
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.us_socket_t, ptr %28, i32 0, i32 6
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %37

32:                                               ; preds = %22
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.us_socket_t, ptr %33, i32 0, i32 6
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = getelementptr inbounds %struct.us_socket_t, ptr %35, i32 0, i32 5
  store ptr null, ptr %36, align 16, !tbaa !19
  br label %37

37:                                               ; preds = %32, %22
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.us_socket_t, ptr %38, i32 0, i32 6
  store ptr null, ptr %39, align 8, !tbaa !14
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.us_socket_t, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !20
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  call void @us_internal_socket_context_link_socket(ptr noundef %42, ptr noundef %43)
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.us_socket_t, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = call ptr @us_socket_context(i32 noundef 0, ptr noundef %46)
  %48 = getelementptr inbounds %struct.us_socket_context_t, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 16, !tbaa !21
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.us_socket_t, ptr %50, i32 0, i32 0
  %52 = call i32 @us_poll_events(ptr noundef %51)
  %53 = or i32 %52, 1
  call void @us_poll_change(ptr noundef %45, ptr noundef %49, i32 noundef %53)
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.us_socket_t, ptr %54, i32 0, i32 3
  store i16 2, ptr %55, align 2, !tbaa !23
  br label %56

56:                                               ; preds = %37
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %57, i32 0, i32 10
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  store ptr %59, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %60, i32 0, i32 11
  %62 = load i32, ptr %61, align 8, !tbaa !9
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr %61, align 8, !tbaa !9
  br label %12, !llvm.loop !24

64:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare void @us_internal_socket_context_link_socket(ptr noundef, ptr noundef) #2

declare void @us_poll_change(ptr noundef, ptr noundef, i32 noundef) #2

declare ptr @us_socket_context(i32 noundef, ptr noundef) #2

declare i32 @us_poll_events(ptr noundef) #2

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 = { "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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 88}
!10 = !{!"us_internal_loop_data_t", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !11, i64 88, !12, i64 96}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!10, !6, i64 80}
!14 = !{!15, !6, i64 40}
!15 = !{!"us_socket_t", !16, i64 0, !7, i64 16, !7, i64 17, !18, i64 18, !6, i64 24, !6, i64 32, !6, i64 40}
!16 = !{!"us_poll_t", !17, i64 0}
!17 = !{!"", !11, i64 0, !11, i64 3}
!18 = !{!"short", !7, i64 0}
!19 = !{!15, !6, i64 32}
!20 = !{!15, !6, i64 24}
!21 = !{!22, !6, i64 0}
!22 = !{!"us_socket_context_t", !6, i64 0, !11, i64 8, !7, i64 12, !7, i64 13, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!23 = !{!15, !18, i64 18}
!24 = distinct !{!24, !25}
!25 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local void @us_internal_handle_low_priority_sockets(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 88
  store i32 5, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 80
  %4 = load ptr, ptr %3, align 8, !tbaa !12
  %.not20 = icmp eq ptr %4, null
  br i1 %.not20, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %12
  %5 = phi i32 [ %22, %12 ], [ 5, %1 ]
  %.021 = phi ptr [ %20, %12 ], [ %4, %1 ]
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %7, label %.critedge

7:                                                ; preds = %.lr.ph
  %8 = getelementptr inbounds i8, ptr %.021, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  store ptr %9, ptr %3, align 8, !tbaa !12
  %.not19 = icmp eq ptr %9, null
  br i1 %.not19, label %12, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %9, i64 32
  store ptr null, ptr %11, align 16, !tbaa !18
  br label %12

12:                                               ; preds = %10, %7
  store ptr null, ptr %8, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %.021, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !19
  tail call void @us_internal_socket_context_link_socket(ptr noundef %14, ptr noundef nonnull %.021) #2
  %15 = tail call ptr @us_socket_context(i32 noundef 0, ptr noundef nonnull %.021) #2
  %16 = load ptr, ptr %15, align 16, !tbaa !20
  %17 = tail call i32 @us_poll_events(ptr noundef nonnull %.021) #2
  %18 = or i32 %17, 1
  tail call void @us_poll_change(ptr noundef nonnull %.021, ptr noundef %16, i32 noundef %18) #2
  %19 = getelementptr inbounds i8, ptr %.021, i64 18
  store i16 2, ptr %19, align 2, !tbaa !22
  %20 = load ptr, ptr %3, align 8, !tbaa !12
  %21 = load i32, ptr %2, align 8, !tbaa !5
  %22 = add nsw i32 %21, -1
  store i32 %22, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %20, null
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !23

.critedge:                                        ; preds = %.lr.ph, %12, %1
  ret void
}

declare void @us_internal_socket_context_link_socket(ptr noundef, ptr noundef) local_unnamed_addr #1

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

declare ptr @us_socket_context(i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @us_poll_events(ptr noundef) local_unnamed_addr #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 = { "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 }

!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 88}
!6 = !{!"us_internal_loop_data_t", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !10, i64 88, !11, i64 96}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!6, !7, i64 80}
!13 = !{!14, !7, i64 40}
!14 = !{!"us_socket_t", !15, i64 0, !8, i64 16, !8, i64 17, !17, i64 18, !7, i64 24, !7, i64 32, !7, i64 40}
!15 = !{!"us_poll_t", !16, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 3}
!17 = !{!"short", !8, i64 0}
!18 = !{!14, !7, i64 32}
!19 = !{!14, !7, i64 24}
!20 = !{!21, !7, i64 0}
!21 = !{!"us_socket_context_t", !7, i64 0, !10, i64 8, !8, i64 12, !8, i64 13, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128}
!22 = !{!14, !17, i64 18}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass