#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 */
scalar_t__ ENOSYS;
scalar_t__ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned long, ...);
int /*<<< orphan*/ stdout;
long syscall(unsigned long, int /*<<< orphan*/, int /*<<< orphan*/,
             int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
             int /*<<< orphan*/);
void check_enosys(unsigned long nr, bool *ok) {
  fflush(stdout);
  long ret = syscall(nr, 0, 0, 0, 0, 0, 0);
  if (ret == 0) {
    printf("[FAIL]\tsyscall %lu succeeded, but it should have failed\n", nr);
    *ok = false;
  } else if (errno != ENOSYS) {
    printf("[FAIL]\tsyscall %lu had error code %d, but it should have reported "
           "ENOSYS\n",
           nr, errno);
    *ok = false;
  }
}


x86 assembly (clang, -O0):
<check_enosys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x8(%rbp),%rdi
xor    %r9d,%r9d
mov    %r9d,%esi
mov    %r9d,%edx
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   1040 <syscall@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119d <check_enosys+0x6d>
mov    -0x8(%rbp),%rsi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    11e2 <check_enosys+0xb2>
mov    0x2e34(%rip),%rax
mov    (%rax),%rax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
je     11dd <check_enosys+0xad>
mov    -0x8(%rbp),%rsi
mov    0x2e16(%rip),%rax
mov    (%rax),%rdx
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    11e2 <check_enosys+0xb2>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_enosys>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
movl   $0x0,(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <syscall@plt>
test   %rax,%rax
je     1191 <check_enosys+0x61>
mov    0x2e69(%rip),%rax
mov    (%rax),%rdx
mov    0x2e6f(%rip),%rax
cmp    (%rax),%rdx
je     11a9 <check_enosys+0x79>
lea    0xeb4(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a2 <check_enosys+0x72>
lea    0xe68(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [57 x i8] c"[FAIL]\09syscall %lu succeeded, but it should have failed\0A\00"
@errno = global i64 0
@ENOSYS = global i64 0
@.str.1 = [74 x i8] c"[FAIL]\09syscall %lu had error code %d, but it should have reported ENOSYS\0A\00"
define void @check_enosys(i64 %0, i32* %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i64
store i64 %0, i64* %3
store i32* %1, i32** %4
%6 = load i32, i32* @stdout
%7 = call i32 @fflush(i32 %6)
%8 = load i64, i64* %3
%9 = call i64 @syscall(i64 %8, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0)
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i64, i64* %3
%14 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i64 %13)
%15 = load i32*, i32** %4
store i32 0, i32* %15
br label %26
16: ; preds = %2
%17 = load i64, i64* @errno
%18 = load i64, i64* @ENOSYS
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i64, i64* %3
%22 = load i64, i64* @errno
%23 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0), i64 %21, i64 %22)
%24 = load i32*, i32** %4
store i32 0, i32* %24
br label %25
25: ; preds = %20, %16
br label %26
26: ; preds = %25, %12
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [57 x i8] c"[FAIL]\09syscall %lu succeeded, but it should have failed\0A\00"
@errno = global i64 0
@ENOSYS = global i64 0
@.str.1 = [74 x i8] c"[FAIL]\09syscall %lu had error code %d, but it should have reported ENOSYS\0A\00"
define void @check_enosys(i64 %0, i32* nocapture writeonly %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 @fflush(i32 %3)
%5 = tail call i64 @syscall(i64 %0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i64 %0)
br label %15
9: ; preds = %2
%10 = load i64, i64* @errno
%11 = load i64, i64* @ENOSYS
%12 = icmp eq i64 %10, %11
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0), i64 %0, i64 %10)
br label %15
15: ; preds = %7, %13
store i32 0, i32* %1
br label %16
16: ; preds = %15, %9
ret void
}