#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 */
typedef struct TYPE_9__ TYPE_3__;
typedef struct TYPE_8__ TYPE_2__;
typedef struct TYPE_7__ TYPE_1__;

/* Type definitions */
struct TYPE_8__ {
  scalar_t__ gregs;
};
struct TYPE_7__ {
  unsigned char *ss_sp;
};
struct TYPE_9__ {
  TYPE_2__ uc_mcontext;
  scalar_t__ uc_link;
  TYPE_1__ uc_stack;
};
typedef TYPE_3__ ucontext_t;

/* Variables and functions */
int MAP_ANONYMOUS;
int MAP_PRIVATE;
unsigned long NGREG;
int /*<<< orphan*/ O_RDONLY;
int PROT_EXEC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fgets(unsigned char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ getcontext(TYPE_3__ *);
int getpagesize();
int /*<<< orphan*/ makecontext(TYPE_3__ *, void (*)(), int /*<<< orphan*/);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
unsigned char *mmap(int /*<<< orphan*/, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ mprotect(unsigned char *, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ read(int, ...);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ setcontext(TYPE_3__ *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main() {
  setbuf(stdout, NULL);
  unsigned char seen[257], *p, *buf, *stack;
  int random = open("/dev/urandom", O_RDONLY);
  memset(seen, 0, sizeof seen);
  buf = mmap(0, (0x4096 & ~(getpagesize() - 1)), PROT_READ | PROT_WRITE,
             MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  puts("Shellcode?");
  fgets(buf, (0x4096 & ~(getpagesize() - 1)), stdin);
  for (p = buf; *p != '\n'; p++) {
    seen[256] += !seen[*p];
    seen[*p] |= 1;
  }
  if (seen[256] > 7) {
    puts("Shellcode too diverse.");
    _exit(1);
  } else {
    mprotect(buf, (0x4096 & ~(getpagesize() - 1)), PROT_READ | PROT_EXEC);
    stack = mmap(0, (0x4096 & ~(getpagesize() - 1)),
                 PROT_READ | PROT_WRITE | PROT_EXEC,
                 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    read(random, stack, (0x4096 & ~(getpagesize() - 1)) - sizeof(ucontext_t));
    stack += (0x4096 & ~(getpagesize() - 1));
    stack -= sizeof(ucontext_t);
    ucontext_t *c = (ucontext_t *)stack;
    getcontext(c);
    c->uc_stack.ss_sp = stack;
    c->uc_link = 0;
    makecontext(c, (void (*)(void))buf, 0);
    unsigned long *p, i = 0;
    for (p = (unsigned long *)c->uc_mcontext.gregs; i < NGREG; i++) {
      if (i != 15 && i != 16) {
        read(random, &p[i], sizeof p[i]);
      }
    }
    close(random);
    setcontext((ucontext_t *)c);
    _exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <setbuf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
lea    0xdec(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,-0x12c(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1070 <memset@plt>
mov    $0x0,%al
call   10f0 <getpagesize@plt>
mov    %eax,%esi
sub    $0x1,%esi
xor    $0xffffffff,%esi
and    $0x4096,%esi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
mov    0x2d61(%rip),%rax
or     (%rax),%edx
mov    0x2d48(%rip),%rax
mov    (%rax),%ecx
mov    0x2d67(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1050 <mmap@plt>
mov    %rax,-0x120(%rbp)
lea    0xd83(%rip),%rdi
call   1040 <puts@plt>
mov    -0x120(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    $0x0,%al
call   10f0 <getpagesize@plt>
mov    -0x150(%rbp),%rdi
mov    %eax,%esi
sub    $0x1,%esi
xor    $0xffffffff,%esi
and    $0x4096,%esi
mov    0x2d18(%rip),%rax
mov    (%rax),%edx
call   10a0 <fgets@plt>
mov    -0x120(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xa,%eax
je     1340 <main+0x160>
mov    -0x118(%rbp),%rax
movzbl (%rax),%eax
cmpb   $0x0,-0x110(%rbp,%rax,1)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%ecx
movzbl -0x10(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x10(%rbp)
mov    -0x118(%rbp),%rax
movzbl (%rax),%eax
movzbl -0x110(%rbp,%rax,1),%ecx
ff
or     $0x1,%ecx
mov    %cl,-0x110(%rbp,%rax,1)
mov    -0x118(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x118(%rbp)
jmp    12d5 <main+0xf5>
movzbl -0x10(%rbp),%eax
cmp    $0x7,%eax
jle    1363 <main+0x183>
lea    0xcc4(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    -0x120(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    $0x0,%al
call   10f0 <getpagesize@plt>
mov    -0x168(%rbp),%rdi
mov    %eax,%esi
sub    $0x1,%esi
xor    $0xffffffff,%esi
and    $0x4096,%esi
mov    0x2c64(%rip),%rax
mov    (%rax),%edx
mov    0x2c2b(%rip),%rax
or     (%rax),%edx
call   10d0 <mprotect@plt>
mov    $0x0,%al
call   10f0 <getpagesize@plt>
mov    %eax,%esi
sub    $0x1,%esi
xor    $0xffffffff,%esi
and    $0x4096,%esi
mov    0x2c38(%rip),%rax
mov    (%rax),%edx
mov    0x2bef(%rip),%rax
or     (%rax),%edx
mov    0x2bf6(%rip),%rax
or     (%rax),%edx
mov    0x2bcd(%rip),%rax
mov    (%rax),%ecx
mov    0x2bec(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1050 <mmap@plt>
mov    %rax,-0x128(%rbp)
mov    -0x12c(%rbp),%eax
mov    %eax,-0x15c(%rbp)
mov    -0x128(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    $0x0,%al
call   10f0 <getpagesize@plt>
mov    -0x15c(%rbp),%edi
mov    -0x158(%rbp),%rsi
sub    $0x1,%eax
xor    $0xffffffff,%eax
and    $0x4096,%eax
movslq %eax,%rdx
sub    $0x18,%rdx
mov    $0x0,%al
call   1090 <read@plt>
mov    $0x0,%al
call   10f0 <getpagesize@plt>
mov    %eax,%ecx
sub    $0x1,%ecx
xor    $0xffffffff,%ecx
and    $0x4096,%ecx
mov    -0x128(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rax
add    $0xffffffffffffffe8,%rax
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rdi
call   1100 <getcontext@plt>
mov    -0x128(%rbp),%rcx
mov    -0x138(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x138(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x138(%rbp),%rdi
mov    -0x120(%rbp),%rsi
xor    %edx,%edx
call   10c0 <makecontext@plt>
movq   $0x0,-0x148(%rbp)
mov    -0x138(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x140(%rbp)
mov    -0x148(%rbp),%rax
mov    0x2a9e(%rip),%rcx
cmp    (%rcx),%rax
jae    1562 <main+0x382>
cmpq   $0xf,-0x148(%rbp)
0f
je     1546 <main+0x366>
cmpq   $0x10,-0x148(%rbp)
10
je     1546 <main+0x366>
mov    -0x12c(%rbp),%edi
mov    -0x140(%rbp),%rsi
mov    -0x148(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1090 <read@plt>
jmp    154b <main+0x36b>
mov    -0x148(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x148(%rbp)
jmp    14ec <main+0x30c>
mov    -0x12c(%rbp),%edi
call   1080 <close@plt>
mov    -0x138(%rbp),%rdi
call   10b0 <setcontext@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
xor    %ebp,%ebp
mov    %ebp,%esi
call   1060 <setbuf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    0xded(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,%r13d
lea    0x10(%rsp),%rdi
mov    $0x101,%edx
mov    %ebp,%esi
call   1070 <memset@plt>
mov    %ebp,%ebx
mov    %ebp,%eax
call   10f0 <getpagesize@plt>
neg    %eax
mov    %eax,%esi
and    $0x4096,%esi
mov    0x2db2(%rip),%r12
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
or     (%r12),%edx
mov    0x2d4e(%rip),%rdi
mov    0x2d6f(%rip),%rax
mov    (%rax),%ecx
or     (%rdi),%ecx
mov    $0xffffffff,%r8d
mov    %ebp,%edi
mov    %ebp,%r9d
call   1050 <mmap@plt>
mov    %rax,%r14
lea    0xd8e(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%eax
call   10f0 <getpagesize@plt>
neg    %eax
mov    %eax,%esi
and    $0x4096,%esi
mov    0x2d3c(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   10a0 <fgets@plt>
mov    (%r14),%dl
mov    0x110(%rsp),%cl
cmp    $0xa,%dl
jne    12b9 <main+0xd9>
mov    %ecx,%ebx
jmp    12ec <main+0x10c>
lea    0x1(%r14),%rax
nopl   (%rax)
movzbl %dl,%edx
cmpb   $0x1,0x10(%rsp,%rdx,1)
adc    $0x0,%cl
mov    %cl,0x110(%rsp)
movzbl -0x1(%rax),%edx
orb    $0x1,0x10(%rsp,%rdx,1)
movzbl (%rax),%esi
add    $0x1,%rax
mov    %ecx,%ebx
mov    %esi,%edx
cmp    $0xa,%sil
jne    12c0 <main+0xe0>
cmp    $0x8,%bl
jb     1307 <main+0x127>
lea    0xd20(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    %r12,%rbp
xor    %eax,%eax
mov    %eax,%r15d
call   10f0 <getpagesize@plt>
neg    %eax
mov    %eax,%esi
and    $0x4096,%esi
mov    0x2ca3(%rip),%rbx
mov    (%rbx),%edx
or     (%r12),%edx
mov    %r14,%rdi
call   10d0 <mprotect@plt>
mov    %r15d,%eax
call   10f0 <getpagesize@plt>
neg    %eax
mov    %eax,%esi
mov    0x2c72(%rip),%rax
mov    (%rax),%eax
or     (%r12),%eax
mov    %eax,%edx
or     (%rbx),%edx
and    $0x4096,%esi
mov    0x2c73(%rip),%rax
mov    (%rax),%ecx
mov    0x2c42(%rip),%rax
or     (%rax),%ecx
mov    $0xffffffff,%r8d
xor    %edi,%edi
mov    %edi,%r9d
call   1050 <mmap@plt>
mov    %rax,%r12
mov    %r15d,%eax
call   10f0 <getpagesize@plt>
neg    %eax
and    $0x4096,%eax
lea    -0x18(%rax),%rdx
mov    %r13d,%edi
mov    %r12,%rsi
mov    %r15d,%eax
call   1090 <read@plt>
mov    %r15d,%eax
call   10f0 <getpagesize@plt>
neg    %eax
and    $0x4096,%eax
mov    %eax,%ebx
lea    (%r12,%rbx,1),%rbp
add    $0xffffffffffffffe8,%rbp
mov    %rbp,%rdi
call   1100 <getcontext@plt>
mov    %rbp,-0x8(%r12,%rbx,1)
movq   $0x0,-0x10(%r12,%rbx,1)
mov    %rbp,0x8(%rsp)
mov    %rbp,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   10c0 <makecontext@plt>
mov    0x2bb4(%rip),%r14
mov    (%r14),%rax
test   %rax,%rax
jne    1405 <main+0x225>
mov    %r13d,%edi
call   1080 <close@plt>
mov    0x8(%rsp),%rdi
call   10b0 <setcontext@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    -0x18(%r12,%rbx,1),%rbx
xor    %r12d,%r12d
mov    %r12d,%r15d
mov    $0x8,%ebp
jmp    1436 <main+0x256>
nopw   0x0(%rax,%rax,1)
mov    %rax,%rcx
mov    %r15,%rdx
add    $0x1,%rdx
add    $0x8,%rbx
mov    %rdx,%r15
cmp    %rax,%rdx
jae    13ec <main+0x20c>
lea    -0x11(%r15),%rcx
cmp    $0xfffffffffffffffd,%rcx
ja     1420 <main+0x240>
mov    %r12d,%eax
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1090 <read@plt>
mov    (%r14),%rax
jmp    1420 <main+0x240>

LLVM IR (-O0):
%struct.TYPE_9__ = type { %struct.TYPE_8__, i64, %struct.TYPE_7__ }
%struct.TYPE_8__ = type { i64 }
%struct.TYPE_7__ = type { i8* }
@stdout = global i32 0
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str.1 = [11 x i8] c"Shellcode?\00"
@stdin = global i32 0
@.str.2 = [23 x i8] c"Shellcode too diverse.\00"
@PROT_EXEC = global i32 0
@NGREG = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [257 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.TYPE_9__*
%8 = alloca i64*
%9 = alloca i64
store i32 0, i32* %1
%10 = load i32, i32* @stdout
%11 = call i32 @setbuf(i32 %10, i32* null)
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %6
%14 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 257)
%16 = call i32 (...) @getpagesize()
%17 = sub nsw i32 %16, 1
%18 = xor i32 %17, -1
%19 = and i32 16534, %18
%20 = load i32, i32* @PROT_READ
%21 = load i32, i32* @PROT_WRITE
%22 = or i32 %20, %21
%23 = load i32, i32* @MAP_PRIVATE
%24 = load i32, i32* @MAP_ANONYMOUS
%25 = or i32 %23, %24
%26 = call i8* @mmap(i32 0, i32 %19, i32 %22, i32 %25, i32 -1, i32 0)
store i8* %26, i8** %4
%27 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%28 = load i8*, i8** %4
%29 = call i32 (...) @getpagesize()
%30 = sub nsw i32 %29, 1
%31 = xor i32 %30, -1
%32 = and i32 16534, %31
%33 = load i32, i32* @stdin
%34 = call i32 @fgets(i8* %28, i32 %32, i32 %33)
%35 = load i8*, i8** %4
store i8* %35, i8** %3
br label %36
36: ; preds = %63, %0
%37 = load i8*, i8** %3
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = icmp ne i32 %39, 10
br i1 %40, label %41, label %66
41: ; preds = %36
%42 = load i8*, i8** %3
%43 = load i8, i8* %42
%44 = zext i8 %43 to i64
%45 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = icmp ne i8 %46, 0
%48 = xor i1 %47, true
%49 = zext i1 %48 to i32
%50 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 256
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = add nsw i32 %52, %49
%54 = trunc i32 %53 to i8
store i8 %54, i8* %50
%55 = load i8*, i8** %3
%56 = load i8, i8* %55
%57 = zext i8 %56 to i64
%58 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = or i32 %60, 1
%62 = trunc i32 %61 to i8
store i8 %62, i8* %58
br label %63
63: ; preds = %41
%64 = load i8*, i8** %3
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %3
br label %36
66: ; preds = %36
%67 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 256
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = icmp sgt i32 %69, 7
br i1 %70, label %71, label %74
71: ; preds = %66
%72 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%73 = call i32 @_exit(i32 1)
unreachable
74: ; preds = %66
%75 = load i8*, i8** %4
%76 = call i32 (...) @getpagesize()
%77 = sub nsw i32 %76, 1
%78 = xor i32 %77, -1
%79 = and i32 16534, %78
%80 = load i32, i32* @PROT_READ
%81 = load i32, i32* @PROT_EXEC
%82 = or i32 %80, %81
%83 = call i32 @mprotect(i8* %75, i32 %79, i32 %82)
%84 = call i32 (...) @getpagesize()
%85 = sub nsw i32 %84, 1
%86 = xor i32 %85, -1
%87 = and i32 16534, %86
%88 = load i32, i32* @PROT_READ
%89 = load i32, i32* @PROT_WRITE
%90 = or i32 %88, %89
%91 = load i32, i32* @PROT_EXEC
%92 = or i32 %90, %91
%93 = load i32, i32* @MAP_PRIVATE
%94 = load i32, i32* @MAP_ANONYMOUS
%95 = or i32 %93, %94
%96 = call i8* @mmap(i32 0, i32 %87, i32 %92, i32 %95, i32 -1, i32 0)
store i8* %96, i8** %5
%97 = load i32, i32* %6
%98 = load i8*, i8** %5
%99 = call i32 (...) @getpagesize()
%100 = sub nsw i32 %99, 1
%101 = xor i32 %100, -1
%102 = and i32 16534, %101
%103 = sext i32 %102 to i64
%104 = sub i64 %103, 24
%105 = call i32 (i32, ...) @read(i32 %97, i8* %98, i64 %104)
%106 = call i32 (...) @getpagesize()
%107 = sub nsw i32 %106, 1
%108 = xor i32 %107, -1
%109 = and i32 16534, %108
%110 = load i8*, i8** %5
%111 = sext i32 %109 to i64
%112 = getelementptr inbounds i8, i8* %110, i64 %111
store i8* %112, i8** %5
%113 = load i8*, i8** %5
%114 = getelementptr inbounds i8, i8* %113, i64 -24
store i8* %114, i8** %5
%115 = load i8*, i8** %5
%116 = bitcast i8* %115 to %struct.TYPE_9__*
store %struct.TYPE_9__* %116, %struct.TYPE_9__** %7
%117 = load %struct.TYPE_9__*, %struct.TYPE_9__** %7
%118 = call i32 @getcontext(%struct.TYPE_9__* %117)
%119 = load i8*, i8** %5
%120 = load %struct.TYPE_9__*, %struct.TYPE_9__** %7
%121 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %120, i32 0, i32 2
%122 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %121, i32 0, i32 0
store i8* %119, i8** %122
%123 = load %struct.TYPE_9__*, %struct.TYPE_9__** %7
%124 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %123, i32 0, i32 1
store i64 0, i64* %124
%125 = load %struct.TYPE_9__*, %struct.TYPE_9__** %7
%126 = load i8*, i8** %4
%127 = bitcast i8* %126 to void ()*
%128 = bitcast void ()* %127 to void (...)*
%129 = call i32 @makecontext(%struct.TYPE_9__* %125, void (...)* %128, i32 0)
store i64 0, i64* %9
%130 = load %struct.TYPE_9__*, %struct.TYPE_9__** %7
%131 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %130, i32 0, i32 0
%132 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %131, i32 0, i32 0
%133 = load i64, i64* %132
%134 = inttoptr i64 %133 to i64*
store i64* %134, i64** %8
br label %135
135: ; preds = %152, %74
%136 = load i64, i64* %9
%137 = load i64, i64* @NGREG
%138 = icmp ult i64 %136, %137
br i1 %138, label %139, label %155
139: ; preds = %135
%140 = load i64, i64* %9
%141 = icmp ne i64 %140, 15
br i1 %141, label %142, label %151
142: ; preds = %139
%143 = load i64, i64* %9
%144 = icmp ne i64 %143, 16
br i1 %144, label %145, label %151
145: ; preds = %142
%146 = load i32, i32* %6
%147 = load i64*, i64** %8
%148 = load i64, i64* %9
%149 = getelementptr inbounds i64, i64* %147, i64 %148
%150 = call i32 (i32, ...) @read(i32 %146, i64* %149, i64 8)
br label %151
151: ; preds = %145, %142, %139
br label %152
152: ; preds = %151
%153 = load i64, i64* %9
%154 = add i64 %153, 1
store i64 %154, i64* %9
br label %135
155: ; preds = %135
%156 = load i32, i32* %6
%157 = call i32 @close(i32 %156)
%158 = load %struct.TYPE_9__*, %struct.TYPE_9__** %7
%159 = call i32 @setcontext(%struct.TYPE_9__* %158)
%160 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.TYPE_9__ = type { %struct.TYPE_8__, i64, %struct.TYPE_7__ }
%struct.TYPE_8__ = type { i64 }
%struct.TYPE_7__ = type { i8* }
@stdout = global i32 0
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str.1 = [11 x i8] c"Shellcode?\00"
@stdin = global i32 0
@.str.2 = [23 x i8] c"Shellcode too diverse.\00"
@PROT_EXEC = global i32 0
@NGREG = global i64 0
define i32 @main() {
%1 = alloca [257 x i8]
%2 = load i32, i32* @stdout
%3 = call i32 @setbuf(i32 %2, i32* null)
%4 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @memset(i8* %4, i32 0, i32 257)
%8 = call i32 (...) @getpagesize()
%9 = sub i32 0, %8
%10 = and i32 %9, 16534
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @PROT_WRITE
%13 = or i32 %12, %11
%14 = load i32, i32* @MAP_PRIVATE
%15 = load i32, i32* @MAP_ANONYMOUS
%16 = or i32 %15, %14
%17 = call i8* @mmap(i32 0, i32 %10, i32 %13, i32 %16, i32 -1, i32 0)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 (...) @getpagesize()
%20 = sub i32 0, %19
%21 = and i32 %20, 16534
%22 = load i32, i32* @stdin
%23 = call i32 @fgets(i8* %17, i32 %21, i32 %22)
%24 = load i8, i8* %17
%25 = icmp eq i8 %24, 10
%26 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 256
%27 = load i8, i8* %26
br i1 %25, label %46, label %28
28: ; preds = %0, %28
%29 = phi i8 [ %37, %28 ], [ %27, %0 ]
%30 = phi i8 [ %44, %28 ], [ %24, %0 ]
%31 = phi i8* [ %43, %28 ], [ %17, %0 ]
%32 = zext i8 %30 to i64
%33 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
%36 = zext i1 %35 to i8
%37 = add i8 %29, %36
store i8 %37, i8* %26
%38 = load i8, i8* %31
%39 = zext i8 %38 to i64
%40 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = or i8 %41, 1
store i8 %42, i8* %40
%43 = getelementptr inbounds i8, i8* %31, i64 1
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 10
br i1 %45, label %46, label %28
46: ; preds = %28, %0
%47 = phi i8 [ %27, %0 ], [ %37, %28 ]
%48 = icmp ugt i8 %47, 7
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%51 = call i32 @_exit(i32 1)
unreachable
52: ; preds = %46
%53 = call i32 (...) @getpagesize()
%54 = sub i32 0, %53
%55 = and i32 %54, 16534
%56 = load i32, i32* @PROT_READ
%57 = load i32, i32* @PROT_EXEC
%58 = or i32 %57, %56
%59 = call i32 @mprotect(i8* %17, i32 %55, i32 %58)
%60 = call i32 (...) @getpagesize()
%61 = sub i32 0, %60
%62 = and i32 %61, 16534
%63 = load i32, i32* @PROT_READ
%64 = load i32, i32* @PROT_WRITE
%65 = or i32 %64, %63
%66 = load i32, i32* @PROT_EXEC
%67 = or i32 %65, %66
%68 = load i32, i32* @MAP_PRIVATE
%69 = load i32, i32* @MAP_ANONYMOUS
%70 = or i32 %69, %68
%71 = call i8* @mmap(i32 0, i32 %62, i32 %67, i32 %70, i32 -1, i32 0)
%72 = call i32 (...) @getpagesize()
%73 = sub i32 0, %72
%74 = and i32 %73, 16534
%75 = zext i32 %74 to i64
%76 = add nsw i64 %75, -24
%77 = call i32 (i32, ...) @read(i32 %6, i8* %71, i64 %76)
%78 = call i32 (...) @getpagesize()
%79 = sub i32 0, %78
%80 = and i32 %79, 16534
%81 = zext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %71, i64 %81
%83 = getelementptr inbounds i8, i8* %82, i64 -24
%84 = bitcast i8* %83 to %struct.TYPE_9__*
%85 = call i32 @getcontext(%struct.TYPE_9__* %84)
%86 = getelementptr inbounds i8, i8* %83, i64 16
%87 = bitcast i8* %86 to i8**
store i8* %83, i8** %87
%88 = getelementptr inbounds i8, i8* %83, i64 8
%89 = bitcast i8* %88 to i64*
store i64 0, i64* %89
%90 = bitcast i8* %17 to void (...)*
%91 = call i32 @makecontext(%struct.TYPE_9__* %84, void (...)* %90, i32 0)
%92 = bitcast i8* %83 to i64*
%93 = load i64, i64* %92
%94 = inttoptr i64 %93 to i64*
%95 = load i64, i64* @NGREG
%96 = icmp eq i64 %95, 0
br i1 %96, label %110, label %97
97: ; preds = %52, %106
%98 = phi i64 [ %107, %106 ], [ %95, %52 ]
%99 = phi i64 [ %108, %106 ], [ 0, %52 ]
%100 = add i64 %99, -17
%101 = icmp ult i64 %100, -2
br i1 %101, label %102, label %106
102: ; preds = %97
%103 = getelementptr inbounds i64, i64* %94, i64 %99
%104 = call i32 (i32, ...) @read(i32 %6, i64* %103, i64 8)
%105 = load i64, i64* @NGREG
br label %106
106: ; preds = %97, %102
%107 = phi i64 [ %98, %97 ], [ %105, %102 ]
%108 = add nuw i64 %99, 1
%109 = icmp ult i64 %108, %107
br i1 %109, label %97, label %110
110: ; preds = %106, %52
%111 = call i32 @close(i32 %6)
%112 = call i32 @setcontext(%struct.TYPE_9__* %84)
%113 = call i32 @_exit(i32 0)
unreachable
}