#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  char v[500];
  char v2[100];
  FILE *ft;
  system("clear");
  printf("\n");
  printf("\t////////////////////////////////////////////////////\n");
  printf("\t///////// Binary to Shellcode Converter ////////////\n");
  printf("\t////////////////////////////////////////////////////\n");
  printf("\n");
  if (argc == 1) {
    printf("Usage: %s InputBinaryFile\n", argv[0]);
    exit(0);
  }
  ft = fopen(argv[1], "r");
  if (!ft) {
    printf("Unable to open file: %s\n", argv[1]);
    exit(-1);
  }
  fclose(ft);
  printf("\t\t\tBinary Name = %s\n", argv[1]);
  printf("    size in bytes = \n");
  snprintf(v2, 100, "size %s | grep  '[0-9]' | cut -f4 ", argv[1]);
  snprintf(v, 500,
           "objdump -D %s |grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut "
           "-f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ "
           "/\\\\x/g'|paste -d '' -s",
           argv[1]);
  system(v2);
  printf("\n");
  printf("    Shellcode = \n\n");
  system(v);
  printf("\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x290,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rdi
call   1040 <system@plt>
lea    0x1008(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xfd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11f1 <main+0x91>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe04(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x288(%rbp)
cmpq   $0x0,-0x288(%rbp)
jne    123a <main+0xda>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x288(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x280(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x64,%esi
lea    0xe4e(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x1f4,%esi
lea    0xe51(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x280(%rbp),%rdi
call   1040 <system@plt>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x210(%rbp),%rdi
call   1040 <system@plt>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
add    $0x290,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x270,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xe68(%rip),%rdi
call   1060 <system@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xf87(%rip),%rbp
mov    %rbp,%rdi
call   1040 <puts@plt>
lea    0xf42(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    $0x1,%r14d
je     129a <main+0x11a>
mov    0x8(%rbx),%rdi
lea    0xe1b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12b2 <main+0x132>
mov    %rax,%rdi
call   1050 <fclose@plt>
mov    0x8(%rbx),%rsi
lea    0xe30(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xf53(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rbx),%rcx
lea    0xe27(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x64,%esi
call   1080 <snprintf@plt>
mov    0x8(%rbx),%rcx
lea    0xe2f(%rip),%rdx
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1f4,%esi
call   1080 <snprintf@plt>
mov    %rbp,%rdi
call   1060 <system@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xf12(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
add    $0x270,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xd62(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x8(%rbx),%rsi
lea    0xd64(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"clear\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [55 x i8] c"\09////////////////////////////////////////////////////\0A\00"
@.str.3 = [55 x i8] c"\09///////// Binary to Shellcode Converter ////////////\0A\00"
@.str.4 = [27 x i8] c"Usage: %s InputBinaryFile\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [25 x i8] c"Unable to open file: %s\0A\00"
@.str.7 = [21 x i8] c"\09\09\09Binary Name = %s\0A\00"
@.str.8 = [22 x i8] c" size in bytes = \0A\00"
@.str.9 = [35 x i8] c"size %s | grep '[0-9]' | cut -f4 \00"
@.str.10 = [141 x i8] c"objdump -D %s |grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\09' ' '|sed 's/ $//g'|sed 's/ /\\\\x/g'|paste -d '' -s\00"
@.str.11 = [19 x i8] c" Shellcode = \0A\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 [500 x i8]
%7 = alloca [100 x i8]
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %27, i32** %8
%28 = load i32*, i32** %8
%29 = icmp ne i32* %28, null
br i1 %29, label %36, label %30
30: ; preds = %23
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %23
%37 = load i32*, i32** %8
%38 = call i32 @fclose(i32* %37)
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 @snprintf(i8* %44, i32 100, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i8* %47)
%49 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = call i32 @snprintf(i8* %49, i32 500, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.10, i64 0, i64 0), i8* %52)
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%55 = call i32 @system(i8* %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
%58 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%59 = call i32 @system(i8* %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%61 = load i32, i32* @EXIT_SUCCESS
ret i32 %61
}

LLVM IR (-O2):
@.str = [6 x i8] c"clear\00"
@.str.4 = [27 x i8] c"Usage: %s InputBinaryFile\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [25 x i8] c"Unable to open file: %s\0A\00"
@.str.7 = [21 x i8] c"\09\09\09Binary Name = %s\0A\00"
@.str.9 = [35 x i8] c"size %s | grep '[0-9]' | cut -f4 \00"
@.str.10 = [141 x i8] c"objdump -D %s |grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\09' ' '|sed 's/ $//g'|sed 's/ /\\\\x/g'|paste -d '' -s\00"
@EXIT_SUCCESS = global i32 0
@str.12 = [54 x i8] c"\09///////// Binary to Shellcode Converter ////////////\00"
@str.13 = [54 x i8] c"\09////////////////////////////////////////////////////\00"
@str.14 = [21 x i8] c" size in bytes = \00"
@str.15 = [18 x i8] c" Shellcode = \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [500 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @putchar(i32 10)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.13, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.12, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.13, i64 0, i64 0))
%12 = tail call i32 @putchar(i32 10)
%13 = icmp eq i32 %0, 1
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8*, i8** %1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i8*, i8** %19
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %24)
%26 = tail call i32 @exit(i32 -1)
unreachable
27: ; preds = %18
%28 = tail call i32 @fclose(i32* %21)
%29 = load i8*, i8** %19
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %29)
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.14, i64 0, i64 0))
%32 = load i8*, i8** %19
%33 = call i32 @snprintf(i8* %6, i32 100, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %19
%35 = call i32 @snprintf(i8* %5, i32 500, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.10, i64 0, i64 0), i8* %34)
%36 = call i32 @system(i8* %6)
%37 = call i32 @putchar(i32 10)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.15, i64 0, i64 0))
%39 = call i32 @system(i8* %5)
%40 = call i32 @putchar(i32 10)
%41 = load i32, i32* @EXIT_SUCCESS
ret i32 %41
}