#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 */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
int /*<<< orphan*/ MSG_NOSIGNAL;
scalar_t__ errno;
scalar_t__ send(int, void const *, size_t, int /*<<< orphan*/);
ssize_t fnet_send(int fd, const void *data, size_t len) {
  do {
    ssize_t send_num = send(fd, data, len, MSG_NOSIGNAL);
    if (send_num >= 0)
      return send_num;
    else {
      if (errno == EINTR)
        continue;
      else if (errno == EAGAIN)
        return -2;
      else
        return -1;
    }
  } while (1);
}


x86 assembly (clang, -O0):
<fnet_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    0x2e9b(%rip),%rax
mov    (%rax),%ecx
call   1030 <send@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jl     1158 <fnet_send+0x48>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ba <fnet_send+0xaa>
mov    0x2e81(%rip),%rax
mov    (%rax),%rax
mov    0x2e6f(%rip),%rcx
cmp    (%rcx),%rax
jne    1177 <fnet_send+0x67>
jmp    11ab <fnet_send+0x9b>
mov    0x2e62(%rip),%rax
mov    (%rax),%rax
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%rax
jne    119e <fnet_send+0x8e>
movq   $0xfffffffffffffffe,-0x8(%rbp)
ff
jmp    11ba <fnet_send+0xaa>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11ba <fnet_send+0xaa>
mov    $0x1,%al
test   $0x1,%al
jne    1123 <fnet_send+0x13>
jmp    11ba <fnet_send+0xaa>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnet_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2ea6(%rip),%r15
mov    0x2eaf(%rip),%r12
mov    0x2ea0(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    (%r15),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <send@plt>
test   %rax,%rax
jns    1171 <fnet_send+0x61>
mov    (%r12),%rcx
cmp    0x0(%r13),%rcx
je     1140 <fnet_send+0x30>
mov    0x2e5a(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
sete   %al
not    %rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@MSG_NOSIGNAL = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
define i64 @fnet_send(i32 %0, i8* %1, i64 %2) {
br label %4
4: ; preds = %8, %3
%5 = load i32, i32* @MSG_NOSIGNAL
%6 = tail call i64 @send(i32 %0, i8* %1, i64 %2, i32 %5)
%7 = icmp sgt i64 %6, -1
br i1 %7, label %16, label %8
8: ; preds = %4
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %4, label %12
12: ; preds = %8
%13 = load i64, i64* @EAGAIN
%14 = icmp eq i64 %9, %13
%15 = select i1 %14, i64 -2, i64 -1
br label %16
16: ; preds = %4, %12
%17 = phi i64 [ %15, %12 ], [ %6, %4 ]
ret i64 %17
}