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

%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.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN19CSocketInConnection19replyToReceivedDataEPci(ptr noundef nonnull align 8 dereferenceable(204) %0, ptr noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %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 %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  %14 = getelementptr inbounds %class.CSocketInConnection, ptr %13, i32 0, i32 6
  %15 = load i8, ptr %14, align 4, !tbaa !11, !range !21, !noundef !22
  %16 = trunc i8 %15 to i1
  br i1 %16, label %18, label %17

17:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  br label %87

18:                                               ; preds = %3
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store i1 false, ptr %4, align 1
  br label %87

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %23 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %23, ptr %9, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %44, %22
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %45

27:                                               ; preds = %24
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %8, align 4, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = getelementptr inbounds %class.CSocketInConnection, ptr %13, i32 0, i32 11
  %32 = load i16, ptr %31, align 2, !tbaa !23
  %33 = zext i16 %32 to i32
  %34 = sub nsw i32 %33, 6
  %35 = icmp sgt i32 %30, %34
  br i1 %35, label %36, label %43

36:                                               ; preds = %27
  %37 = getelementptr inbounds %class.CSocketInConnection, ptr %13, i32 0, i32 11
  %38 = load i16, ptr %37, align 2, !tbaa !23
  %39 = zext i16 %38 to i32
  %40 = sub nsw i32 %39, 6
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = sub nsw i32 %41, %40
  store i32 %42, ptr %9, align 4, !tbaa !9
  br label %44

43:                                               ; preds = %27
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %43, %36
  br label %24, !llvm.loop !24

45:                                               ; preds = %24
  %46 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %46, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %84, %45
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %85

50:                                               ; preds = %47
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %53 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %53, ptr %11, align 4, !tbaa !9
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = getelementptr inbounds %class.CSocketInConnection, ptr %13, i32 0, i32 11
  %56 = load i16, ptr %55, align 2, !tbaa !23
  %57 = zext i16 %56 to i32
  %58 = sub nsw i32 %57, 6
  %59 = icmp sgt i32 %54, %58
  br i1 %59, label %60, label %65

60:                                               ; preds = %50
  %61 = getelementptr inbounds %class.CSocketInConnection, ptr %13, i32 0, i32 11
  %62 = load i16, ptr %61, align 2, !tbaa !23
  %63 = zext i16 %62 to i32
  %64 = sub nsw i32 %63, 6
  store i32 %64, ptr %11, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %60, %50
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = sub nsw i32 %67, %66
  store i32 %68, ptr %9, align 4, !tbaa !9
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i8, ptr %69, i64 %71
  %73 = load i32, ptr %11, align 4, !tbaa !9
  %74 = load i32, ptr %8, align 4, !tbaa !9
  %75 = trunc i32 %74 to i16
  %76 = call noundef zeroext i1 @_ZN19CSocketInConnection17_sendSimplePacketEPcit(ptr noundef nonnull align 8 dereferenceable(204) %13, ptr noundef %72, i32 noundef %73, i16 noundef zeroext %75)
  br i1 %76, label %78, label %77

77:                                               ; preds = %65
  store i1 false, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %82

78:                                               ; preds = %65
  %79 = load i32, ptr %11, align 4, !tbaa !9
  %80 = load i32, ptr %10, align 4, !tbaa !9
  %81 = add nsw i32 %80, %79
  store i32 %81, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %12, align 4
  br label %82

82:                                               ; preds = %78, %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  %83 = load i32, ptr %12, align 4
  switch i32 %83, label %86 [
    i32 0, label %84
  ]

84:                                               ; preds = %82
  br label %47, !llvm.loop !26

85:                                               ; preds = %47
  store i1 true, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %86

86:                                               ; preds = %85, %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %87

87:                                               ; preds = %86, %21, %17
  %88 = load i1, ptr %4, align 1
  ret i1 %88
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN19CSocketInConnection17_sendSimplePacketEPcit(ptr noundef nonnull align 8 dereferenceable(204), ptr noundef, i32 noundef, i16 noundef zeroext) #1 align 2

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


; 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN19CSocketInConnection19replyToReceivedDataEPci(ptr noundef nonnull align 8 dereferenceable(204) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 164
  %5 = load i8, ptr %4, align 4, !tbaa !5, !range !19, !noundef !20
  %6 = trunc nuw i8 %5 to i1
  %7 = icmp ne i32 %2, 0
  %or.cond.not = and i1 %7, %6
  br i1 %or.cond.not, label %select.unfold.preheader, label %.loopexit

select.unfold.preheader:                          ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 202
  %9 = load i16, ptr %8, align 2, !tbaa !21
  %10 = zext i16 %9 to i32
  %11 = add nsw i32 %10, -6
  br label %select.unfold

select.unfold:                                    ; preds = %select.unfold.preheader, %select.unfold
  %.02338 = phi i32 [ %2, %select.unfold.preheader ], [ %14, %select.unfold ]
  %.02537 = phi i16 [ 0, %select.unfold.preheader ], [ %12, %select.unfold ]
  %12 = add i16 %.02537, 1
  %13 = icmp sle i32 %.02338, %11
  %14 = sub nsw i32 %.02338, %11
  %.not39 = icmp eq i32 %14, 0
  %.not = select i1 %13, i1 true, i1 %.not39
  br i1 %.not, label %.preheader, label %select.unfold

.preheader:                                       ; preds = %select.unfold, %15
  %.126 = phi i16 [ %16, %15 ], [ %12, %select.unfold ]
  %.2 = phi i32 [ %20, %15 ], [ %2, %select.unfold ]
  %.022 = phi i32 [ %24, %15 ], [ 0, %select.unfold ]
  %.not33 = icmp eq i32 %.2, 0
  br i1 %.not33, label %.loopexit, label %15

15:                                               ; preds = %.preheader
  %16 = add i16 %.126, -1
  %17 = load i16, ptr %8, align 2, !tbaa !21
  %18 = zext i16 %17 to i32
  %19 = add nsw i32 %18, -6
  %spec.select = tail call i32 @llvm.smin.i32(i32 %.2, i32 %19)
  %20 = sub nsw i32 %.2, %spec.select
  %21 = sext i32 %.022 to i64
  %22 = getelementptr inbounds i8, ptr %1, i64 %21
  %23 = tail call noundef zeroext i1 @_ZN19CSocketInConnection17_sendSimplePacketEPcit(ptr noundef nonnull align 8 dereferenceable(204) %0, ptr noundef %22, i32 noundef %spec.select, i16 noundef zeroext %16)
  %24 = add nsw i32 %spec.select, %.022
  br i1 %23, label %.preheader, label %.loopexit, !llvm.loop !22

.loopexit:                                        ; preds = %15, %.preheader, %3
  %.3 = phi i1 [ false, %3 ], [ %.not33, %.preheader ], [ %.not33, %15 ]
  ret i1 %.3
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN19CSocketInConnection17_sendSimplePacketEPcit(ptr noundef nonnull align 8 dereferenceable(204), ptr noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !14, i64 164}
!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 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!6, !11, i64 202}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass