#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 *, unsigned int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
void _send(int sock, const char *buffer, unsigned int size) {
  int rs;
  if (sock == -1)
    return;
  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    %edx,-0x14(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1161 <_send+0x21>
jmp    1250 <_send+0x110>
jmp    1166 <_send+0x26>
cmpl   $0x0,-0x14(%rbp)
jbe    1250 <_send+0x110>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11ff <_send+0xbf>
mov    0x2e3c(%rip),%rax
mov    (%rax),%rax
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%rax
je     11fa <_send+0xba>
mov    0x2e22(%rip),%rax
mov    (%rax),%rax
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%rax
je     11fa <_send+0xba>
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    1250 <_send+0x110>
cmpl   $0x0,-0x18(%rbp)
jne    122a <_send+0xea>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    122f <_send+0xef>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1166 <_send+0x26>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_send>:
push   %rbp
push   %r14
push   %rbx
cmp    $0xffffffff,%edi
je     11a6 <_send+0x66>
mov    %edx,%ebp
test   %edx,%edx
je     11a6 <_send+0x66>
mov    %rsi,%rbx
mov    %edi,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
cmp    $0xffffffff,%eax
je     1184 <_send+0x44>
test   %eax,%eax
je     11ab <_send+0x6b>
movslq %eax,%rcx
add    %rcx,%rbx
sub    %eax,%ebp
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, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %3
br label %52
11: ; preds = %3
br label %12
12: ; preds = %44, %11
%13 = load i32, i32* %6
%14 = icmp ugt i32 %13, 0
br i1 %14, label %15, label %52
15: ; preds = %12
%16 = load i32, i32* %4
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = call i32 @send(i32 %16, i8* %17, i32 %18, i32 0)
store i32 %19, i32* %7
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %36
21: ; preds = %15
%22 = load i64, i64* @errno
%23 = load i64, i64* @EINTR
%24 = icmp ne i64 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = load i64, i64* @errno
%27 = load i64, i64* @ECONNRESET
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = load i64, i64* @errno
%32 = call i8* @strerror(i64 %31)
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %25, %21
br label %52
36: ; preds = %15
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %36
br label %44
44: ; preds = %43
%45 = load i32, i32* %7
%46 = load i8*, i8** %5
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8* %48, i8** %5
%49 = load i32, i32* %7
%50 = load i32, i32* %6
%51 = sub i32 %50, %49
store i32 %51, i32* %6
br label %12
52: ; preds = %10, %35, %12
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, i32 %2) {
%4 = icmp eq i32 %0, -1
%5 = icmp eq i32 %2, 0
%6 = or i1 %4, %5
br i1 %6, label %32, label %7
7: ; preds = %3, %27
%8 = phi i8* [ %29, %27 ], [ %1, %3 ]
%9 = phi i32 [ %30, %27 ], [ %2, %3 ]
%10 = tail call i32 @send(i32 %0, i8* %8, i32 %9, i32 0)
switch i32 %10, label %27 [
i32 -1, label %11
i32 0, label %23
]
11: ; preds = %7
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %12, %13
%15 = load i64, i64* @ECONNRESET
%16 = icmp eq i64 %12, %15
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %32, label %18
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = tail call i8* @strerror(i64 %12)
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %7
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %7
%28 = sext i32 %10 to i64
%29 = getelementptr inbounds i8, i8* %8, i64 %28
%30 = sub i32 %9, %10
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %7
32: ; preds = %27, %11, %3
ret void
}