#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int send(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int sendall(int conn_fd, uint8_t *buf, int size) {
  int rvalue = 0;
  int bytes2send = size;
  do {
    rvalue = send(conn_fd, buf, bytes2send, 0);
    if (-1 == rvalue) {
      fprintf(stderr, "sendall failed:%s\n", strerror(errno));
      return -1;
    } else if (rvalue == 0) {
      fprintf(stderr, "sendall failed:%s\n", strerror(errno));
      return -1;
    }
    bytes2send -= rvalue;
    buf += rvalue;
  } while (bytes2send > 0);
  return 0;
}


x86 assembly (clang, -O0):
<sendall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x18(%rbp)
mov    $0xffffffff,%eax
cmp    -0x18(%rbp),%eax
jne    11a9 <sendall+0x79>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe68(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <sendall+0xf1>
cmpl   $0x0,-0x18(%rbp)
jne    11eb <sendall+0xbb>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe26(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <sendall+0xf1>
jmp    11f0 <sendall+0xc0>
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     114f <sendall+0x1f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendall>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
jb     1166 <sendall+0x36>
movslq %eax,%rcx
lea    (%rbx,%rcx,4),%rbx
sub    %eax,%ebp
jg     1140 <sendall+0x10>
xor    %eax,%eax
jmp    1193 <sendall+0x63>
mov    0x2e73(%rip),%rax
mov    (%rax),%ebx
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe7c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"sendall failed:%s\0A\00"
@errno = global i32 0
define i32 @sendall(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 0, i32* %8
%10 = load i32, i32* %7
store i32 %10, i32* %9
br label %11
11: ; preds = %40, %3
%12 = load i32, i32* %5
%13 = load i32*, i32** %6
%14 = load i32, i32* %9
%15 = call i32 @send(i32 %12, i32* %13, i32 %14, i32 0)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 -1, i32* %4
br label %44
23: ; preds = %11
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %29)
store i32 -1, i32* %4
br label %44
31: ; preds = %23
br label %32
32: ; preds = %31
%33 = load i32, i32* %8
%34 = load i32, i32* %9
%35 = sub nsw i32 %34, %33
store i32 %35, i32* %9
%36 = load i32, i32* %8
%37 = load i32*, i32** %6
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i32, i32* %37, i64 %38
store i32* %39, i32** %6
br label %40
40: ; preds = %32
%41 = load i32, i32* %9
%42 = icmp sgt i32 %41, 0
br i1 %42, label %11, label %43
43: ; preds = %40
store i32 0, i32* %4
br label %44
44: ; preds = %43, %26, %18
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"sendall failed:%s\0A\00"
@errno = global i32 0
define i32 @sendall(i32 %0, i32* %1, i32 %2) {
br label %4
4: ; preds = %8, %3
%5 = phi i32* [ %1, %3 ], [ %11, %8 ]
%6 = phi i32 [ %2, %3 ], [ %9, %8 ]
%7 = tail call i32 @send(i32 %0, i32* %5, i32 %6, i32 0)
switch i32 %7, label %8 [
i32 -1, label %13
i32 0, label %13
]
8: ; preds = %4
%9 = sub nsw i32 %6, %7
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds i32, i32* %5, i64 %10
%12 = icmp sgt i32 %9, 0
br i1 %12, label %4, label %18
13: ; preds = %4, %4
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %8, %13
%19 = phi i32 [ -1, %13 ], [ 0, %8 ]
ret i32 %19
}