; 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_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_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 %16

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

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

24:                                               ; preds = %16
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.us_socket_context_t, ptr %25, i32 0, i32 4
  store ptr null, ptr %26, align 16, !tbaa !18
  br label %60

27:                                               ; preds = %16
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.us_socket_t, ptr %28, i32 0, i32 5
  %30 = load ptr, ptr %29, align 16, !tbaa !17
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %40

32:                                               ; preds = %27
  %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 !12
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.us_socket_t, ptr %36, i32 0, i32 5
  %38 = load ptr, ptr %37, align 16, !tbaa !17
  %39 = getelementptr inbounds %struct.us_socket_t, ptr %38, i32 0, i32 6
  store ptr %35, ptr %39, align 8, !tbaa !12
  br label %46

40:                                               ; preds = %27
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.us_socket_t, ptr %41, i32 0, i32 6
  %43 = load ptr, ptr %42, align 8, !tbaa !12
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.us_socket_context_t, ptr %44, i32 0, i32 4
  store ptr %43, ptr %45, align 16, !tbaa !18
  br label %46

46:                                               ; preds = %40, %32
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.us_socket_t, ptr %47, i32 0, i32 6
  %49 = load ptr, ptr %48, align 8, !tbaa !12
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %59

51:                                               ; preds = %46
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.us_socket_t, ptr %52, i32 0, i32 5
  %54 = load ptr, ptr %53, align 16, !tbaa !17
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.us_socket_t, ptr %55, i32 0, i32 6
  %57 = load ptr, ptr %56, align 8, !tbaa !12
  %58 = getelementptr inbounds %struct.us_socket_t, ptr %57, i32 0, i32 5
  store ptr %54, ptr %58, align 16, !tbaa !17
  br label %59

59:                                               ; preds = %51, %46
  br label %60

60:                                               ; preds = %59, %24
  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_socket_t", !14, i64 0, !7, i64 16, !7, i64 17, !16, i64 18, !6, i64 24, !6, i64 32, !6, i64 40}
!14 = !{!"us_poll_t", !15, i64 0}
!15 = !{!"", !11, i64 0, !11, i64 3}
!16 = !{!"short", !7, i64 0}
!17 = !{!13, !6, i64 32}
!18 = !{!10, !6, i64 16}


; 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_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 !16
  %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 16
  store ptr null, ptr %14, align 16, !tbaa !17
  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 !11
  %.pre19 = load ptr, ptr %11, align 8, !tbaa !11
  br label %20

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %7, ptr %19, align 16, !tbaa !17
  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 !16
  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_socket_t", !13, i64 0, !8, i64 16, !8, i64 17, !15, i64 18, !7, i64 24, !7, i64 32, !7, i64 40}
!13 = !{!"us_poll_t", !14, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 3}
!15 = !{!"short", !8, i64 0}
!16 = !{!12, !7, i64 32}
!17 = !{!6, !7, i64 16}


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