; LLVM IR from mhsitu/welding_robot :: coppeliaSim-client/common (socketInConnection)

; 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_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%class.CSocketInConnection = type <{ ptr, i32, i32, %struct.sockaddr_in, %struct.fd_set, i32, i8, [3 x i8], %"class.std::__cxx11::basic_string", i8, i8, i16, [4 x i8] }>
%struct.fd_set = type { [16 x i64] }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN19CSocketInConnection15connectToClientEv(ptr noundef nonnull align 8 dereferenceable(204) %0) #0 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca %struct.sockaddr_in, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.in_addr, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  %10 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 3
  %11 = getelementptr inbounds %struct.sockaddr_in, ptr %10, i32 0, i32 0
  store i16 2, ptr %11, align 8, !tbaa !9
  %12 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 3
  %13 = getelementptr inbounds %struct.sockaddr_in, ptr %12, i32 0, i32 2
  %14 = getelementptr inbounds %struct.in_addr, ptr %13, i32 0, i32 0
  store i32 0, ptr %14, align 4, !tbaa !20
  %15 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 5
  %16 = load i32, ptr %15, align 8, !tbaa !21
  %17 = trunc i32 %16 to i16
  %18 = call noundef zeroext i16 @_ZL10__bswap_16t(i16 noundef zeroext %17)
  %19 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 3
  %20 = getelementptr inbounds %struct.sockaddr_in, ptr %19, i32 0, i32 1
  store i16 %18, ptr %20, align 2, !tbaa !22
  %21 = call i32 @socket(i32 noundef 2, i32 noundef 1, i32 noundef 0) #6
  %22 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 1
  store i32 %21, ptr %22, align 8, !tbaa !23
  %23 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !23
  %25 = icmp eq i32 %24, -1
  br i1 %25, label %26, label %27

26:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %84

27:                                               ; preds = %1
  %28 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !23
  %30 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 3
  %31 = call i32 @bind(i32 noundef %29, ptr noundef %30, i32 noundef 16) #6
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  store i1 false, ptr %2, align 1
  br label %84

34:                                               ; preds = %27
  %35 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !23
  %37 = call i32 @listen(i32 noundef %36, i32 noundef 10) #6
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %34
  store i1 false, ptr %2, align 1
  br label %84

40:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 16, ptr %5, align 4, !tbaa !24
  %41 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 1
  %42 = load i32, ptr %41, align 8, !tbaa !23
  %43 = call i32 @accept(i32 noundef %42, ptr noundef %4, ptr noundef %5)
  %44 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 2
  store i32 %43, ptr %44, align 4, !tbaa !25
  %45 = getelementptr inbounds %struct.sockaddr_in, ptr %4, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %45, i64 4, i1 false), !tbaa.struct !26
  %46 = getelementptr inbounds %struct.in_addr, ptr %6, i32 0, i32 0
  %47 = load i32, ptr %46, align 4
  %48 = call ptr @inet_ntoa(i32 %47) #6
  %49 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 8
  %50 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc(ptr noundef nonnull align 8 dereferenceable(32) %49, ptr noundef %48)
  br label %51

51:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %52 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 4
  store ptr %52, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !24
  br label %53

53:                                               ; preds = %63, %51
  %54 = load i32, ptr %7, align 4, !tbaa !24
  %55 = zext i32 %54 to i64
  %56 = icmp ult i64 %55, 16
  br i1 %56, label %57, label %66

57:                                               ; preds = %53
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.fd_set, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %7, align 4, !tbaa !24
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds [16 x i64], ptr %59, i64 0, i64 %61
  store i64 0, ptr %62, align 8, !tbaa !27
  br label %63

63:                                               ; preds = %57
  %64 = load i32, ptr %7, align 4, !tbaa !24
  %65 = add i32 %64, 1
  store i32 %65, ptr %7, align 4, !tbaa !24
  br label %53, !llvm.loop !28

66:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  %69 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 2
  %70 = load i32, ptr %69, align 4, !tbaa !25
  %71 = srem i32 %70, 64
  %72 = zext i32 %71 to i64
  %73 = shl i64 1, %72
  %74 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 4
  %75 = getelementptr inbounds %struct.fd_set, ptr %74, i32 0, i32 0
  %76 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 2
  %77 = load i32, ptr %76, align 4, !tbaa !25
  %78 = sdiv i32 %77, 64
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [16 x i64], ptr %75, i64 0, i64 %79
  %81 = load i64, ptr %80, align 8, !tbaa !27
  %82 = or i64 %81, %73
  store i64 %82, ptr %80, align 8, !tbaa !27
  %83 = getelementptr inbounds %class.CSocketInConnection, ptr %9, i32 0, i32 6
  store i8 1, ptr %83, align 4, !tbaa !30
  store i1 true, ptr %2, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #6
  br label %84

84:                                               ; preds = %68, %39, %33, %26
  %85 = load i1, ptr %2, align 1
  ret i1 %85
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i16 @_ZL10__bswap_16t(i16 noundef zeroext) #1

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) #2

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

; Function Attrs: nounwind
declare i32 @listen(i32 noundef, i32 noundef) #2

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

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

; Function Attrs: nounwind
declare ptr @inet_ntoa(i32) #2

; 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) #5

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) #0 align 2

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

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !13, i64 16}
!10 = !{!"_ZTS19CSocketInConnection", !11, i64 8, !11, i64 12, !12, i64 16, !15, i64 32, !11, i64 160, !16, i64 164, !17, i64 168, !7, i64 200, !7, i64 201, !13, i64 202}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS11sockaddr_in", !13, i64 0, !13, i64 2, !14, i64 4, !7, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!"_ZTS7in_addr", !11, i64 0}
!15 = !{!"_ZTS6fd_set", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !18, i64 0, !19, i64 8, !7, i64 16}
!18 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!10, !11, i64 20}
!21 = !{!10, !11, i64 160}
!22 = !{!10, !13, i64 18}
!23 = !{!10, !11, i64 8}
!24 = !{!11, !11, i64 0}
!25 = !{!10, !11, i64 12}
!26 = !{i64 0, i64 4, !24}
!27 = !{!19, !19, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = !{!10, !16, i64 164}


; 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_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN19CSocketInConnection15connectToClientEv(ptr noundef nonnull align 8 dereferenceable(204) %0) local_unnamed_addr #0 align 2 {
  %2 = alloca %struct.sockaddr_in, align 4
  %3 = alloca i32, align 4
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  store i16 2, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 0, ptr %5, align 4, !tbaa !19
  %6 = getelementptr inbounds i8, ptr %0, i64 160
  %7 = load i32, ptr %6, align 8, !tbaa !20
  %8 = trunc i32 %7 to i16
  %9 = tail call noundef zeroext i16 @_ZL10__bswap_16t(i16 noundef zeroext %8)
  %10 = getelementptr inbounds i8, ptr %0, i64 18
  store i16 %9, ptr %10, align 2, !tbaa !21
  %11 = tail call i32 @socket(i32 noundef 2, i32 noundef 1, i32 noundef 0) #6
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %11, ptr %12, align 8, !tbaa !22
  %13 = icmp eq i32 %11, -1
  br i1 %13, label %38, label %14

14:                                               ; preds = %1
  %15 = tail call i32 @bind(i32 noundef %11, ptr noundef nonnull %4, i32 noundef 16) #6
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %16, label %38

16:                                               ; preds = %14
  %17 = load i32, ptr %12, align 8, !tbaa !22
  %18 = tail call i32 @listen(i32 noundef %17, i32 noundef 10) #6
  %.not8 = icmp eq i32 %18, 0
  br i1 %.not8, label %19, label %38

19:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  store i32 16, ptr %3, align 4, !tbaa !23
  %20 = load i32, ptr %12, align 8, !tbaa !22
  %21 = call i32 @accept(i32 noundef %20, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %22 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %21, ptr %22, align 4, !tbaa !24
  %23 = getelementptr inbounds i8, ptr %2, i64 4
  %.sroa.0.0.copyload = load i32, ptr %23, align 4, !tbaa !23
  %24 = call ptr @inet_ntoa(i32 %.sroa.0.0.copyload) #6
  %25 = getelementptr inbounds i8, ptr %0, i64 168
  %26 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc(ptr noundef nonnull align 8 dereferenceable(32) %25, ptr noundef %24)
  %27 = getelementptr inbounds i8, ptr %0, i64 32
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(128) %27, i8 0, i64 128, i1 false), !tbaa !25
  %28 = load i32, ptr %22, align 4, !tbaa !24
  %29 = srem i32 %28, 64
  %30 = zext nneg i32 %29 to i64
  %31 = shl nuw i64 1, %30
  %32 = sdiv i32 %28, 64
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [16 x i64], ptr %27, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !25
  %36 = or i64 %31, %35
  store i64 %36, ptr %34, align 8, !tbaa !25
  %37 = getelementptr inbounds i8, ptr %0, i64 164
  store i8 1, ptr %37, align 4, !tbaa !26
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #6
  br label %38

38:                                               ; preds = %16, %14, %1, %19
  %.0 = phi i1 [ true, %19 ], [ false, %1 ], [ false, %14 ], [ false, %16 ]
  ret i1 %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i16 @_ZL10__bswap_16t(i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind
declare i32 @listen(i32 noundef, i32 noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind
declare ptr @inet_ntoa(i32) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) local_unnamed_addr #0 align 2

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

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

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !11, i64 16}
!6 = !{!"_ZTS19CSocketInConnection", !7, i64 8, !7, i64 12, !10, i64 16, !13, i64 32, !7, i64 160, !14, i64 164, !15, i64 168, !8, i64 200, !8, i64 201, !11, i64 202}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS11sockaddr_in", !11, i64 0, !11, i64 2, !12, i64 4, !8, i64 8}
!11 = !{!"short", !8, i64 0}
!12 = !{!"_ZTS7in_addr", !7, i64 0}
!13 = !{!"_ZTS6fd_set", !8, i64 0}
!14 = !{!"bool", !8, i64 0}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !16, i64 0, !18, i64 8, !8, i64 16}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !17, i64 0}
!17 = !{!"any pointer", !8, i64 0}
!18 = !{!"long", !8, i64 0}
!19 = !{!6, !7, i64 20}
!20 = !{!6, !7, i64 160}
!21 = !{!6, !11, i64 18}
!22 = !{!6, !7, i64 8}
!23 = !{!7, !7, i64 0}
!24 = !{!6, !7, i64 12}
!25 = !{!18, !18, i64 0}
!26 = !{!6, !14, i64 164}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass