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

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int send(int, void *, size_t, int /*<<< orphan*/);
int send_safe(int sock, void *buf, size_t len) {
  ssize_t nr;
  int ret = -1;
  do {
    nr = send(sock, buf, len, 0);
  } while ((-1 == nr) && (errno == EINTR));
  if (nr >= 0) {
    ret = 0;
  }
  return ret;
}


x86 assembly (clang, -O0):
<send_safe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    -0x1c(%rbp),%ecx
mov    %al,-0x21(%rbp)
jne    116c <send_safe+0x5c>
mov    0x2e87(%rip),%rax
mov    (%rax),%rax
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    112a <send_safe+0x1a>
cmpl   $0x0,-0x1c(%rbp)
jl     1188 <send_safe+0x78>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_safe>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb9(%rip),%r15
mov    0x2eaa(%rip),%r12
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
cmp    $0xffffffff,%eax
jne    114d <send_safe+0x3d>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1130 <send_safe+0x20>
sar    $0x1f,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @send_safe(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 -1, i32* %8
br label %9
9: ; preds = %21, %3
%10 = load i32, i32* %4
%11 = load i8*, i8** %5
%12 = load i64, i64* %6
%13 = call i32 @send(i32 %10, i8* %11, i64 %12, i32 0)
store i32 %13, i32* %7
br label %14
14: ; preds = %9
%15 = load i32, i32* %7
%16 = icmp eq i32 -1, %15
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i64, i64* @errno
%19 = load i64, i64* @EINTR
%20 = icmp eq i64 %18, %19
br label %21
21: ; preds = %17, %14
%22 = phi i1 [ false, %14 ], [ %20, %17 ]
br i1 %22, label %9, label %23
23: ; preds = %21
%24 = load i32, i32* %7
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 0, i32* %8
br label %27
27: ; preds = %26, %23
%28 = load i32, i32* %8
ret i32 %28
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @send_safe(i32 %0, i8* %1, i64 %2) {
br label %4
4: ; preds = %4, %3
%5 = tail call i32 @send(i32 %0, i8* %1, i64 %2, i32 0)
%6 = icmp eq i32 %5, -1
%7 = load i64, i64* @errno
%8 = load i64, i64* @EINTR
%9 = icmp eq i64 %7, %8
%10 = select i1 %6, i1 %9, i1 false
br i1 %10, label %4, label %11
11: ; preds = %4
%12 = ashr i32 %5, 31
ret i32 %12
}