#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*/ enc_code;

/* Variables and functions */
int /*<<< orphan*/ _decrypt(char *, char *, int);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char key[] = "slae_3_2";
  char enc_code[] = "\xa7\x74\xfe\x21\x86\x19\x13\xec\x41\xc4\x13\xf9\xae\x99"
                    "\x20\xf6\xfa\x43\x8d\xaa\xea\xd2\xa8\x70\xd1";
  char *shell_code;
  int scSize = sizeof(enc_code) - 1;
  shell_code = malloc(scSize);
  printf("Shellcode size:%d \n", scSize);
  memcpy(shell_code, _decrypt(key, enc_code, scSize), scSize);
  int c = 0;
  printf("Decrypted text:\n");
  for (c = 0; c < scSize; c++) {
    printf("\\x%02x", (unsigned char)shell_code[c]);
  }
  printf("\n");
  int (*ret)() = (int (*)())shell_code;
  ret();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0xd(%rbp)
mov    0xea8(%rip),%al
mov    %al,-0x5(%rbp)
mov    0xed6(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed3(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xed0(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xecd(%rip),%ax
mov    %ax,-0x18(%rbp)
movl   $0x19,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x3c(%rbp),%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0xd(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1040 <_decrypt@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
mov    -0x3c(%rbp),%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x40(%rbp)
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1229 <main+0xe9>
mov    -0x38(%rbp),%rax
movslq -0x40(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11f5 <main+0xb5>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   *-0x48(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movabs $0x325f335f65616c73,%rax
33 5f 32
mov    %rax,(%rsp)
movb   $0x0,0x8(%rsp)
movups 0xec9(%rip),%xmm0
movups %xmm0,0x1a(%rsp)
movaps 0xeb3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    $0x19,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe63(%rip),%rdi
mov    $0x19,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
mov    $0x19,%edx
call   1060 <_decrypt@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x19,%edx
call   1070 <memcpy@plt>
lea    0xe4a(%rip),%rdi
call   1040 <puts@plt>
movzbl (%rbx),%esi
lea    0xe34(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x1(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x2(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x3(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x4(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x5(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x6(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x7(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x8(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x9(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xa(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xb(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xc(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xd(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xe(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xf(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x10(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x11(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x12(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x13(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x14(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x15(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x16(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x17(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x18(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   *%rbx
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.key = [9 x i8] c"slae_3_2\00"
@__const.main.enc_code = [26 x i8] c"\A7t\FE!\86\19\13\ECA\C4\13\F9\AE\99 \F6\FAC\8D\AA\EA\D2\A8p\D1\00"
@.str = [20 x i8] c"Shellcode size:%d \0A\00"
@.str.1 = [17 x i8] c"Decrypted text:\0A\00"
@.str.2 = [7 x i8] c"\\x%02x\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x i8]
%3 = alloca [26 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32 (...)*
store i32 0, i32* %1
%8 = bitcast [9 x i8]* %2 to i8*
%9 = bitcast [26 x i8]* %3 to i8*
store i32 25, i32* %5
%10 = load i32, i32* %5
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %4
%12 = load i32, i32* %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i8*, i8** %4
%15 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%16 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* %5
%18 = call i32 @_decrypt(i8* %15, i8* %16, i32 %17)
%19 = load i32, i32* %5
%20 = call i32 @memcpy(i8* %14, i32 %18, i32 %19)
store i32 0, i32* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %22
22: ; preds = %34, %0
%23 = load i32, i32* %6
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %37
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %26
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %22
37: ; preds = %22
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%39 = load i8*, i8** %4
%40 = bitcast i8* %39 to i32 (...)*
store i32 (...)* %40, i32 (...)** %7
%41 = load i32 (...)*, i32 (...)** %7
%42 = call i32 (...) %41()
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@__const.main.key = [9 x i8] c"slae_3_2\00"
@__const.main.enc_code = [26 x i8] c"\A7t\FE!\86\19\13\ECA\C4\13\F9\AE\99 \F6\FAC\8D\AA\EA\D2\A8p\D1\00"
@.str = [20 x i8] c"Shellcode size:%d \0A\00"
@.str.2 = [7 x i8] c"\\x%02x\00"
@str = [16 x i8] c"Decrypted text:\00"
define i32 @main() {
%1 = alloca [9 x i8]
%2 = alloca [26 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [26 x i8], [26 x i8]* %2, i64 0, i64 0
%5 = tail call dereferenceable_or_null(25) i8* @malloc(i32 25)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 25)
%7 = call i32 @_decrypt(i8* %3, i8* %4, i32 25)
%8 = call i32 @memcpy(i8* %5, i32 %7, i32 25)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%10 = load i8, i8* %5
%11 = zext i8 %10 to i32
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds i8, i8* %5, i64 1
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds i8, i8* %5, i64 2
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds i8, i8* %5, i64 3
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds i8, i8* %5, i64 4
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds i8, i8* %5, i64 5
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds i8, i8* %5, i64 6
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds i8, i8* %5, i64 7
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds i8, i8* %5, i64 8
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds i8, i8* %5, i64 9
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds i8, i8* %5, i64 10
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %51)
%53 = getelementptr inbounds i8, i8* %5, i64 11
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %55)
%57 = getelementptr inbounds i8, i8* %5, i64 12
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %59)
%61 = getelementptr inbounds i8, i8* %5, i64 13
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %63)
%65 = getelementptr inbounds i8, i8* %5, i64 14
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %67)
%69 = getelementptr inbounds i8, i8* %5, i64 15
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %71)
%73 = getelementptr inbounds i8, i8* %5, i64 16
%74 = load i8, i8* %73
%75 = zext i8 %74 to i32
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %75)
%77 = getelementptr inbounds i8, i8* %5, i64 17
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %79)
%81 = getelementptr inbounds i8, i8* %5, i64 18
%82 = load i8, i8* %81
%83 = zext i8 %82 to i32
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %83)
%85 = getelementptr inbounds i8, i8* %5, i64 19
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %87)
%89 = getelementptr inbounds i8, i8* %5, i64 20
%90 = load i8, i8* %89
%91 = zext i8 %90 to i32
%92 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %91)
%93 = getelementptr inbounds i8, i8* %5, i64 21
%94 = load i8, i8* %93
%95 = zext i8 %94 to i32
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %95)
%97 = getelementptr inbounds i8, i8* %5, i64 22
%98 = load i8, i8* %97
%99 = zext i8 %98 to i32
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %99)
%101 = getelementptr inbounds i8, i8* %5, i64 23
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %103)
%105 = getelementptr inbounds i8, i8* %5, i64 24
%106 = load i8, i8* %105
%107 = zext i8 %106 to i32
%108 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %107)
%109 = call i32 @putchar(i32 10)
%110 = bitcast i8* %5 to i32 (...)*
%111 = call i32 (...) %110()
ret i32 0
}