#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ abortmsgerrno(char *);
scalar_t__ send(int, char const *, int, int /*<<< orphan*/);
void sendall(int sockfd, const void *data, size_t datasize) {
  const char *p = data;
  const char *const endp = p + datasize;
  while (p < endp) {
    ssize_t r = send(sockfd, p, endp - p, 0);
    if (r < 0)
      abortmsgerrno("cannot communicate");
    p += r;
  }
}


x86 assembly (clang, -O0):
<sendall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    119c <sendall+0x7c>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    118b <sendall+0x6b>
lea    0xe7a(%rip),%rdi
call   1040 <abortmsgerrno@plt>
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1147 <sendall+0x27>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendall>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdx,%rdx
jle    117c <sendall+0x5c>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r12d
add    %rsi,%r14
lea    0xec0(%rip),%r15
jmp    1158 <sendall+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %rbp,%rbx
cmp    %r14,%rbx
jae    117c <sendall+0x5c>
mov    %r14d,%edx
sub    %ebx,%edx
mov    %r12d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %rax,%rbp
test   %rax,%rax
jns    1150 <sendall+0x30>
mov    %r15,%rdi
call   1040 <abortmsgerrno@plt>
jmp    1150 <sendall+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [19 x i8] c"cannot communicate\00"
define void @sendall(i32 %0, i8* %1, i64 %2) {
%4 = getelementptr inbounds i8, i8* %1, i64 %2
%5 = icmp sgt i64 %2, 0
br i1 %5, label %6, label %20
6: ; preds = %3
%7 = ptrtoint i8* %4 to i64
br label %8
8: ; preds = %6, %17
%9 = phi i8* [ %1, %6 ], [ %18, %17 ]
%10 = ptrtoint i8* %9 to i64
%11 = sub i64 %7, %10
%12 = trunc i64 %11 to i32
%13 = tail call i64 @send(i32 %0, i8* %9, i32 %12, i32 0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = tail call i32 @abortmsgerrno(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %8
%18 = getelementptr inbounds i8, i8* %9, i64 %13
%19 = icmp ult i8* %18, %4
br i1 %19, label %8, label %20
20: ; preds = %17, %3
ret void
}