; 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_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: nounwind uwtable
define dso_local void @us_internal_loop_unlink(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.us_loop_t, ptr %5, i32 0, i32 0
  %7 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %6, i32 0, i32 3
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr %8, %9
  br i1 %10, label %11, label %30

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.us_socket_context_t, ptr %12, i32 0, i32 8
  %14 = load ptr, ptr %13, align 16, !tbaa !14
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.us_loop_t, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %16, i32 0, i32 3
  store ptr %14, ptr %17, align 8, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.us_loop_t, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %29

23:                                               ; preds = %11
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.us_loop_t, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.us_socket_context_t, ptr %27, i32 0, i32 7
  store ptr null, ptr %28, align 8, !tbaa !16
  br label %29

29:                                               ; preds = %23, %11
  br label %51

30:                                               ; preds = %2
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.us_socket_context_t, ptr %31, i32 0, i32 8
  %33 = load ptr, ptr %32, align 16, !tbaa !14
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.us_socket_context_t, ptr %34, i32 0, i32 7
  %36 = load ptr, ptr %35, align 8, !tbaa !16
  %37 = getelementptr inbounds %struct.us_socket_context_t, ptr %36, i32 0, i32 8
  store ptr %33, ptr %37, align 16, !tbaa !14
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.us_socket_context_t, ptr %38, i32 0, i32 8
  %40 = load ptr, ptr %39, align 16, !tbaa !14
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %50

42:                                               ; preds = %30
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.us_socket_context_t, ptr %43, i32 0, i32 7
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.us_socket_context_t, ptr %46, i32 0, i32 8
  %48 = load ptr, ptr %47, align 16, !tbaa !14
  %49 = getelementptr inbounds %struct.us_socket_context_t, ptr %48, i32 0, i32 7
  store ptr %45, ptr %49, align 8, !tbaa !16
  br label %50

50:                                               ; preds = %42, %30
  br label %51

51:                                               ; preds = %50, %29
  ret void
}

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

!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, !6, i64 24}
!10 = !{!"us_loop_t", !11, i64 0, !12, i64 104, !12, i64 108, !12, i64 112, !12, i64 116, !7, i64 120}
!11 = !{!"us_internal_loop_data_t", !6, i64 0, !6, i64 8, !12, 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, !12, i64 88, !13, i64 96}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!15, !6, i64 48}
!15 = !{!"us_socket_context_t", !6, i64 0, !12, 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}
!16 = !{!15, !6, i64 40}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @us_internal_loop_unlink(ptr nocapture noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, %1
  %6 = getelementptr inbounds i8, ptr %1, i64 48
  %7 = load ptr, ptr %6, align 16, !tbaa !13
  br i1 %5, label %8, label %9

8:                                                ; preds = %2
  store ptr %7, ptr %3, align 8, !tbaa !5
  %.not13 = icmp eq ptr %7, null
  br i1 %.not13, label %14, label %.sink.split

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %1, i64 40
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %11, i64 48
  store ptr %7, ptr %12, align 16, !tbaa !13
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %14, label %.sink.split

.sink.split:                                      ; preds = %9, %8
  %.sink = phi ptr [ null, %8 ], [ %11, %9 ]
  %13 = getelementptr inbounds i8, ptr %7, i64 40
  store ptr %.sink, ptr %13, align 8, !tbaa !15
  br label %14

14:                                               ; preds = %.sink.split, %9, %8
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) 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" }

!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, !8, i64 24}
!6 = !{!"us_loop_t", !7, i64 0, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !9, i64 120}
!7 = !{!"us_internal_loop_data_t", !8, i64 0, !8, i64 8, !11, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !11, i64 88, !12, i64 96}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"long long", !9, i64 0}
!13 = !{!14, !8, i64 48}
!14 = !{!"us_socket_context_t", !8, i64 0, !11, i64 8, !9, i64 12, !9, i64 13, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !8, i64 104, !8, i64 112, !8, i64 120, !8, i64 128}
!15 = !{!14, !8, i64 40}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass