#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 */
scalar_t__ ECONNRESET;
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int send(int, char const *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
void _send(int sock, const char *buffer, size_t size) {
  int rs;
  while (size > 0) {
    if ((rs = send(sock, buffer, size, 0)) == -1) {
      if (errno != EINTR && errno != ECONNRESET) {
        fprintf(stderr, "send() failed: %s\n", strerror(errno));
        exit(1);
      } else {
        return;
      }
    } else if (rs == 0) {
      fprintf(stderr, "send() unexpectedly returned 0\n");
      exit(1);
    }
    buffer += rs;
    size -= rs;
  }
}


x86 assembly (clang, -O0):
<_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    1243 <_send+0x103>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11ee <_send+0xae>
mov    0x2e4d(%rip),%rax
mov    (%rax),%rax
mov    0x2e3b(%rip),%rcx
cmp    (%rcx),%rax
je     11e9 <_send+0xa9>
mov    0x2e33(%rip),%rax
mov    (%rax),%rax
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%rax
je     11e9 <_send+0xa9>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    1243 <_send+0x103>
cmpl   $0x0,-0x1c(%rbp)
jne    1219 <_send+0xd9>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    121e <_send+0xde>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movslq -0x1c(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1153 <_send+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_send>:
push   %rbp
push   %r14
push   %rbx
test   %rdx,%rdx
je     11a6 <_send+0x66>
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>
cmp    $0xffffffff,%eax
je     1184 <_send+0x44>
test   %eax,%eax
je     11ab <_send+0x6b>
cltq
add    %rax,%rbx
sub    %rax,%r14
jne    1160 <_send+0x20>
jmp    11a6 <_send+0x66>
mov    0x2e45(%rip),%rax
mov    (%rax),%rdi
mov    0x2e33(%rip),%rax
cmp    (%rax),%rdi
je     11a6 <_send+0x66>
mov    0x2e3f(%rip),%rax
cmp    (%rax),%rdi
jne    11cc <_send+0x8c>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%ebx
call   1060 <strerror@plt>
lea    0xe1f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@ECONNRESET = global i64 0
@stderr = global i32 0
@.str = [19 x i8] c"send() failed: %s\0A\00"
@.str.1 = [32 x i8] c"send() unexpectedly returned 0\0A\00"
define void @_send(i32 %0, i8* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %30, label %5
5: ; preds = %3, %25
%6 = phi i8* [ %27, %25 ], [ %1, %3 ]
%7 = phi i64 [ %28, %25 ], [ %2, %3 ]
%8 = tail call i32 @send(i32 %0, i8* %6, i64 %7, i32 0)
switch i32 %8, label %25 [
i32 -1, label %9
i32 0, label %21
]
9: ; preds = %5
%10 = load i64, i64* @errno
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %10, %11
%13 = load i64, i64* @ECONNRESET
%14 = icmp eq i64 %10, %13
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %30, label %16
16: ; preds = %9
%17 = load i32, i32* @stderr
%18 = tail call i8* @strerror(i64 %10)
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %5
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %5
%26 = sext i32 %8 to i64
%27 = getelementptr inbounds i8, i8* %6, i64 %26
%28 = sub i64 %7, %26
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %5
30: ; preds = %25, %3, %9
ret void
}