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

/* Variables and functions */
int /*<<< orphan*/ _crypt(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 shellcode[] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89"
                     "\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80";
  char *enc;
  int len = sizeof(shellcode) - 1;
  enc = malloc(len);
  printf("Shellcode lenght:%d \n", len);
  memcpy(enc, _crypt(key, shellcode, len), len);
  int i = 0;
  printf("Encrypted shellcode:\n");
  for (i = 0; i < len; i++) {
    printf("\\x%02x", (unsigned char)enc[i]);
  }
  printf("\n");
}


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,-0x48(%rbp)
lea    -0xd(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1050 <_crypt@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
mov    -0x3c(%rbp),%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x40(%rbp)
lea    0xe38(%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    0xe21(%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    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
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   1070 <_crypt@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x19,%edx
call   1060 <memcpy@plt>
lea    0xe4c(%rip),%rdi
call   1040 <puts@plt>
movzbl (%rbx),%esi
lea    0xe36(%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
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.key = [9 x i8] c"slae_3_2\00"
@__const.main.shellcode = [26 x i8] c"1\C0Ph//shh/bin\89\E3P\89\E2S\89\E1\B0\0B\CD\80\00"
@.str = [22 x i8] c"Shellcode lenght:%d \0A\00"
@.str.1 = [22 x i8] c"Encrypted shellcode:\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
store i32 0, i32* %1
%7 = bitcast [9 x i8]* %2 to i8*
%8 = bitcast [26 x i8]* %3 to i8*
store i32 25, i32* %5
%9 = load i32, i32* %5
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %4
%11 = load i32, i32* %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %4
%14 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%15 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%16 = load i32, i32* %5
%17 = call i32 @_crypt(i8* %14, i8* %15, i32 %16)
%18 = load i32, i32* %5
%19 = call i32 @memcpy(i8* %13, i32 %17, i32 %18)
store i32 0, i32* %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %21
21: ; preds = %33, %0
%22 = load i32, i32* %6
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %25
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %21
36: ; preds = %21
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@__const.main.key = [9 x i8] c"slae_3_2\00"
@__const.main.shellcode = [26 x i8] c"1\C0Ph//shh/bin\89\E3P\89\E2S\89\E1\B0\0B\CD\80\00"
@.str = [22 x i8] c"Shellcode lenght:%d \0A\00"
@.str.2 = [7 x i8] c"\\x%02x\00"
@str = [21 x i8] c"Encrypted shellcode:\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 ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 25)
%7 = call i32 @_crypt(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 ([21 x i8], [21 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)
ret i32 0
}