#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 */
#define EAGAIN 129
#define EINTR 128
int /*<<< orphan*/ MSG_NOSIGNAL;
int 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 {
      switch (errno) {
      case EINTR:
        continue;
      case EAGAIN:
        return -2;
      default:
        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    0x2ea3(%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    11b5 <fnet_send+0xa5>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x80,%eax
je     1187 <fnet_send+0x77>
jmp    1174 <fnet_send+0x64>
mov    -0x2c(%rbp),%eax
sub    $0x81,%eax
je     118c <fnet_send+0x7c>
jmp    1199 <fnet_send+0x89>
jmp    11a6 <fnet_send+0x96>
movq   $0xfffffffffffffffe,-0x8(%rbp)
ff
jmp    11b5 <fnet_send+0xa5>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11b5 <fnet_send+0xa5>
mov    $0x1,%al
test   $0x1,%al
jne    1123 <fnet_send+0x13>
jmp    11b5 <fnet_send+0xa5>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnet_send>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb1(%rip),%r15
mov    0x2eb2(%rip),%r12
xchg   %ax,%ax
mov    (%r15),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <send@plt>
test   %rax,%rax
jns    1167 <fnet_send+0x57>
mov    (%r12),%ecx
cmp    $0x80,%ecx
je     1130 <fnet_send+0x20>
mov    $0xfffffffffffffffe,%rax
cmp    $0x81,%ecx
je     1167 <fnet_send+0x57>
mov    $0xffffffffffffffff,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MSG_NOSIGNAL = global i32 0
@errno = global i32 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 = %24, %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 %25
19: ; preds = %9
%20 = load i32, i32* @errno
switch i32 %20, label %23 [
i32 128, label %21
i32 129, label %22
]
21: ; preds = %19
br label %24
22: ; preds = %19
store i64 -2, i64* %4
br label %25
23: ; preds = %19
store i64 -1, i64* %4
br label %25
24: ; preds = %21
br i1 true, label %9, label %25
25: ; preds = %17, %22, %23, %24
%26 = load i64, i64* %4
ret i64 %26
}

LLVM IR (-O2):
@MSG_NOSIGNAL = global i32 0
@errno = global i32 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 %10, label %8
8: ; preds = %4
%9 = load i32, i32* @errno
switch i32 %9, label %12 [
i32 128, label %4
i32 129, label %10
]
10: ; preds = %4, %8
%11 = phi i64 [ -2, %8 ], [ %6, %4 ]
br label %12
12: ; preds = %8, %10
%13 = phi i64 [ %11, %10 ], [ -1, %8 ]
ret i64 %13
}