; 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.in6_addr = type { %union.anon.0 }
%union.anon.0 = type { [4 x i32] }
%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] }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%struct.sockaddr_in6 = type { i16, i16, i32, %struct.in6_addr, i32 }

@in6addr_any = external constant %struct.in6_addr, align 4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) #2

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

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

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i16, ptr %7, align 2, !tbaa !9
  %20 = call i32 @XsSocket_internalLookup(ptr noundef %17, ptr noundef %18, i16 noundef zeroext %19, i32 noundef 1, ptr noundef @binder, ptr noundef null, ptr noundef null)
  store i32 %20, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %58

21:                                               ; preds = %3
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 128, i1 false)
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.XsSocket, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = getelementptr inbounds %struct.XsSocketPrivate, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %38

28:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  store ptr %9, ptr %12, align 8, !tbaa !5
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.sockaddr_in, ptr %29, i32 0, i32 0
  store i16 2, ptr %30, align 4, !tbaa !18
  %31 = load i16, ptr %7, align 2, !tbaa !9
  %32 = call zeroext i16 @__bswap_16(i16 noundef zeroext %31)
  %33 = load ptr, ptr %12, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.sockaddr_in, ptr %33, i32 0, i32 1
  store i16 %32, ptr %34, align 2, !tbaa !21
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.sockaddr_in, ptr %35, i32 0, i32 2
  %37 = getelementptr inbounds %struct.in_addr, ptr %36, i32 0, i32 0
  store i32 0, ptr %37, align 4, !tbaa !22
  store i32 16, ptr %10, align 4, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %47

38:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  store ptr %9, ptr %13, align 8, !tbaa !5
  %39 = load ptr, ptr %13, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.sockaddr_in6, ptr %39, i32 0, i32 0
  store i16 10, ptr %40, align 4, !tbaa !24
  %41 = load i16, ptr %7, align 2, !tbaa !9
  %42 = call zeroext i16 @__bswap_16(i16 noundef zeroext %41)
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.sockaddr_in6, ptr %43, i32 0, i32 1
  store i16 %42, ptr %44, align 2, !tbaa !27
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.sockaddr_in6, ptr %45, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %46, ptr align 4 @in6addr_any, i64 16, i1 false), !tbaa.struct !28
  store i32 28, ptr %10, align 4, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  br label %47

47:                                               ; preds = %38, %28
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.XsSocket, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.XsSocketPrivate, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 8, !tbaa !30
  %53 = load i32, ptr %10, align 4, !tbaa !23
  %54 = call i32 @bind(i32 noundef %52, ptr noundef %9, i32 noundef %53) #6
  store i32 %54, ptr %8, align 4, !tbaa !23
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i32, ptr %8, align 4, !tbaa !23
  %57 = call i32 @translateAndReturnSocketError(ptr noundef %55, i32 noundef %56)
  store i32 %57, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %58

58:                                               ; preds = %47, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 128, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  %59 = load i32, ptr %4, align 4
  ret i32 %59
}

; Function Attrs: nounwind uwtable
declare hidden i32 @XsSocket_internalLookup(ptr noundef, ptr noundef, i16 noundef zeroext, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #3

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

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

; Function Attrs: nounwind
declare i32 @bind(i32 noundef, ptr noundef, i32 noundef) #5

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind "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 #6 = { 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 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"XsSocket", !6, i64 0}
!13 = !{!14, !15, i64 4}
!14 = !{!"XsSocketPrivate", !15, i64 0, !15, i64 4, !15, i64 8, !16, i64 16, !15, i64 144, !15, i64 148, !15, i64 152, !15, i64 156, !7, i64 160}
!15 = !{!"int", !7, i64 0}
!16 = !{!"sockaddr_storage", !10, i64 0, !7, i64 2, !17, i64 120}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !10, i64 0}
!19 = !{!"sockaddr_in", !10, i64 0, !10, i64 2, !20, i64 4, !7, i64 8}
!20 = !{!"in_addr", !15, i64 0}
!21 = !{!19, !10, i64 2}
!22 = !{!19, !15, i64 4}
!23 = !{!15, !15, i64 0}
!24 = !{!25, !10, i64 0}
!25 = !{!"sockaddr_in6", !10, i64 0, !10, i64 2, !15, i64 4, !26, i64 8, !15, i64 24}
!26 = !{!"in6_addr", !7, i64 0}
!27 = !{!25, !10, i64 2}
!28 = !{i64 0, i64 16, !29}
!29 = !{!7, !7, i64 0}
!30 = !{!14, !15, 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.in6_addr = type { %union.anon.0 }
%union.anon.0 = type { [4 x i32] }
%struct.sockaddr_storage = type { i16, [118 x i8], i64 }

@in6addr_any = external local_unnamed_addr constant %struct.in6_addr, align 4

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XsSocket_bind(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) local_unnamed_addr #3 {
  %4 = alloca %struct.sockaddr_storage, align 8
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %4) #6
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %7, label %5

5:                                                ; preds = %3
  %6 = tail call i32 @XsSocket_internalLookup(ptr noundef %0, ptr noundef nonnull %1, i16 noundef zeroext %2, i32 noundef 1, ptr noundef nonnull @binder, ptr noundef null, ptr noundef null)
  br label %23

7:                                                ; preds = %3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(128) %4, i8 0, i64 128, i1 false)
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !10
  %11 = icmp eq i32 %10, 0
  %12 = tail call zeroext i16 @__bswap_16(i16 noundef zeroext %2)
  br i1 %11, label %13, label %15

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 0, ptr %14, align 4, !tbaa !16
  br label %17

15:                                               ; preds = %7
  %16 = getelementptr inbounds i8, ptr %4, i64 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %16, ptr noundef nonnull align 4 dereferenceable(16) @in6addr_any, i64 16, i1 false), !tbaa.struct !19
  br label %17

17:                                               ; preds = %15, %13
  %.sink19 = phi i16 [ 2, %13 ], [ 10, %15 ]
  %.017 = phi i32 [ 16, %13 ], [ 28, %15 ]
  store i16 %.sink19, ptr %4, align 8
  %18 = getelementptr inbounds i8, ptr %4, i64 2
  store i16 %12, ptr %18, align 2
  %19 = load ptr, ptr %0, align 8, !tbaa !5
  %20 = load i32, ptr %19, align 8, !tbaa !21
  %21 = call i32 @bind(i32 noundef %20, ptr noundef nonnull %4, i32 noundef %.017) #6
  %22 = call i32 @translateAndReturnSocketError(ptr noundef nonnull %0, i32 noundef %21)
  br label %23

23:                                               ; preds = %17, %5
  %.0 = phi i32 [ %6, %5 ], [ %22, %17 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %4) #6
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @XsSocket_internalLookup(ptr noundef, ptr noundef, i16 noundef zeroext, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

; Function Attrs: nounwind
declare i32 @bind(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind "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 #6 = { 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 0}
!6 = !{!"XsSocket", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 4}
!11 = !{!"XsSocketPrivate", !12, i64 0, !12, i64 4, !12, i64 8, !13, i64 16, !12, i64 144, !12, i64 148, !12, i64 152, !12, i64 156, !8, i64 160}
!12 = !{!"int", !8, i64 0}
!13 = !{!"sockaddr_storage", !14, i64 0, !8, i64 2, !15, i64 120}
!14 = !{!"short", !8, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{!17, !12, i64 4}
!17 = !{!"sockaddr_in", !14, i64 0, !14, i64 2, !18, i64 4, !8, i64 8}
!18 = !{!"in_addr", !12, i64 0}
!19 = !{i64 0, i64 16, !20}
!20 = !{!8, !8, i64 0}
!21 = !{!11, !12, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass,TailCallElimPass