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

; 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_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] }
%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 }

declare i32 @us_poll_fd(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @us_socket_is_closed(i32 noundef, ptr noundef) #1

declare void @us_internal_socket_context_unlink_socket(ptr noundef, ptr noundef) #0

declare void @us_poll_stop(ptr noundef, ptr noundef) #0

declare void @bsd_close_socket(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @us_socket_close(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !9
  %10 = load ptr, ptr %7, align 8, !tbaa !9
  %11 = call i32 @us_socket_is_closed(i32 noundef 0, ptr noundef %10)
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %109, label %13

13:                                               ; preds = %4
  %14 = load ptr, ptr %7, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.us_socket_t, ptr %14, i32 0, i32 3
  %16 = load i16, ptr %15, align 2, !tbaa !11
  %17 = zext i16 %16 to i32
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %63

19:                                               ; preds = %13
  %20 = load ptr, ptr %7, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.us_socket_t, ptr %20, i32 0, i32 5
  %22 = load ptr, ptr %21, align 16, !tbaa !16
  %23 = icmp ne ptr %22, null
  br i1 %23, label %35, label %24

24:                                               ; preds = %19
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.us_socket_t, ptr %25, i32 0, i32 6
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.us_socket_t, ptr %28, i32 0, i32 4
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %31 = getelementptr inbounds %struct.us_socket_context_t, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 16, !tbaa !19
  %33 = getelementptr inbounds %struct.us_loop_t, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %33, i32 0, i32 10
  store ptr %27, ptr %34, align 16, !tbaa !21
  br label %43

35:                                               ; preds = %19
  %36 = load ptr, ptr %7, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.us_socket_t, ptr %36, i32 0, i32 6
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.us_socket_t, ptr %39, i32 0, i32 5
  %41 = load ptr, ptr %40, align 16, !tbaa !16
  %42 = getelementptr inbounds %struct.us_socket_t, ptr %41, i32 0, i32 6
  store ptr %38, ptr %42, align 8, !tbaa !17
  br label %43

43:                                               ; preds = %35, %24
  %44 = load ptr, ptr %7, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.us_socket_t, ptr %44, i32 0, i32 6
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %56

48:                                               ; preds = %43
  %49 = load ptr, ptr %7, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.us_socket_t, ptr %49, i32 0, i32 5
  %51 = load ptr, ptr %50, align 16, !tbaa !16
  %52 = load ptr, ptr %7, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.us_socket_t, ptr %52, i32 0, i32 6
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = getelementptr inbounds %struct.us_socket_t, ptr %54, i32 0, i32 5
  store ptr %51, ptr %55, align 16, !tbaa !16
  br label %56

56:                                               ; preds = %48, %43
  %57 = load ptr, ptr %7, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.us_socket_t, ptr %57, i32 0, i32 5
  store ptr null, ptr %58, align 16, !tbaa !16
  %59 = load ptr, ptr %7, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.us_socket_t, ptr %59, i32 0, i32 6
  store ptr null, ptr %60, align 8, !tbaa !17
  %61 = load ptr, ptr %7, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.us_socket_t, ptr %61, i32 0, i32 3
  store i16 0, ptr %62, align 2, !tbaa !11
  br label %68

63:                                               ; preds = %13
  %64 = load ptr, ptr %7, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.us_socket_t, ptr %64, i32 0, i32 4
  %66 = load ptr, ptr %65, align 8, !tbaa !18
  %67 = load ptr, ptr %7, align 8, !tbaa !9
  call void @us_internal_socket_context_unlink_socket(ptr noundef %66, ptr noundef %67)
  br label %68

68:                                               ; preds = %63, %56
  %69 = load ptr, ptr %7, align 8, !tbaa !9
  %70 = load ptr, ptr %7, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.us_socket_t, ptr %70, i32 0, i32 4
  %72 = load ptr, ptr %71, align 8, !tbaa !18
  %73 = getelementptr inbounds %struct.us_socket_context_t, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 16, !tbaa !19
  call void @us_poll_stop(ptr noundef %69, ptr noundef %74)
  %75 = load ptr, ptr %7, align 8, !tbaa !9
  %76 = call i32 @us_poll_fd(ptr noundef %75)
  call void @bsd_close_socket(i32 noundef %76)
  %77 = load ptr, ptr %7, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.us_socket_t, ptr %77, i32 0, i32 4
  %79 = load ptr, ptr %78, align 8, !tbaa !18
  %80 = getelementptr inbounds %struct.us_socket_context_t, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 16, !tbaa !19
  %82 = getelementptr inbounds %struct.us_loop_t, ptr %81, i32 0, i32 0
  %83 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %82, i32 0, i32 9
  %84 = load ptr, ptr %83, align 8, !tbaa !25
  %85 = load ptr, ptr %7, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.us_socket_t, ptr %85, i32 0, i32 6
  store ptr %84, ptr %86, align 8, !tbaa !17
  %87 = load ptr, ptr %7, align 8, !tbaa !9
  %88 = load ptr, ptr %7, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct.us_socket_t, ptr %88, i32 0, i32 4
  %90 = load ptr, ptr %89, align 8, !tbaa !18
  %91 = getelementptr inbounds %struct.us_socket_context_t, ptr %90, i32 0, i32 0
  %92 = load ptr, ptr %91, align 16, !tbaa !19
  %93 = getelementptr inbounds %struct.us_loop_t, ptr %92, i32 0, i32 0
  %94 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %93, i32 0, i32 9
  store ptr %87, ptr %94, align 8, !tbaa !25
  %95 = load ptr, ptr %7, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.us_socket_t, ptr %95, i32 0, i32 4
  %97 = load ptr, ptr %96, align 8, !tbaa !18
  %98 = load ptr, ptr %7, align 8, !tbaa !9
  %99 = getelementptr inbounds %struct.us_socket_t, ptr %98, i32 0, i32 5
  store ptr %97, ptr %99, align 16, !tbaa !16
  %100 = load ptr, ptr %7, align 8, !tbaa !9
  %101 = getelementptr inbounds %struct.us_socket_t, ptr %100, i32 0, i32 4
  %102 = load ptr, ptr %101, align 8, !tbaa !18
  %103 = getelementptr inbounds %struct.us_socket_context_t, ptr %102, i32 0, i32 13
  %104 = load ptr, ptr %103, align 8, !tbaa !26
  %105 = load ptr, ptr %7, align 8, !tbaa !9
  %106 = load i32, ptr %8, align 4, !tbaa !5
  %107 = load ptr, ptr %9, align 8, !tbaa !9
  %108 = call ptr %104(ptr noundef %105, i32 noundef %106, ptr noundef %107)
  store ptr %108, ptr %5, align 8
  br label %111

109:                                              ; preds = %4
  %110 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %110, ptr %5, align 8
  br label %111

111:                                              ; preds = %109, %68
  %112 = load ptr, ptr %5, align 8
  ret ptr %112
}

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 = { 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 = !{!"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, !15, i64 18}
!12 = !{!"us_socket_t", !13, i64 0, !7, i64 16, !7, i64 17, !15, i64 18, !10, i64 24, !10, i64 32, !10, i64 40}
!13 = !{!"us_poll_t", !14, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 3}
!15 = !{!"short", !7, i64 0}
!16 = !{!12, !10, i64 32}
!17 = !{!12, !10, i64 40}
!18 = !{!12, !10, i64 24}
!19 = !{!20, !10, i64 0}
!20 = !{!"us_socket_context_t", !10, i64 0, !6, i64 8, !7, i64 12, !7, i64 13, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128}
!21 = !{!22, !10, i64 80}
!22 = !{!"us_loop_t", !23, i64 0, !6, i64 104, !6, i64 108, !6, i64 112, !6, i64 116, !7, i64 120}
!23 = !{!"us_internal_loop_data_t", !10, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !6, i64 88, !24, i64 96}
!24 = !{!"long long", !7, i64 0}
!25 = !{!22, !10, i64 72}
!26 = !{!20, !10, i64 88}


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

declare i32 @us_poll_fd(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @us_socket_is_closed(i32 noundef, ptr noundef) local_unnamed_addr #1

declare void @us_internal_socket_context_unlink_socket(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @us_poll_stop(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @bsd_close_socket(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @us_socket_close(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = tail call i32 @us_socket_is_closed(i32 noundef 0, ptr noundef %1)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %43

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %1, i64 18
  %8 = load i16, ptr %7, align 2, !tbaa !5
  %9 = icmp eq i16 %8, 1
  br i1 %9, label %10, label %26

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %1, i64 32
  %12 = load ptr, ptr %11, align 16, !tbaa !14
  %.not31 = icmp eq ptr %12, null
  %13 = getelementptr inbounds i8, ptr %1, i64 40
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  br i1 %.not31, label %15, label %20

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %1, i64 24
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = load ptr, ptr %17, align 16, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %18, i64 80
  store ptr %14, ptr %19, align 16, !tbaa !19
  br label %22

20:                                               ; preds = %10
  %21 = getelementptr inbounds i8, ptr %12, i64 40
  store ptr %14, ptr %21, align 8, !tbaa !15
  br label %22

22:                                               ; preds = %20, %15
  %.not32 = icmp eq ptr %14, null
  br i1 %.not32, label %25, label %23

23:                                               ; preds = %22
  %24 = getelementptr inbounds i8, ptr %14, i64 32
  store ptr %12, ptr %24, align 16, !tbaa !14
  br label %25

25:                                               ; preds = %23, %22
  store i16 0, ptr %7, align 2, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %11, i8 0, i64 16, i1 false)
  br label %29

26:                                               ; preds = %6
  %27 = getelementptr inbounds i8, ptr %1, i64 24
  %28 = load ptr, ptr %27, align 8, !tbaa !16
  tail call void @us_internal_socket_context_unlink_socket(ptr noundef %28, ptr noundef nonnull %1) #3
  br label %29

29:                                               ; preds = %26, %25
  %30 = getelementptr inbounds i8, ptr %1, i64 24
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = load ptr, ptr %31, align 16, !tbaa !17
  tail call void @us_poll_stop(ptr noundef nonnull %1, ptr noundef %32) #3
  %33 = tail call i32 @us_poll_fd(ptr noundef nonnull %1) #3
  tail call void @bsd_close_socket(i32 noundef %33) #3
  %34 = load ptr, ptr %30, align 8, !tbaa !16
  %35 = load ptr, ptr %34, align 16, !tbaa !17
  %36 = getelementptr inbounds i8, ptr %35, i64 72
  %37 = load ptr, ptr %36, align 8, !tbaa !23
  %38 = getelementptr inbounds i8, ptr %1, i64 40
  store ptr %37, ptr %38, align 8, !tbaa !15
  store ptr %1, ptr %36, align 8, !tbaa !23
  %39 = getelementptr inbounds i8, ptr %1, i64 32
  store ptr %34, ptr %39, align 16, !tbaa !14
  %40 = getelementptr inbounds i8, ptr %34, i64 88
  %41 = load ptr, ptr %40, align 8, !tbaa !24
  %42 = tail call ptr %41(ptr noundef nonnull %1, i32 noundef %2, ptr noundef %3) #3
  br label %43

43:                                               ; preds = %4, %29
  %.0 = phi ptr [ %42, %29 ], [ %1, %4 ]
  ret ptr %.0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass