#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 */
unsigned char *malloc(int);
int strlen(char *);
unsigned char *alpha2_encode(unsigned char *data, int len) {
  int i, j, m, n;
  unsigned char ah, al, A, B, C, D;
  unsigned char *newshellcode = malloc(2 * len + 1);
  for (i = 0, j = 0; i < len; i++, j += 2) {
    A = al = data[i] & 0x0f;
    B = ah = (data[i] & 0xf0) >> 4;
    for (m = 0;
         m <
         strlen(
             "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
         m++) {
      if (("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"[m] &
           0x0F) == A)
        break;
    }
    B = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"[m] >>
        4;
    C = B ^ A;
    for (n = 0;
         n <
         strlen(
             "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
         n++) {
      if (("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"[n] &
           0x0F) == C)
        break;
    }
    D = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"[n] >>
        4;
    newshellcode[j] = (D << 4) + C;
    newshellcode[j + 1] = (B << 4) + A;
  }
  newshellcode[2 * len] = '\x0';
  return newshellcode;
}


x86 assembly (clang, -O0):
<alpha2_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12c9 <alpha2_encode+0x1a9>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
mov    %al,-0x1e(%rbp)
mov    %al,-0x1f(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf0,%eax
sar    $0x4,%eax
mov    %al,-0x1d(%rbp)
mov    %al,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    0xe62(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    11e6 <alpha2_encode+0xc6>
movslq -0x18(%rbp),%rcx
lea    0xe45(%rip),%rax
movsbl (%rax,%rcx,1),%eax
and    $0xf,%eax
movzbl -0x1f(%rbp),%ecx
cmp    %ecx,%eax
jne    11d3 <alpha2_encode+0xb3>
jmp    11e6 <alpha2_encode+0xc6>
jmp    11d8 <alpha2_encode+0xb8>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1191 <alpha2_encode+0x71>
movslq -0x18(%rbp),%rcx
lea    0xe0f(%rip),%rax
movsbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
mov    %al,-0x20(%rbp)
movzbl -0x20(%rbp),%eax
movzbl -0x1f(%rbp),%ecx
xor    %ecx,%eax
mov    %al,-0x21(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
lea    0xde4(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jge    1264 <alpha2_encode+0x144>
movslq -0x1c(%rbp),%rcx
lea    0xdc7(%rip),%rax
movsbl (%rax,%rcx,1),%eax
and    $0xf,%eax
movzbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
jne    1251 <alpha2_encode+0x131>
jmp    1264 <alpha2_encode+0x144>
jmp    1256 <alpha2_encode+0x136>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120f <alpha2_encode+0xef>
movslq -0x1c(%rbp),%rcx
lea    0xd91(%rip),%rax
movsbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
mov    %al,-0x22(%rbp)
movzbl -0x22(%rbp),%eax
shl    $0x4,%eax
movzbl -0x21(%rbp),%ecx
add    %ecx,%eax
mov    %al,%dl
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movzbl -0x20(%rbp),%eax
shl    $0x4,%eax
movzbl -0x1f(%rbp),%ecx
add    %ecx,%eax
mov    %al,%dl
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    114f <alpha2_encode+0x2f>
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):
<alpha2_encode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %rdi,0x18(%rsp)
movslq %esi,%rbp
mov    %rbp,%rcx
add    %rbp,%rcx
mov    %rcx,0x8(%rsp)
lea    0x1(%rcx),%edi
call   1040 <malloc@plt>
mov    %rax,(%rsp)
test   %ebp,%ebp
jle    1258 <alpha2_encode+0x138>
mov    %ebx,%eax
mov    %rax,0x10(%rsp)
xor    %ebp,%ebp
lea    0xe99(%rip),%rbx
xor    %r12d,%r12d
jmp    11ab <alpha2_encode+0x8b>
nopl   0x0(%rax)
mov    %ebp,%eax
mov    (%rax,%rbx,1),%al
and    $0xf0,%al
add    %r13b,%al
mov    (%rsp),%rcx
mov    0x20(%rsp),%rbp
mov    %al,(%rcx,%rbp,1)
and    $0xf0,%r15b
or     %r14b,%r15b
mov    %rbp,%rax
or     $0x1,%rax
mov    %r15b,(%rcx,%rax,1)
add    $0x1,%r12
add    $0x2,%rbp
cmp    0x10(%rsp),%r12
je     1258 <alpha2_encode+0x138>
mov    0x18(%rsp),%rax
mov    (%rax,%r12,1),%r14b
and    $0xf,%r14b
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
mov    %rbp,0x20(%rsp)
jle    1200 <alpha2_encode+0xe0>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp,%rbx,1),%eax
and    $0xf,%al
cmp    %r14b,%al
je     1202 <alpha2_encode+0xe2>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     11d0 <alpha2_encode+0xb0>
jmp    1202 <alpha2_encode+0xe2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
mov    %ebp,%eax
mov    (%rax,%rbx,1),%r15b
mov    %r15d,%r13d
sar    $0x4,%r13b
xor    %r14b,%r13b
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %ebp,%ebp
test   %eax,%eax
jle    1170 <alpha2_encode+0x50>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x0(%rbp,%rbx,1),%eax
and    $0xf,%al
cmp    %r13b,%al
je     1170 <alpha2_encode+0x50>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1230 <alpha2_encode+0x110>
jmp    1170 <alpha2_encode+0x50>
mov    0x8(%rsp),%rax
mov    (%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

LLVM IR (-O0):
@.str = [63 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i8* @alpha2_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 i8
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8
%14 = alloca i8
%15 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%16 = load i32, i32* %4
%17 = mul nsw i32 2, %16
%18 = add nsw i32 %17, 1
%19 = call i8* @malloc(i32 %18)
store i8* %19, i8** %15
store i32 0, i32* %5
store i32 0, i32* %6
br label %20
20: ; preds = %125, %2
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %130
24: ; preds = %20
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = and i32 %30, 15
%32 = trunc i32 %31 to i8
store i8 %32, i8* %10
store i8 %32, i8* %11
%33 = load i8*, i8** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = and i32 %38, 240
%40 = ashr i32 %39, 4
%41 = trunc i32 %40 to i8
store i8 %41, i8* %9
store i8 %41, i8* %12
store i32 0, i32* %7
br label %42
42: ; preds = %58, %24
%43 = load i32, i32* %7
%44 = call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %61
46: ; preds = %42
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [63 x i8], [63 x i8]* @.str, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = and i32 %51, 15
%53 = load i8, i8* %11
%54 = zext i8 %53 to i32
%55 = icmp eq i32 %52, %54
br i1 %55, label %56, label %57
56: ; preds = %46
br label %61
57: ; preds = %46
br label %58
58: ; preds = %57
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %42
61: ; preds = %56, %42
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [63 x i8], [63 x i8]* @.str, i64 0, i64 %63
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = ashr i32 %66, 4
%68 = trunc i32 %67 to i8
store i8 %68, i8* %12
%69 = load i8, i8* %12
%70 = zext i8 %69 to i32
%71 = load i8, i8* %11
%72 = zext i8 %71 to i32
%73 = xor i32 %70, %72
%74 = trunc i32 %73 to i8
store i8 %74, i8* %13
store i32 0, i32* %8
br label %75
75: ; preds = %91, %61
%76 = load i32, i32* %8
%77 = call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %94
79: ; preds = %75
%80 = load i32, i32* %8
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [63 x i8], [63 x i8]* @.str, i64 0, i64 %81
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = and i32 %84, 15
%86 = load i8, i8* %13
%87 = zext i8 %86 to i32
%88 = icmp eq i32 %85, %87
br i1 %88, label %89, label %90
89: ; preds = %79
br label %94
90: ; preds = %79
br label %91
91: ; preds = %90
%92 = load i32, i32* %8
%93 = add nsw i32 %92, 1
store i32 %93, i32* %8
br label %75
94: ; preds = %89, %75
%95 = load i32, i32* %8
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [63 x i8], [63 x i8]* @.str, i64 0, i64 %96
%98 = load i8, i8* %97
%99 = sext i8 %98 to i32
%100 = ashr i32 %99, 4
%101 = trunc i32 %100 to i8
store i8 %101, i8* %14
%102 = load i8, i8* %14
%103 = zext i8 %102 to i32
%104 = shl i32 %103, 4
%105 = load i8, i8* %13
%106 = zext i8 %105 to i32
%107 = add nsw i32 %104, %106
%108 = trunc i32 %107 to i8
%109 = load i8*, i8** %15
%110 = load i32, i32* %6
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8, i8* %109, i64 %111
store i8 %108, i8* %112
%113 = load i8, i8* %12
%114 = zext i8 %113 to i32
%115 = shl i32 %114, 4
%116 = load i8, i8* %11
%117 = zext i8 %116 to i32
%118 = add nsw i32 %115, %117
%119 = trunc i32 %118 to i8
%120 = load i8*, i8** %15
%121 = load i32, i32* %6
%122 = add nsw i32 %121, 1
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds i8, i8* %120, i64 %123
store i8 %119, i8* %124
br label %125
125: ; preds = %94
%126 = load i32, i32* %5
%127 = add nsw i32 %126, 1
store i32 %127, i32* %5
%128 = load i32, i32* %6
%129 = add nsw i32 %128, 2
store i32 %129, i32* %6
br label %20
130: ; preds = %20
%131 = load i8*, i8** %15
%132 = load i32, i32* %4
%133 = mul nsw i32 2, %132
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds i8, i8* %131, i64 %134
store i8 0, i8* %135
%136 = load i8*, i8** %15
ret i8* %136
}

LLVM IR (-O2):
@.str = [63 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define noalias i8* @alpha2_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 %63
7: ; preds = %2
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %48
%10 = phi i64 [ 0, %7 ], [ %61, %48 ]
%11 = phi i64 [ 0, %7 ], [ %60, %48 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = and i8 %13, 15
%15 = tail call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %9, %23
%18 = phi i64 [ %24, %23 ], [ 0, %9 ]
%19 = getelementptr inbounds [63 x i8], [63 x i8]* @.str, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = and i8 %20, 15
%22 = icmp eq i8 %21, %14
br i1 %22, label %28, label %23
23: ; preds = %17
%24 = add nuw nsw i64 %18, 1
%25 = tail call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %17, label %28
28: ; preds = %23, %17, %9
%29 = phi i64 [ 0, %9 ], [ %18, %17 ], [ %24, %23 ]
%30 = and i64 %29, 4294967295
%31 = getelementptr inbounds [63 x i8], [63 x i8]* @.str, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = ashr i8 %32, 4
%34 = xor i8 %33, %14
%35 = tail call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %48
37: ; preds = %28, %43
%38 = phi i64 [ %44, %43 ], [ 0, %28 ]
%39 = getelementptr inbounds [63 x i8], [63 x i8]* @.str, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = and i8 %40, 15
%42 = icmp eq i8 %41, %34
br i1 %42, label %48, label %43
43: ; preds = %37
%44 = add nuw nsw i64 %38, 1
%45 = tail call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%46 = sext i32 %45 to i64
%47 = icmp slt i64 %44, %46
br i1 %47, label %37, label %48
48: ; preds = %43, %37, %28
%49 = phi i64 [ 0, %28 ], [ %38, %37 ], [ %44, %43 ]
%50 = and i64 %49, 4294967295
%51 = getelementptr inbounds [63 x i8], [63 x i8]* @.str, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = and i8 %52, -16
%54 = add i8 %53, %34
%55 = getelementptr inbounds i8, i8* %5, i64 %10
store i8 %54, i8* %55
%56 = and i8 %32, -16
%57 = or i8 %56, %14
%58 = or i64 %10, 1
%59 = getelementptr inbounds i8, i8* %5, i64 %58
store i8 %57, i8* %59
%60 = add nuw nsw i64 %11, 1
%61 = add nuw nsw i64 %10, 2
%62 = icmp eq i64 %60, %8
br i1 %62, label %63, label %9
63: ; preds = %48, %2
%64 = sext i32 %3 to i64
%65 = getelementptr inbounds i8, i8* %5, i64 %64
store i8 0, i8* %65
ret i8* %5
}