#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*/ printf(char *, ...);
int /*<<< orphan*/ split_every_four(char const *, size_t);
size_t strlen(char const *);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("Usage: %s <shellcode>\n", argv[0]);
    return -1;
  }
  const char *reversed_shellcode = argv[1];
  size_t len = strlen(reversed_shellcode);
  if ((len % 2) != 0) {
    printf("Shellcode length MUST be a multiple of 2\n");
    return -1;
  }
  split_every_four(reversed_shellcode, len);
  return 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)
cmpl   $0x2,-0x8(%rbp)
je     1171 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <main+0x9a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11b6 <main+0x86>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <main+0x9a>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <split_every_four@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    1165 <main+0x25>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   $0x1,%al
jne    1178 <main+0x38>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <split_every_four@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    (%rsi),%rsi
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1184 <main+0x44>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Usage: %s <shellcode>\0A\00"
@.str.1 = [42 x i8] c"Shellcode length MUST be a multiple of 2\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 -1, i32* %3
br label %30
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = urem i64 %21, 2
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
26: ; preds = %15
%27 = load i8*, i8** %6
%28 = load i64, i64* %7
%29 = call i32 @split_every_four(i8* %27, i64 %28)
store i32 0, i32* %3
br label %30
30: ; preds = %26, %24, %10
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [23 x i8] c"Usage: %s <shellcode>\0A\00"
@str = [41 x i8] c"Shellcode length MUST be a multiple of 2\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %17
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strlen(i8* dereferenceable(1) %9)
%11 = and i64 %10, 1
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %17
15: ; preds = %7
%16 = tail call i32 @split_every_four(i8* %9, i64 %10)
br label %17
17: ; preds = %13, %15, %4
%18 = phi i32 [ -1, %4 ], [ -1, %13 ], [ 0, %15 ]
ret i32 %18
}