; 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
declare dso_local void @us_listen_socket_close(i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @us_socket_context_close(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.us_socket_context_t, ptr %9, i32 0, i32 5
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %5, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %15, %2
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %23

15:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.us_listen_socket_t, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds %struct.us_socket_t, ptr %17, i32 0, i32 6
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  store ptr %19, ptr %6, align 8, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  call void @us_listen_socket_close(i32 noundef %20, ptr noundef %21)
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %22, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %12, !llvm.loop !19

23:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.us_socket_context_t, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %25, align 16, !tbaa !21
  store ptr %26, ptr %7, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %30, %23
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %38

30:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %31 = load ptr, ptr %7, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.us_socket_t, ptr %31, i32 0, i32 6
  %33 = load ptr, ptr %32, align 8, !tbaa !22
  store ptr %33, ptr %8, align 8, !tbaa !9
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = call ptr @us_socket_close(i32 noundef %34, ptr noundef %35, i32 noundef 0, ptr noundef null)
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %37, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %27, !llvm.loop !23

38:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; 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

declare ptr @us_socket_close(i32 noundef, ptr noundef, i32 noundef, ptr noundef) #2

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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, !10, i64 24}
!12 = !{!"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}
!13 = !{!14, !10, i64 40}
!14 = !{!"us_listen_socket_t", !15, i64 0, !6, i64 48}
!15 = !{!"us_socket_t", !16, i64 0, !7, i64 16, !7, i64 17, !18, i64 18, !10, i64 24, !10, i64 32, !10, i64 40}
!16 = !{!"us_poll_t", !17, i64 0}
!17 = !{!"", !6, i64 0, !6, i64 3}
!18 = !{!"short", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !10, i64 16}
!22 = !{!15, !10, i64 40}
!23 = distinct !{!23, !20}


; 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: nounwind uwtable
declare dso_local void @us_listen_socket_close(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @us_socket_context_close(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not13 = icmp eq ptr %4, null
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.014 = phi ptr [ %6, %.lr.ph ], [ %4, %2 ]
  %5 = getelementptr inbounds i8, ptr %.014, i64 40
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  tail call void @us_listen_socket_close(i32 noundef %0, ptr noundef nonnull %.014)
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph, %2
  %7 = getelementptr inbounds i8, ptr %1, i64 16
  %8 = load ptr, ptr %7, align 16, !tbaa !19
  %.not1215 = icmp eq ptr %8, null
  br i1 %.not1215, label %._crit_edge19, label %.lr.ph18

.lr.ph18:                                         ; preds = %._crit_edge, %.lr.ph18
  %.01116 = phi ptr [ %10, %.lr.ph18 ], [ %8, %._crit_edge ]
  %9 = getelementptr inbounds i8, ptr %.01116, i64 40
  %10 = load ptr, ptr %9, align 8, !tbaa !20
  %11 = tail call ptr @us_socket_close(i32 noundef %0, ptr noundef nonnull %.01116, i32 noundef 0, ptr noundef null) #2
  %.not12 = icmp eq ptr %10, null
  br i1 %.not12, label %._crit_edge19, label %.lr.ph18, !llvm.loop !21

._crit_edge19:                                    ; preds = %.lr.ph18, %._crit_edge
  ret void
}

declare ptr @us_socket_close(i32 noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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" }
attributes #1 = { "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, !7, i64 24}
!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 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !7, i64 16}
!20 = !{!13, !7, i64 40}
!21 = distinct !{!21, !18}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass