#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 */
struct sockaddr {
  int dummy;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int errno;
scalar_t__ sendto(int, void const *, size_t, int, struct sockaddr const *,
                  int /*<<< orphan*/);
ssize_t __sulong_posix_sendto(int socket, const void *message, size_t length,
                              int flags, const struct sockaddr *dest_addr,
                              socklen_t dest_len) {
  {
    int native_errno = errno;
    ssize_t result =
        sendto(socket, message, length, flags, dest_addr, dest_len);
    if (result == (ssize_t)-1) {
      result = (ssize_t)(long)-errno;
    }
    errno = native_errno;
    return result;
  };
}


x86 assembly (clang, -O0):
<__sulong_posix_sendto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
call   1030 <sendto@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0xffffffffffffffff,-0x38(%rbp)
jne    1175 <__sulong_posix_sendto+0x65>
xor    %eax,%eax
mov    0x2e73(%rip),%rcx
sub    (%rcx),%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%ecx
mov    0x2e61(%rip),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__sulong_posix_sendto>:
push   %rbp
push   %rbx
push   %rax
mov    0x2ec6(%rip),%rbx
mov    (%rbx),%ebp
call   1030 <sendto@plt>
movslq (%rbx),%rcx
neg    %rcx
cmp    $0xffffffffffffffff,%rax
cmove  %rcx,%rax
mov    %ebp,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@errno = global i32 0
define i64 @__sulong_posix_sendto(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr* %4, i32 %5) {
%7 = load i32, i32* @errno
%8 = tail call i64 @sendto(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr* %4, i32 %5)
%9 = icmp eq i64 %8, -1
%10 = load i32, i32* @errno
%11 = sub nsw i32 0, %10
%12 = sext i32 %11 to i64
%13 = select i1 %9, i64 %12, i64 %8
store i32 %7, i32* @errno
ret i64 %13
}