#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(int /*<<< orphan*/);
unsigned char *malloc(int);
int /*<<< orphan*/ printf(char *, int, unsigned char);
int strlen(char *);
unsigned char *_alpha_encode(unsigned char *data, int len) {
  int i, j, m, n;
  int isFind = 0;
  unsigned char X, Y;
  unsigned char *newshellcode;
  newshellcode = malloc(2 * len + 1);
  for (i = 0, j = 0; i < len; i++, j += 2) {
    for (m = 0;
         m <
         strlen(
             "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
         m++) {
      X = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"[m];
      for (n = 0; n < strlen("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm"
                             "nopqrstuvwxyz");
           n++) {
        Y = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"[n];
        if (((data[i] ^ X) & 0xFF) == ((Y * 0x58) & 0xFF)) {
          isFind = 1;
          break;
        } else {
          isFind = 0;
        }
      }
      if (1 == isFind) {
        newshellcode[j] = X;
        newshellcode[j + 1] = Y;
        break;
      }
    }
    if (0 == isFind) {
      printf("can not encode data[i]=0x%02x\n\n", i, data[i]);
      exit(0);
    }
    isFind = 0;
  }
  newshellcode[2 * len] = '\x0';
  return newshellcode;
}


x86 assembly (clang, -O0):
<_alpha_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12d4 <_alpha_encode+0x194>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    0xe6a(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    1289 <_alpha_encode+0x149>
movslq -0x18(%rbp),%rcx
lea    0xe4d(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
lea    0xe33(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jge    1242 <_alpha_encode+0x102>
movslq -0x1c(%rbp),%rcx
lea    0xe16(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x22(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
movzbl -0x21(%rbp),%ecx
xor    %ecx,%eax
and    $0xff,%eax
movzbl -0x22(%rbp),%ecx
imul   $0x58,%ecx,%ecx
and    $0xff,%ecx
cmp    %ecx,%eax
jne    1228 <_alpha_encode+0xe8>
movl   $0x1,-0x20(%rbp)
jmp    1242 <_alpha_encode+0x102>
movl   $0x0,-0x20(%rbp)
jmp    1234 <_alpha_encode+0xf4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c0 <_alpha_encode+0x80>
mov    $0x1,%eax
cmp    -0x20(%rbp),%eax
jne    1276 <_alpha_encode+0x136>
mov    -0x21(%rbp),%dl
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x22(%rbp),%dl
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1289 <_alpha_encode+0x149>
jmp    127b <_alpha_encode+0x13b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1189 <_alpha_encode+0x49>
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
jne    12b6 <_alpha_encode+0x176>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xd99(%rip),%rdi
movzbl (%rax,%rcx,1),%edx
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1176 <_alpha_encode+0x36>
mov    -0x30(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_alpha_encode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %rdi,%r15
movslq %esi,%rbp
mov    %rbp,%rcx
add    %rbp,%rcx
mov    %rcx,0x10(%rsp)
lea    0x1(%rcx),%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %ebp,%ebp
jle    122e <_alpha_encode+0xee>
mov    %ebx,%eax
mov    %rax,0x18(%rsp)
xor    %esi,%esi
lea    0xe7a(%rip),%r12
xor    %ebx,%ebx
jmp    11b7 <_alpha_encode+0x77>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdx
mov    0x20(%rsp),%rsi
mov    %r14b,(%rdx,%rsi,1)
mov    %rsi,%rcx
or     $0x1,%rcx
mov    %al,(%rdx,%rcx,1)
add    $0x1,%rbx
add    $0x2,%rsi
cmp    0x18(%rsp),%rbx
je     122e <_alpha_encode+0xee>
mov    %rsi,0x20(%rsp)
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    124e <_alpha_encode+0x10e>
xor    %ebp,%ebp
jmp    11e3 <_alpha_encode+0xa3>
add    $0x1,%rbp
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    124e <_alpha_encode+0x10e>
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11d0 <_alpha_encode+0x90>
mov    0x0(%rbp,%r12,1),%r14b
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
movzbl 0x0(%r13,%r12,1),%eax
movzbl (%r15,%rbx,1),%ecx
xor    %r14b,%cl
imul   $0x58,%eax,%edx
cmp    %dl,%cl
je     1190 <_alpha_encode+0x50>
add    $0x1,%r13
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%r13
jl     1200 <_alpha_encode+0xc0>
jmp    11d0 <_alpha_encode+0x90>
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
movb   $0x0,(%rcx,%rax,1)
mov    %rcx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%eax
movzbl (%r15,%rax,1),%edx
lea    0xde3(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [63 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\00"
@.str.1 = [32 x i8] c"can not encode data[i]=0x%02x\0A\0A\00"
define i8* @_alpha_encode(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %9
%13 = load i32, i32* %4
%14 = mul nsw i32 2, %13
%15 = add nsw i32 %14, 1
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %12
store i32 0, i32* %5
store i32 0, i32* %6
br label %17
17: ; preds = %93, %2
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %98
21: ; preds = %17
store i32 0, i32* %7
br label %22
22: ; preds = %77, %21
%23 = load i32, i32* %7
%24 = call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %80
26: ; preds = %22
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [63 x i8], [63 x i8]* @.str, i64 0, i64 %28
%30 = load i8, i8* %29
store i8 %30, i8* %10
store i32 0, i32* %8
br label %31
31: ; preds = %58, %26
%32 = load i32, i32* %8
%33 = call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %61
35: ; preds = %31
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [63 x i8], [63 x i8]* @.str, i64 0, i64 %37
%39 = load i8, i8* %38
store i8 %39, i8* %11
%40 = load i8*, i8** %3
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = load i8, i8* %10
%47 = zext i8 %46 to i32
%48 = xor i32 %45, %47
%49 = and i32 %48, 255
%50 = load i8, i8* %11
%51 = zext i8 %50 to i32
%52 = mul nsw i32 %51, 88
%53 = and i32 %52, 255
%54 = icmp eq i32 %49, %53
br i1 %54, label %55, label %56
55: ; preds = %35
store i32 1, i32* %9
br label %61
56: ; preds = %35
store i32 0, i32* %9
br label %57
57: ; preds = %56
br label %58
58: ; preds = %57
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %31
61: ; preds = %55, %31
%62 = load i32, i32* %9
%63 = icmp eq i32 1, %62
br i1 %63, label %64, label %76
64: ; preds = %61
%65 = load i8, i8* %10
%66 = load i8*, i8** %12
%67 = load i32, i32* %6
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
store i8 %65, i8* %69
%70 = load i8, i8* %11
%71 = load i8*, i8** %12
%72 = load i32, i32* %6
%73 = add nsw i32 %72, 1
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %71, i64 %74
store i8 %70, i8* %75
br label %80
76: ; preds = %61
br label %77
77: ; preds = %76
%78 = load i32, i32* %7
%79 = add nsw i32 %78, 1
store i32 %79, i32* %7
br label %22
80: ; preds = %64, %22
%81 = load i32, i32* %9
%82 = icmp eq i32 0, %81
br i1 %82, label %83, label %92
83: ; preds = %80
%84 = load i32, i32* %5
%85 = load i8*, i8** %3
%86 = load i32, i32* %5
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %85, i64 %87
%89 = load i8, i8* %88
%90 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %84, i8 zeroext %89)
%91 = call i32 @exit(i32 0)
unreachable
92: ; preds = %80
store i32 0, i32* %9
br label %93
93: ; preds = %92
%94 = load i32, i32* %5
%95 = add nsw i32 %94, 1
store i32 %95, i32* %5
%96 = load i32, i32* %6
%97 = add nsw i32 %96, 2
store i32 %97, i32* %6
br label %17
98: ; preds = %17
%99 = load i8*, i8** %12
%100 = load i32, i32* %4
%101 = mul nsw i32 2, %100
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %99, i64 %102
store i8 0, i8* %103
%104 = load i8*, i8** %12
ret i8* %104
}

LLVM IR (-O2):
@.str = [63 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\00"
@.str.1 = [32 x i8] c"can not encode data[i]=0x%02x\0A\0A\00"
define noalias i8* @_alpha_encode(i8* nocapture %0, i32 %1) {
%3 = shl nsw i32 %1, 1
%4 = or i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %54
7: ; preds = %2
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %47
%10 = phi i64 [ 0, %7 ], [ %52, %47 ]
%11 = phi i64 [ 0, %7 ], [ %51, %47 ]
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %40
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %0, i64 %11
br label %16
16: ; preds = %14, %35
%17 = phi i64 [ 0, %14 ], [ %36, %35 ]
%18 = getelementptr inbounds [63 x i8], [63 x i8]* @.str, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = tail call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%21 = icmp sgt i32 %20, 0
br i1 %21, label %26, label %35
22: ; preds = %26
%23 = tail call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %34, %24
br i1 %25, label %26, label %35
26: ; preds = %16, %22
%27 = phi i64 [ %34, %22 ], [ 0, %16 ]
%28 = getelementptr inbounds [63 x i8], [63 x i8]* @.str, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = load i8, i8* %15
%31 = xor i8 %30, %19
%32 = mul i8 %29, 88
%33 = icmp eq i8 %31, %32
%34 = add nuw nsw i64 %27, 1
br i1 %33, label %47, label %22
35: ; preds = %22, %16
%36 = add nuw nsw i64 %17, 1
%37 = tail call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %36, %38
br i1 %39, label %16, label %40
40: ; preds = %9, %35
%41 = trunc i64 %11 to i32
%42 = and i64 %11, 4294967295
%43 = getelementptr inbounds i8, i8* %0, i64 %42
%44 = load i8, i8* %43
%45 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %41, i8 zeroext %44)
%46 = tail call i32 @exit(i32 0)
unreachable
47: ; preds = %26
%48 = getelementptr inbounds i8, i8* %5, i64 %10
store i8 %19, i8* %48
%49 = or i64 %10, 1
%50 = getelementptr inbounds i8, i8* %5, i64 %49
store i8 %29, i8* %50
%51 = add nuw nsw i64 %11, 1
%52 = add nuw nsw i64 %10, 2
%53 = icmp eq i64 %51, %8
br i1 %53, label %54, label %9
54: ; preds = %47, %2
%55 = sext i32 %3 to i64
%56 = getelementptr inbounds i8, i8* %5, i64 %55
store i8 0, i8* %56
ret i8* %5
}