; 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_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_socket_is_closed(i32 noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @us_internal_socket_context_unlink_socket(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @us_internal_socket_context_link_socket(ptr noundef, ptr noundef) #2

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

13:                                               ; preds = %4
  %14 = load ptr, ptr %7, align 8, !tbaa !9
  %15 = load ptr, ptr %8, align 8, !tbaa !9
  %16 = load i32, ptr %9, align 4, !tbaa !5
  %17 = call ptr @us_internal_ssl_socket_context_adopt_socket(ptr noundef %14, ptr noundef %15, i32 noundef %16)
  store ptr %17, ptr %5, align 8
  br label %95

18:                                               ; preds = %4
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = load ptr, ptr %8, align 8, !tbaa !9
  %21 = call i32 @us_socket_is_closed(i32 noundef %19, ptr noundef %20)
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %18
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %24, ptr %5, align 8
  br label %95

25:                                               ; preds = %18
  %26 = load ptr, ptr %8, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.us_socket_t, ptr %26, i32 0, i32 3
  %28 = load i16, ptr %27, align 2, !tbaa !11
  %29 = zext i16 %28 to i32
  %30 = icmp ne i32 %29, 1
  br i1 %30, label %31, label %36

31:                                               ; preds = %25
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.us_socket_t, ptr %32, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  call void @us_internal_socket_context_unlink_socket(ptr noundef %34, ptr noundef %35)
  br label %36

36:                                               ; preds = %31, %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.us_socket_t, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %8, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.us_socket_t, ptr %39, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = getelementptr inbounds %struct.us_socket_context_t, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 16, !tbaa !17
  %44 = load i32, ptr %9, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = add i64 48, %45
  %47 = trunc i64 %46 to i32
  %48 = call ptr @us_poll_resize(ptr noundef %38, ptr noundef %43, i32 noundef %47)
  store ptr %48, ptr %10, align 8, !tbaa !9
  %49 = load ptr, ptr %10, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.us_socket_t, ptr %49, i32 0, i32 1
  store i8 -1, ptr %50, align 16, !tbaa !19
  %51 = load ptr, ptr %10, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.us_socket_t, ptr %51, i32 0, i32 2
  store i8 -1, ptr %52, align 1, !tbaa !20
  %53 = load ptr, ptr %10, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.us_socket_t, ptr %53, i32 0, i32 3
  %55 = load i16, ptr %54, align 2, !tbaa !11
  %56 = zext i16 %55 to i32
  %57 = icmp eq i32 %56, 1
  br i1 %57, label %58, label %90

58:                                               ; preds = %36
  %59 = load ptr, ptr %10, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.us_socket_t, ptr %59, i32 0, i32 5
  %61 = load ptr, ptr %60, align 16, !tbaa !21
  %62 = icmp ne ptr %61, null
  br i1 %62, label %72, label %63

63:                                               ; preds = %58
  %64 = load ptr, ptr %10, align 8, !tbaa !9
  %65 = load ptr, ptr %10, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.us_socket_t, ptr %65, i32 0, i32 4
  %67 = load ptr, ptr %66, align 8, !tbaa !16
  %68 = getelementptr inbounds %struct.us_socket_context_t, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 16, !tbaa !17
  %70 = getelementptr inbounds %struct.us_loop_t, ptr %69, i32 0, i32 0
  %71 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %70, i32 0, i32 10
  store ptr %64, ptr %71, align 16, !tbaa !22
  br label %78

72:                                               ; preds = %58
  %73 = load ptr, ptr %10, align 8, !tbaa !9
  %74 = load ptr, ptr %10, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.us_socket_t, ptr %74, i32 0, i32 5
  %76 = load ptr, ptr %75, align 16, !tbaa !21
  %77 = getelementptr inbounds %struct.us_socket_t, ptr %76, i32 0, i32 6
  store ptr %73, ptr %77, align 8, !tbaa !26
  br label %78

78:                                               ; preds = %72, %63
  %79 = load ptr, ptr %10, align 8, !tbaa !9
  %80 = getelementptr inbounds %struct.us_socket_t, ptr %79, i32 0, i32 6
  %81 = load ptr, ptr %80, align 8, !tbaa !26
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %89

83:                                               ; preds = %78
  %84 = load ptr, ptr %10, align 8, !tbaa !9
  %85 = load ptr, ptr %10, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.us_socket_t, ptr %85, i32 0, i32 6
  %87 = load ptr, ptr %86, align 8, !tbaa !26
  %88 = getelementptr inbounds %struct.us_socket_t, ptr %87, i32 0, i32 5
  store ptr %84, ptr %88, align 16, !tbaa !21
  br label %89

89:                                               ; preds = %83, %78
  br label %93

90:                                               ; preds = %36
  %91 = load ptr, ptr %7, align 8, !tbaa !9
  %92 = load ptr, ptr %10, align 8, !tbaa !9
  call void @us_internal_socket_context_link_socket(ptr noundef %91, ptr noundef %92)
  br label %93

93:                                               ; preds = %90, %89
  %94 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %94, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %95

95:                                               ; preds = %93, %23, %13
  %96 = load ptr, ptr %5, align 8
  ret ptr %96
}

declare ptr @us_internal_ssl_socket_context_adopt_socket(ptr noundef, ptr noundef, i32 noundef) #0

declare ptr @us_poll_resize(ptr noundef, ptr noundef, i32 noundef) #0

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"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 24}
!17 = !{!18, !10, i64 0}
!18 = !{!"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}
!19 = !{!12, !7, i64 16}
!20 = !{!12, !7, i64 17}
!21 = !{!12, !10, i64 32}
!22 = !{!23, !10, i64 80}
!23 = !{!"us_loop_t", !24, i64 0, !6, i64 104, !6, i64 108, !6, i64 112, !6, i64 116, !7, i64 120}
!24 = !{!"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, !25, i64 96}
!25 = !{!"long long", !7, i64 0}
!26 = !{!12, !10, 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"

declare i32 @us_socket_is_closed(i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

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

5:                                                ; preds = %4
  %6 = tail call ptr @us_internal_ssl_socket_context_adopt_socket(ptr noundef %1, ptr noundef %2, i32 noundef %3) #2
  br label %42

7:                                                ; preds = %4
  %8 = tail call i32 @us_socket_is_closed(i32 noundef 0, ptr noundef %2) #2
  %.not30 = icmp eq i32 %8, 0
  br i1 %.not30, label %9, label %42

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %2, i64 18
  %11 = load i16, ptr %10, align 2, !tbaa !5
  %.not31 = icmp eq i16 %11, 1
  br i1 %.not31, label %15, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %2, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  tail call void @us_internal_socket_context_unlink_socket(ptr noundef %14, ptr noundef nonnull %2)
  br label %15

15:                                               ; preds = %12, %9
  %16 = getelementptr inbounds i8, ptr %2, i64 24
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = load ptr, ptr %17, align 16, !tbaa !15
  %19 = add i32 %3, 48
  %20 = tail call ptr @us_poll_resize(ptr noundef nonnull %2, ptr noundef %18, i32 noundef %19) #2
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  store i8 -1, ptr %21, align 16, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %20, i64 17
  store i8 -1, ptr %22, align 1, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %20, i64 18
  %24 = load i16, ptr %23, align 2, !tbaa !5
  %25 = icmp eq i16 %24, 1
  br i1 %25, label %26, label %41

26:                                               ; preds = %15
  %27 = getelementptr inbounds i8, ptr %20, i64 32
  %28 = load ptr, ptr %27, align 16, !tbaa !19
  %.not32 = icmp eq ptr %28, null
  br i1 %.not32, label %29, label %34

29:                                               ; preds = %26
  %30 = getelementptr inbounds i8, ptr %20, i64 24
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = load ptr, ptr %31, align 16, !tbaa !15
  %33 = getelementptr inbounds i8, ptr %32, i64 80
  store ptr %20, ptr %33, align 16, !tbaa !20
  br label %36

34:                                               ; preds = %26
  %35 = getelementptr inbounds i8, ptr %28, i64 40
  store ptr %20, ptr %35, align 8, !tbaa !24
  br label %36

36:                                               ; preds = %34, %29
  %37 = getelementptr inbounds i8, ptr %20, i64 40
  %38 = load ptr, ptr %37, align 8, !tbaa !24
  %.not33 = icmp eq ptr %38, null
  br i1 %.not33, label %42, label %39

39:                                               ; preds = %36
  %40 = getelementptr inbounds i8, ptr %38, i64 32
  store ptr %20, ptr %40, align 16, !tbaa !19
  br label %42

41:                                               ; preds = %15
  tail call void @us_internal_socket_context_link_socket(ptr noundef %1, ptr noundef nonnull %20)
  br label %42

42:                                               ; preds = %41, %39, %36, %7, %5
  %.0 = phi ptr [ %6, %5 ], [ %2, %7 ], [ %20, %36 ], [ %20, %39 ], [ %20, %41 ]
  ret ptr %.0
}

declare ptr @us_internal_ssl_socket_context_adopt_socket(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare ptr @us_poll_resize(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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 = { 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 24}
!15 = !{!16, !13, i64 0}
!16 = !{!"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}
!17 = !{!6, !10, i64 16}
!18 = !{!6, !10, i64 17}
!19 = !{!6, !13, i64 32}
!20 = !{!21, !13, i64 80}
!21 = !{!"us_loop_t", !22, i64 0, !9, i64 104, !9, i64 108, !9, i64 112, !9, i64 116, !10, i64 120}
!22 = !{!"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, !23, i64 96}
!23 = !{!"long long", !10, i64 0}
!24 = !{!6, !13, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass