#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;
int /*<<< orphan*/ PROT_EXEC;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int mprotect(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int err = mprotect(0, 8193, PROT_EXEC);
  if (err == -1 && errno == ENOSYS)
    printf("ENOSYS\n");
  printf("xyzzy\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
mov    $0x2001,%esi
call   1040 <mprotect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    118e <main+0x5e>
mov    0x2e61(%rip),%rax
mov    (%rax),%rax
mov    0x2e6f(%rip),%rcx
cmp    (%rcx),%rax
jne    118e <main+0x5e>
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ea8(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
mov    $0x2001,%esi
call   1040 <mprotect@plt>
cmp    $0xffffffff,%eax
jne    116d <main+0x3d>
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
mov    0x2e8c(%rip),%rcx
cmp    (%rcx),%rax
jne    116d <main+0x3d>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@PROT_EXEC = global i32 0
@errno = global i64 0
@ENOSYS = global i64 0
@.str = [8 x i8] c"ENOSYS\0A\00"
@.str.1 = [7 x i8] c"xyzzy\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @PROT_EXEC
%8 = call i32 @mprotect(i32 0, i32 8193, i32 %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = load i64, i64* @ENOSYS
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %11, %2
%18 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@PROT_EXEC = global i32 0
@errno = global i64 0
@ENOSYS = global i64 0
@str = [6 x i8] c"xyzzy\00"
@str.2 = [7 x i8] c"ENOSYS\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @PROT_EXEC
%4 = tail call i32 @mprotect(i32 0, i32 8193, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENOSYS
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %6, %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 0)
unreachable
}