#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*/ 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(int /*<<< orphan*/);
void _send(int sock, const char *buffer, size_t size) {
  int rs;
  while (size > 0) {
    if ((rs = send(sock, buffer, size, 0)) == -1) {
      fprintf(stderr, "send() failed: %s\n", strerror(errno));
      exit(1);
    } 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    1209 <_send+0xc9>
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    11b4 <_send+0x74>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11df <_send+0x9f>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11e4 <_send+0xa4>
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     1182 <_send+0x42>
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
je     1187 <_send+0x47>
cmp    $0xffffffff,%eax
je     11a8 <_send+0x68>
cltq
add    %rax,%rbx
sub    %rax,%r14
jne    1160 <_send+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%ebx
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe3a(%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):
@stderr = global i32 0
@.str = [19 x i8] c"send() failed: %s\0A\00"
@errno = global i32 0
@.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 = %31, %3
%9 = load i64, i64* %6
%10 = icmp ugt i64 %9, 0
br i1 %10, label %11, label %40
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 %23
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %11
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %23
br label %31
31: ; preds = %30
%32 = load i32, i32* %7
%33 = load i8*, i8** %5
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %5
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = load i64, i64* %6
%39 = sub i64 %38, %37
store i64 %39, i64* %6
br label %8
40: ; preds = %8
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"send() failed: %s\0A\00"
@errno = global i32 0
@.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 %24, label %5
5: ; preds = %3, %19
%6 = phi i8* [ %21, %19 ], [ %1, %3 ]
%7 = phi i64 [ %22, %19 ], [ %2, %3 ]
%8 = tail call i32 @send(i32 %0, i8* %6, i64 %7, i32 0)
switch i32 %8, label %19 [
i32 -1, label %9
i32 0, label %15
]
9: ; preds = %5
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %5
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %5
%20 = sext i32 %8 to i64
%21 = getelementptr inbounds i8, i8* %6, i64 %20
%22 = sub i64 %7, %20
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %5
24: ; preds = %19, %3
ret void
}