#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 */

/* Variables and functions */
int errno;
long syscall(long, long, long, long, long, long, long);
long __sulong_posix_syscall(long number, long rdi, long rsi, long rdx, long r10,
                            long r8, long r9) {
  {
    int native_errno = errno;
    long result = syscall(number, rdi, rsi, rdx, r10, r8, r9);
    if (result == (long)-1) {
      result = (long)(long)-errno;
    }
    errno = native_errno;
    return result;
  };
}


x86 assembly (clang, -O0):
<__sulong_posix_syscall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    0x10(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <syscall@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0xffffffffffffffff,-0x40(%rbp)
jne    1185 <__sulong_posix_syscall+0x75>
xor    %eax,%eax
mov    0x2e63(%rip),%rcx
sub    (%rcx),%eax
cltq
mov    %rax,-0x40(%rbp)
mov    -0x34(%rbp),%ecx
mov    0x2e51(%rip),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__sulong_posix_syscall>:
push   %rbp
push   %rbx
push   %rax
mov    0x20(%rsp),%rax
mov    0x2ec1(%rip),%rbx
mov    (%rbx),%ebp
mov    %rax,(%rsp)
call   1030 <syscall@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):
@errno = global i32 0
define i64 @__sulong_posix_syscall(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5, i64 %6) {
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
%16 = alloca i64
store i64 %0, i64* %8
store i64 %1, i64* %9
store i64 %2, i64* %10
store i64 %3, i64* %11
store i64 %4, i64* %12
store i64 %5, i64* %13
store i64 %6, i64* %14
%17 = load i32, i32* @errno
store i32 %17, i32* %15
%18 = load i64, i64* %8
%19 = load i64, i64* %9
%20 = load i64, i64* %10
%21 = load i64, i64* %11
%22 = load i64, i64* %12
%23 = load i64, i64* %13
%24 = load i64, i64* %14
%25 = call i64 @syscall(i64 %18, i64 %19, i64 %20, i64 %21, i64 %22, i64 %23, i64 %24)
store i64 %25, i64* %16
%26 = load i64, i64* %16
%27 = icmp eq i64 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %7
%29 = load i32, i32* @errno
%30 = sub nsw i32 0, %29
%31 = sext i32 %30 to i64
store i64 %31, i64* %16
br label %32
32: ; preds = %28, %7
%33 = load i32, i32* %15
store i32 %33, i32* @errno
%34 = load i64, i64* %16
ret i64 %34
}

LLVM IR (-O2):
@errno = global i32 0
define i64 @__sulong_posix_syscall(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5, i64 %6) {
%8 = load i32, i32* @errno
%9 = tail call i64 @syscall(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5, i64 %6)
%10 = icmp eq i64 %9, -1
%11 = load i32, i32* @errno
%12 = sub nsw i32 0, %11
%13 = sext i32 %12 to i64
%14 = select i1 %10, i64 %13, i64 %9
store i32 %8, i32* @errno
ret i64 %14
}