; LLVM IR from MRPT/mrpt :: 3rdparty/xspublic/xstypes (xssocket)

; 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.sockaddr_storage = type { i16, [118 x i8], i64 }
%struct.XsSocket = type { ptr }
%struct.XsSocketPrivate = type { i32, i32, i32, %struct.sockaddr_storage, i32, i32, i32, i32, [32768 x i8] }

; Function Attrs: nounwind uwtable
declare dso_local void @XsSocket_createFromNativeSocket(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 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: nounwind uwtable
declare hidden void @translateSocketError(ptr noundef, i32 noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden i32 @setLastResult(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @XsSocket_accept(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca %struct.sockaddr_storage, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 128, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 128, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp sge i32 %13, 0
  br i1 %14, label %15, label %36

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = call i32 @XsSocket_select(ptr noundef %16, i32 noundef %17, ptr noundef %10, ptr noundef null)
  store i32 %18, ptr %11, align 4, !tbaa !9
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %15
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = call i32 @setLastResult(ptr noundef %23, i32 noundef 259, i32 noundef 0)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %33

25:                                               ; preds = %15
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = icmp eq i32 %26, -1
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %11, align 4, !tbaa !9
  call void @translateSocketError(ptr noundef %29, i32 noundef %30)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %33

31:                                               ; preds = %25
  br label %32

32:                                               ; preds = %31
  store i32 0, ptr %12, align 4
  br label %33

33:                                               ; preds = %32, %28, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %34 = load i32, ptr %12, align 4
  switch i32 %34, label %53 [
    i32 0, label %35
  ]

35:                                               ; preds = %33
  br label %36

36:                                               ; preds = %35, %2
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.XsSocket, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.XsSocketPrivate, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !13
  %42 = call i32 @accept(i32 noundef %41, ptr noundef %7, ptr noundef %8)
  store i32 %42, ptr %9, align 4, !tbaa !9
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = call i32 @socketIsUsable(i32 noundef %43)
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %47, label %46

46:                                               ; preds = %36
  store ptr null, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %53

47:                                               ; preds = %36
  %48 = call ptr @XsSocket_allocate()
  store ptr %48, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = load i32, ptr %8, align 4, !tbaa !9
  call void @XsSocket_createFromNativeSocket(ptr noundef %49, i32 noundef %50, ptr noundef %7, i32 noundef %51, i32 noundef 1)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %52, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %53

53:                                               ; preds = %47, %46, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 128, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %54 = load ptr, ptr %3, align 8
  ret ptr %54
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @socketIsUsable(i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @XsSocket_allocate() #0

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"XsSocket", !6, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"XsSocketPrivate", !10, i64 0, !10, i64 4, !10, i64 8, !15, i64 16, !10, i64 144, !10, i64 148, !10, i64 152, !10, i64 156, !7, i64 160}
!15 = !{!"sockaddr_storage", !16, i64 0, !7, i64 2, !17, i64 120}
!16 = !{!"short", !7, i64 0}
!17 = !{!"long", !7, i64 0}


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

%struct.sockaddr_storage = type { i16, [118 x i8], i64 }

; Function Attrs: nounwind uwtable
declare dso_local void @XsSocket_createFromNativeSocket(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare hidden void @translateSocketError(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress 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 i32 @XsSocket_select(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @setLastResult(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @XsSocket_accept(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.sockaddr_storage, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  store i32 128, ptr %4, align 4, !tbaa !5
  %6 = icmp sgt i32 %1, -1
  br i1 %6, label %7, label %13

7:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %8 = call i32 @XsSocket_select(ptr noundef %0, i32 noundef %1, ptr noundef nonnull %5, ptr noundef null)
  switch i32 %8, label %12 [
    i32 0, label %9
    i32 -1, label %11
  ]

9:                                                ; preds = %7
  %10 = call i32 @setLastResult(ptr noundef %0, i32 noundef 259, i32 noundef 0)
  br label %.critedge

11:                                               ; preds = %7
  call void @translateSocketError(ptr noundef %0, i32 noundef -1)
  br label %.critedge

12:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %13

13:                                               ; preds = %12, %2
  %14 = load ptr, ptr %0, align 8, !tbaa !9
  %15 = load i32, ptr %14, align 8, !tbaa !12
  %16 = call i32 @accept(i32 noundef %15, ptr noundef nonnull %3, ptr noundef nonnull %4) #3
  %17 = call i32 @socketIsUsable(i32 noundef %16)
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %21, label %18

18:                                               ; preds = %13
  %19 = call ptr @XsSocket_allocate()
  %20 = load i32, ptr %4, align 4, !tbaa !5
  call void @XsSocket_createFromNativeSocket(ptr noundef %19, i32 noundef %16, ptr noundef nonnull %3, i32 noundef %20, i32 noundef 1)
  br label %21

.critedge:                                        ; preds = %11, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %21

21:                                               ; preds = %13, %.critedge, %18
  %.1 = phi ptr [ %19, %18 ], [ null, %.critedge ], [ null, %13 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %3) #3
  ret ptr %.1
}

declare i32 @accept(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @socketIsUsable(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @XsSocket_allocate() local_unnamed_addr #0

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 = { mustprogress 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, !11, i64 0}
!10 = !{!"XsSocket", !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"XsSocketPrivate", !6, i64 0, !6, i64 4, !6, i64 8, !14, i64 16, !6, i64 144, !6, i64 148, !6, i64 152, !6, i64 156, !7, i64 160}
!14 = !{!"sockaddr_storage", !15, i64 0, !7, i64 2, !16, i64 120}
!15 = !{!"short", !7, i64 0}
!16 = !{!"long", !7, i64 0}


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