#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int send(int, char const *, int, int /*<<< orphan*/);
int rlSendData(int theSocket, const void *theData, int theLength) {
  int theBytesSent = 0;
  int theMsgError = 0;
  const char *theDataBuffer = (const char *)theData;
  while (theBytesSent < theLength) {
    theMsgError = send(theSocket, theDataBuffer + theBytesSent,
                       theLength - theBytesSent, 0);
    if (theMsgError == -1)
      break;
    else
      theBytesSent += theMsgError;
  }
  return theBytesSent;
}


x86 assembly (clang, -O0):
<rlSendData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117f <rlSendData+0x6f>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x18(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1171 <rlSendData+0x61>
jmp    117f <rlSendData+0x6f>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1138 <rlSendData+0x28>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rlSendData>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1152 <rlSendData+0x42>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebx,%rax
lea    (%r14,%rax,1),%rsi
mov    %ebp,%edx
sub    %eax,%edx
mov    %r15d,%edi
xor    %ecx,%ecx
call   1030 <send@plt>
cmp    $0xffffffff,%eax
je     1154 <rlSendData+0x44>
add    %eax,%ebx
cmp    %ebp,%ebx
jl     1130 <rlSendData+0x20>
jmp    1154 <rlSendData+0x44>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rlSendData(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%10 = load i8*, i8** %5
store i8* %10, i8** %9
br label %11
11: ; preds = %32, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = load i32, i32* %4
%17 = load i8*, i8** %9
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = sub nsw i32 %21, %22
%24 = call i32 @send(i32 %16, i8* %20, i32 %23, i32 0)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %15
br label %33
28: ; preds = %15
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = add nsw i32 %30, %29
store i32 %31, i32* %7
br label %32
32: ; preds = %28
br label %11
33: ; preds = %27, %11
%34 = load i32, i32* %7
ret i32 %34
}

LLVM IR (-O2):
define i32 @rlSendData(i32 %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %7, label %15
5: ; preds = %7
%6 = icmp slt i32 %14, %2
br i1 %6, label %7, label %15
7: ; preds = %3, %5
%8 = phi i32 [ %14, %5 ], [ 0, %3 ]
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = sub nsw i32 %2, %8
%12 = tail call i32 @send(i32 %0, i8* %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
%14 = add nsw i32 %12, %8
br i1 %13, label %15, label %5
15: ; preds = %5, %7, %3
%16 = phi i32 [ 0, %3 ], [ %8, %7 ], [ %14, %5 ]
ret i32 %16
}