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

; 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_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] }
%struct.us_listen_socket_t = type { %struct.us_socket_t, i32, [12 x i8] }
%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 }

; Function Attrs: nounwind uwtable
define dso_local void @us_internal_socket_context_unlink_listen_socket(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 %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.us_socket_context_t, ptr %6, i32 0, i32 6
  %8 = load ptr, ptr %7, align 16, !tbaa !9
  %9 = icmp eq ptr %5, %8
  br i1 %9, label %10, label %17

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.us_listen_socket_t, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.us_socket_t, ptr %12, i32 0, i32 6
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.us_socket_context_t, ptr %15, i32 0, i32 6
  store ptr %14, ptr %16, align 16, !tbaa !9
  br label %17

17:                                               ; preds = %10, %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.us_listen_socket_t, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds %struct.us_socket_t, ptr %19, i32 0, i32 5
  %21 = load ptr, ptr %20, align 16, !tbaa !18
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.us_listen_socket_t, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds %struct.us_socket_t, ptr %23, i32 0, i32 6
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = icmp eq ptr %21, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %17
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.us_socket_context_t, ptr %28, i32 0, i32 5
  store ptr null, ptr %29, align 8, !tbaa !19
  br label %70

30:                                               ; preds = %17
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.us_listen_socket_t, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds %struct.us_socket_t, ptr %32, i32 0, i32 5
  %34 = load ptr, ptr %33, align 16, !tbaa !18
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %46

36:                                               ; preds = %30
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.us_listen_socket_t, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %struct.us_socket_t, ptr %38, i32 0, i32 6
  %40 = load ptr, ptr %39, align 8, !tbaa !12
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.us_listen_socket_t, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %struct.us_socket_t, ptr %42, i32 0, i32 5
  %44 = load ptr, ptr %43, align 16, !tbaa !18
  %45 = getelementptr inbounds %struct.us_socket_t, ptr %44, i32 0, i32 6
  store ptr %40, ptr %45, align 8, !tbaa !20
  br label %53

46:                                               ; preds = %30
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.us_listen_socket_t, ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds %struct.us_socket_t, ptr %48, i32 0, i32 6
  %50 = load ptr, ptr %49, align 8, !tbaa !12
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.us_socket_context_t, ptr %51, i32 0, i32 5
  store ptr %50, ptr %52, align 8, !tbaa !19
  br label %53

53:                                               ; preds = %46, %36
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.us_listen_socket_t, ptr %54, i32 0, i32 0
  %56 = getelementptr inbounds %struct.us_socket_t, ptr %55, i32 0, i32 6
  %57 = load ptr, ptr %56, align 8, !tbaa !12
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %69

59:                                               ; preds = %53
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.us_listen_socket_t, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.us_socket_t, ptr %61, i32 0, i32 5
  %63 = load ptr, ptr %62, align 16, !tbaa !18
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.us_listen_socket_t, ptr %64, i32 0, i32 0
  %66 = getelementptr inbounds %struct.us_socket_t, ptr %65, i32 0, i32 6
  %67 = load ptr, ptr %66, align 8, !tbaa !12
  %68 = getelementptr inbounds %struct.us_socket_t, ptr %67, i32 0, i32 5
  store ptr %63, ptr %68, align 16, !tbaa !21
  br label %69

69:                                               ; preds = %59, %53
  br label %70

70:                                               ; preds = %69, %27
  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 32}
!10 = !{!"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}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 40}
!13 = !{!"us_listen_socket_t", !14, i64 0, !11, i64 48}
!14 = !{!"us_socket_t", !15, i64 0, !7, i64 16, !7, i64 17, !17, i64 18, !6, i64 24, !6, i64 32, !6, i64 40}
!15 = !{!"us_poll_t", !16, i64 0}
!16 = !{!"", !11, i64 0, !11, i64 3}
!17 = !{!"short", !7, i64 0}
!18 = !{!13, !6, i64 32}
!19 = !{!10, !6, i64 24}
!20 = !{!14, !6, i64 40}
!21 = !{!14, !6, i64 32}


; 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_socket_context_unlink_listen_socket(ptr nocapture noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load ptr, ptr %3, align 16, !tbaa !5
  %5 = icmp eq ptr %4, %1
  %6 = getelementptr inbounds i8, ptr %1, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  br i1 %5, label %8, label %._crit_edge

8:                                                ; preds = %2
  store ptr %7, ptr %3, align 16, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %2, %8
  %9 = getelementptr inbounds i8, ptr %1, i64 32
  %10 = load ptr, ptr %9, align 16, !tbaa !17
  %11 = getelementptr inbounds i8, ptr %1, i64 40
  %12 = icmp eq ptr %10, %7
  br i1 %12, label %13, label %15

13:                                               ; preds = %._crit_edge
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr null, ptr %14, align 8, !tbaa !18
  br label %24

15:                                               ; preds = %._crit_edge
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %18, label %16

16:                                               ; preds = %15
  %17 = getelementptr inbounds i8, ptr %10, i64 40
  store ptr %7, ptr %17, align 8, !tbaa !19
  %.pre19 = load ptr, ptr %11, align 8, !tbaa !11
  br label %20

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %7, ptr %19, align 8, !tbaa !18
  br label %20

20:                                               ; preds = %18, %16
  %21 = phi ptr [ %7, %18 ], [ %.pre19, %16 ]
  %.not18 = icmp eq ptr %21, null
  br i1 %.not18, label %24, label %22

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %21, i64 32
  store ptr %10, ptr %23, align 16, !tbaa !20
  br label %24

24:                                               ; preds = %20, %22, %13
  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, !7, i64 32}
!6 = !{!"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}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 40}
!12 = !{!"us_listen_socket_t", !13, i64 0, !10, i64 48}
!13 = !{!"us_socket_t", !14, i64 0, !8, i64 16, !8, i64 17, !16, i64 18, !7, i64 24, !7, i64 32, !7, i64 40}
!14 = !{!"us_poll_t", !15, i64 0}
!15 = !{!"", !10, i64 0, !10, i64 3}
!16 = !{!"short", !8, i64 0}
!17 = !{!12, !7, i64 32}
!18 = !{!6, !7, i64 24}
!19 = !{!13, !7, i64 40}
!20 = !{!13, !7, i64 32}


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