#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int send(int, char *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int send_data(int conn, void *buff, size_t len) {
  char *scan;
  int sent = 0;
  for (scan = (char *)buff; len != 0; scan = scan + sent, len -= sent) {
    if ((sent = send(conn, scan, len, 0)) < 0) {
      fprintf(stderr, "Cannot send data over network\n");
      return -3;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<send_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b4 <send_data+0x94>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    118c <send_data+0x6c>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11bb <send_data+0x9b>
jmp    1191 <send_data+0x71>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movslq -0x24(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1142 <send_data+0x22>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_data>:
push   %rbp
push   %r14
push   %rbx
test   %rdx,%rdx
je     115d <send_data+0x3d>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
test   %eax,%eax
js     1161 <send_data+0x41>
mov    %eax,%eax
add    %rax,%rbx
sub    %rax,%r14
jne    1140 <send_data+0x20>
xor    %eax,%eax
jmp    117b <send_data+0x5b>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xfffffffd,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Cannot send data over network\0A\00"
define i32 @send_data(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 0, i32* %9
%10 = load i8*, i8** %6
store i8* %10, i8** %8
br label %11
11: ; preds = %24, %3
%12 = load i64, i64* %7
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %33
14: ; preds = %11
%15 = load i32, i32* %5
%16 = load i8*, i8** %8
%17 = load i64, i64* %7
%18 = call i32 @send(i32 %15, i8* %16, i64 %17, i32 0)
store i32 %18, i32* %9
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -3, i32* %4
br label %34
23: ; preds = %14
br label %24
24: ; preds = %23
%25 = load i8*, i8** %8
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8* %28, i8** %8
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = load i64, i64* %7
%32 = sub i64 %31, %30
store i64 %32, i64* %7
br label %11
33: ; preds = %11
store i32 0, i32* %4
br label %34
34: ; preds = %33, %20
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Cannot send data over network\0A\00"
define i32 @send_data(i32 %0, i8* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %18, label %5
5: ; preds = %3, %13
%6 = phi i8* [ %15, %13 ], [ %1, %3 ]
%7 = phi i64 [ %16, %13 ], [ %2, %3 ]
%8 = tail call i32 @send(i32 %0, i8* %6, i64 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %18
13: ; preds = %5
%14 = zext i32 %8 to i64
%15 = getelementptr inbounds i8, i8* %6, i64 %14
%16 = sub i64 %7, %14
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %5
18: ; preds = %13, %3, %10
%19 = phi i32 [ -3, %10 ], [ 0, %3 ], [ 0, %13 ]
ret i32 %19
}