#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 *, int, int /*<<< orphan*/);
int SendData(int sockfd, const void *payload, int cbPayload) {
  int cb;
  int cbTotal = cbPayload;
  char *p = (char *)payload;
  while (cbTotal > 0) {
    cb = send(sockfd, p, cbTotal, 0);
    if (cb <= 0)
      break;
    if (cb == cbTotal)
      return cbPayload;
    p += cb;
    cbTotal -= cb;
  };
  return 0;
}


x86 assembly (clang, -O0):
<SendData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1195 <SendData+0x85>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     115d <SendData+0x4d>
jmp    1195 <SendData+0x85>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1174 <SendData+0x64>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <SendData+0x8c>
mov    -0x18(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    1130 <SendData+0x20>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SendData>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
jle    1152 <SendData+0x42>
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %edx,%ebp
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
test   %eax,%eax
jle    115a <SendData+0x4a>
cmp    %eax,%ebp
je     1157 <SendData+0x47>
mov    %eax,%ecx
add    %rcx,%rbx
sub    %eax,%ebp
jg     1130 <SendData+0x20>
jmp    115a <SendData+0x4a>
xor    %r12d,%r12d
jmp    115a <SendData+0x4a>
mov    %r14d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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