; LLVM IR from mhsitu/welding_robot :: coppeliaSim-client/common/socketOutConnection.ll (ZN20CSocketOutConnection8sendDataEPKci)

; 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.CSocketOutConnection = type <{ ptr, %"class.std::__cxx11::basic_string", i32, i32, %struct.sockaddr_in, i8, i8, i16, [4 x i8] }>
%"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] }
%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 @_ZN20CSocketOutConnection8sendDataEPKci(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef %1, i32 noundef %2) #0 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.CSocketOutConnection, ptr %13, i32 0, i32 3
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %18

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.CSocketOutConnection, ptr %13, i32 0, i32 7
  %32 = load i16, ptr %31, align 2, !tbaa !19
  %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.CSocketOutConnection, ptr %13, i32 0, i32 7
  %38 = load i16, ptr %37, align 2, !tbaa !19
  %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 !20

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.CSocketOutConnection, ptr %13, i32 0, i32 7
  %56 = load i16, ptr %55, align 2, !tbaa !19
  %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.CSocketOutConnection, ptr %13, i32 0, i32 7
  %62 = load i16, ptr %61, align 2, !tbaa !19
  %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 @_ZN20CSocketOutConnection17_sendSimplePacketEPKcit(ptr noundef nonnull align 8 dereferenceable(68) %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 !22

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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
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, !10, i64 44}
!12 = !{!"_ZTS20CSocketOutConnection", !13, i64 8, !10, i64 40, !10, i64 44, !16, i64 48, !7, i64 64, !7, i64 65, !17, i64 66}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ZTS11sockaddr_in", !17, i64 0, !17, i64 2, !18, i64 4, !7, i64 8}
!17 = !{!"short", !7, i64 0}
!18 = !{!"_ZTS7in_addr", !10, i64 0}
!19 = !{!12, !17, i64 66}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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 @_ZN20CSocketOutConnection8sendDataEPKci(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 44
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp eq i32 %5, -1
  %7 = icmp eq i32 %2, 0
  %or.cond = or i1 %7, %6
  br i1 %or.cond, label %.loopexit, label %select.unfold.preheader

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

select.unfold:                                    ; preds = %select.unfold.preheader, %select.unfold
  %.02336 = phi i32 [ %2, %select.unfold.preheader ], [ %14, %select.unfold ]
  %.02535 = phi i16 [ 0, %select.unfold.preheader ], [ %12, %select.unfold ]
  %12 = add i16 %.02535, 1
  %13 = icmp sle i32 %.02336, %11
  %14 = sub nsw i32 %.02336, %11
  %.not37 = icmp eq i32 %14, 0
  %.not = select i1 %13, i1 true, i1 %.not37
  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 !17
  %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 @_ZN20CSocketOutConnection17_sendSimplePacketEPKcit(ptr noundef nonnull align 8 dereferenceable(68) %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 !18

.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 @_ZN20CSocketOutConnection17_sendSimplePacketEPKcit(ptr noundef nonnull align 8 dereferenceable(68), 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, !13, i64 44}
!6 = !{!"_ZTS20CSocketOutConnection", !7, i64 8, !13, i64 40, !13, i64 44, !14, i64 48, !10, i64 64, !10, i64 65, !15, i64 66}
!7 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !8, i64 0, !12, i64 8, !10, i64 16}
!8 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!"int", !10, i64 0}
!14 = !{!"_ZTS11sockaddr_in", !15, i64 0, !15, i64 2, !16, i64 4, !10, i64 8}
!15 = !{!"short", !10, i64 0}
!16 = !{!"_ZTS7in_addr", !13, i64 0}
!17 = !{!6, !15, i64 66}
!18 = distinct !{!18, !19}
!19 = !{!"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