#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 EAGAIN;
int errno;
scalar_t__ send(int, char const *, int, int /*<<< orphan*/);
int manos_socket_send(int fd, const char *buffer, int offset, int len,
                      int *err) {
  ssize_t rc;
  rc = send(fd, buffer + offset, len, 0);
  if (rc < 0 && (errno == EAGAIN)) {
    *err = 0;
  } else {
    *err = errno;
  }
  return rc;
}


x86 assembly (clang, -O0):
<manos_socket_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    1177 <manos_socket_send+0x67>
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%eax
jne    1177 <manos_socket_send+0x67>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
jmp    1186 <manos_socket_send+0x76>
mov    0x2e62(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<manos_socket_send>:
push   %rbp
push   %rbx
push   %rax
mov    %r8,%rbx
movslq %edx,%rax
add    %rax,%rsi
xor    %ebp,%ebp
mov    %ecx,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    0x2eb2(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e99(%rip),%rdx
cmp    (%rdx),%ecx
cmovne %ecx,%ebp
test   %rax,%rax
cmovns %ecx,%ebp
mov    %ebp,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@errno = global i32 0
@EAGAIN = global i32 0
define i32 @manos_socket_send(i32 %0, i8* %1, i32 %2, i32 %3, i32* nocapture writeonly %4) {
%6 = sext i32 %2 to i64
%7 = getelementptr inbounds i8, i8* %1, i64 %6
%8 = tail call i64 @send(i32 %0, i8* %7, i32 %3, i32 0)
%9 = icmp slt i64 %8, 0
%10 = load i32, i32* @errno
%11 = load i32, i32* @EAGAIN
%12 = icmp eq i32 %10, %11
%13 = select i1 %9, i1 %12, i1 false
%14 = select i1 %13, i32 0, i32 %10
store i32 %14, i32* %4
%15 = trunc i64 %8 to i32
ret i32 %15
}