#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 char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ perror(char *);
int strlen(char *);
int firstlevelencode(char *str, uint8_t *outbuf) {
  int i;
  char *inbuf;
  inbuf = (char *)malloc(32);
  if (inbuf == NULL) {
    perror("can't allocate memory\n");
    exit(1);
  }
  memset(inbuf, 0x20, 32);
  inbuf[(32 / 2) - 1] = 0x00;
  if (strlen(str) > 32)
    str[32 / 2] = 0x00;
  memcpy(inbuf, str, strlen(str));
  for (i = 0; i < strlen(str); i++) {
    if ((inbuf[i] >= 'a') && (inbuf[i] <= 'z'))
      inbuf[i] -= 32;
  }
  for (i = 0; i < 32 / 2; i++) {
    outbuf[i * 2] = (inbuf[i] >> 4) + 0x41;
    outbuf[(i * 2) + 1] = (inbuf[i] & 0x0f) + 0x41;
  }
  outbuf[32] = 0x00;
  free(inbuf);
  return (0);
}


x86 assembly (clang, -O0):
<firstlevelencode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11af <firstlevelencode+0x3f>
lea    0xe60(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    $0x20,%edx
mov    %edx,%esi
call   1050 <memset@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,0xf(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x20,%eax
jle    11e1 <firstlevelencode+0x71>
mov    -0x8(%rbp),%rax
movb   $0x0,0x10(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    127b <firstlevelencode+0x10b>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x61,%eax
jl     1268 <firstlevelencode+0xf8>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7a,%eax
jg     1268 <firstlevelencode+0xf8>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
sub    $0x20,%edx
mov    %dl,(%rax,%rcx,1)
jmp    126d <firstlevelencode+0xfd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1210 <firstlevelencode+0xa0>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    12e5 <firstlevelencode+0x175>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
add    $0x41,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xf,%eax
add    $0x41,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1282 <firstlevelencode+0x112>
mov    -0x10(%rbp),%rax
movb   $0x0,0x20(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<firstlevelencode>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x20,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     132d <firstlevelencode+0x1bd>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x20,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
movb   $0x0,0xf(%r12)
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    $0x21,%eax
jl     11be <firstlevelencode+0x4e>
movb   $0x0,0x10(%r15)
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1218 <firstlevelencode+0xa8>
xor    %ebx,%ebx
jmp    1203 <firstlevelencode+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1218 <firstlevelencode+0xa8>
movzbl (%r12,%rbx,1),%eax
lea    -0x61(%rax),%ecx
cmp    $0x19,%cl
ja     11f0 <firstlevelencode+0x80>
add    $0xe0,%al
mov    %al,(%r12,%rbx,1)
jmp    11f0 <firstlevelencode+0x80>
mov    %r12,%rax
add    $0x10,%rax
cmp    %r14,%rax
jbe    1290 <firstlevelencode+0x120>
lea    0x20(%r14),%rax
cmp    %r12,%rax
jbe    1290 <firstlevelencode+0x120>
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl -0x1(%r12,%rax,1),%ecx
sar    $0x4,%cl
add    $0x41,%cl
mov    %cl,-0x2(%r14,%rax,2)
movzbl -0x1(%r12,%rax,1),%ecx
and    $0xf,%cl
add    $0x41,%cl
mov    %cl,-0x1(%r14,%rax,2)
movzbl (%r12,%rax,1),%ecx
sar    $0x4,%cl
add    $0x41,%cl
mov    %cl,(%r14,%rax,2)
movzbl (%r12,%rax,1),%ecx
and    $0xf,%cl
add    $0x41,%cl
mov    %cl,0x1(%r14,%rax,2)
add    $0x2,%rax
cmp    $0x11,%rax
jne    1240 <firstlevelencode+0xd0>
jmp    1312 <firstlevelencode+0x1a2>
movq   (%r12),%xmm0
movdqa %xmm0,%xmm1
psrlw  $0x4,%xmm1
movdqa 0xd59(%rip),%xmm2
pand   %xmm2,%xmm1
movdqa 0xd5d(%rip),%xmm3
pxor   %xmm3,%xmm1
movdqa 0xd61(%rip),%xmm4
paddb  %xmm4,%xmm1
movdqa 0xd65(%rip),%xmm5
movdqa 0xd6d(%rip),%xmm6
pand   %xmm6,%xmm0
paddb  %xmm5,%xmm0
punpcklbw %xmm0,%xmm1
movdqu %xmm1,(%r14)
movq   0x8(%r12),%xmm0
movdqa %xmm0,%xmm1
psrlw  $0x4,%xmm1
pand   %xmm2,%xmm1
pxor   %xmm3,%xmm1
paddb  %xmm4,%xmm1
pand   %xmm6,%xmm0
paddb  %xmm5,%xmm0
punpcklbw %xmm0,%xmm1
movdqu %xmm1,0x10(%r14)
movb   $0x0,0x20(%r14)
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd1c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
@.str = [23 x i8] c"can't allocate memory\0A\00"
define i32 @firstlevelencode(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call i64 @malloc(i32 32)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i32 @memset(i8* %4, i32 32, i32 32)
%11 = getelementptr inbounds i8, i8* %4, i64 15
store i8 0, i8* %11
%12 = tail call i32 @strlen(i8* %0)
%13 = icmp sgt i32 %12, 32
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %0, i64 16
store i8 0, i8* %15
br label %16
16: ; preds = %14, %9
%17 = tail call i32 @strlen(i8* %0)
%18 = tail call i32 @memcpy(i8* %4, i8* %0, i32 %17)
%19 = tail call i32 @strlen(i8* %0)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %46, label %21
21: ; preds = %54, %16
%22 = getelementptr i8, i8* %1, i64 32
%23 = getelementptr i8, i8* %4, i64 16
%24 = icmp ugt i8* %23, %1
%25 = icmp ugt i8* %22, %4
%26 = and i1 %24, %25
br i1 %26, label %59, label %27
27: ; preds = %21
%28 = inttoptr i64 %3 to <8 x i8>*
%29 = load <8 x i8>, <8 x i8>* %28
%30 = ashr <8 x i8> %29, <i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4>
%31 = add nsw <8 x i8> %30, <i8 65, i8 65, i8 65, i8 65, i8 65, i8 65, i8 65, i8 65>
%32 = and <8 x i8> %29, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%33 = add nuw nsw <8 x i8> %32, <i8 65, i8 65, i8 65, i8 65, i8 65, i8 65, i8 65, i8 65>
%34 = bitcast i8* %1 to <16 x i8>*
%35 = shufflevector <8 x i8> %31, <8 x i8> %33, <16 x i32> <i32 0, i32 8, i32 1, i32 9, i32 2, i32 10, i32 3, i32 11, i32 4, i32 12, i32 5, i32 13, i32 6, i32 14, i32 7, i32 15>
store <16 x i8> %35, <16 x i8>* %34
%36 = getelementptr inbounds i8, i8* %4, i64 8
%37 = bitcast i8* %36 to <8 x i8>*
%38 = load <8 x i8>, <8 x i8>* %37
%39 = ashr <8 x i8> %38, <i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4>
%40 = add nsw <8 x i8> %39, <i8 65, i8 65, i8 65, i8 65, i8 65, i8 65, i8 65, i8 65>
%41 = and <8 x i8> %38, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%42 = add nuw nsw <8 x i8> %41, <i8 65, i8 65, i8 65, i8 65, i8 65, i8 65, i8 65, i8 65>
%43 = getelementptr inbounds i8, i8* %1, i64 16
%44 = bitcast i8* %43 to <16 x i8>*
%45 = shufflevector <8 x i8> %40, <8 x i8> %42, <16 x i32> <i32 0, i32 8, i32 1, i32 9, i32 2, i32 10, i32 3, i32 11, i32 4, i32 12, i32 5, i32 13, i32 6, i32 14, i32 7, i32 15>
store <16 x i8> %45, <16 x i8>* %44
br label %86
46: ; preds = %16, %54
%47 = phi i64 [ %55, %54 ], [ 0, %16 ]
%48 = getelementptr inbounds i8, i8* %4, i64 %47
%49 = load i8, i8* %48
%50 = add i8 %49, -97
%51 = icmp ult i8 %50, 26
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = add nsw i8 %49, -32
store i8 %53, i8* %48
br label %54
54: ; preds = %46, %52
%55 = add nuw nsw i64 %47, 1
%56 = tail call i32 @strlen(i8* %0)
%57 = sext i32 %56 to i64
%58 = icmp slt i64 %55, %57
br i1 %58, label %46, label %21
59: ; preds = %21, %59
%60 = phi i64 [ %84, %59 ], [ 0, %21 ]
%61 = getelementptr inbounds i8, i8* %4, i64 %60
%62 = load i8, i8* %61
%63 = ashr i8 %62, 4
%64 = add nsw i8 %63, 65
%65 = shl nuw nsw i64 %60, 1
%66 = getelementptr inbounds i8, i8* %1, i64 %65
store i8 %64, i8* %66
%67 = load i8, i8* %61
%68 = and i8 %67, 15
%69 = add nuw nsw i8 %68, 65
%70 = or i64 %65, 1
%71 = getelementptr inbounds i8, i8* %1, i64 %70
store i8 %69, i8* %71
%72 = or i64 %60, 1
%73 = getelementptr inbounds i8, i8* %4, i64 %72
%74 = load i8, i8* %73
%75 = ashr i8 %74, 4
%76 = add nsw i8 %75, 65
%77 = shl nuw nsw i64 %72, 1
%78 = getelementptr inbounds i8, i8* %1, i64 %77
store i8 %76, i8* %78
%79 = load i8, i8* %73
%80 = and i8 %79, 15
%81 = add nuw nsw i8 %80, 65
%82 = or i64 %77, 1
%83 = getelementptr inbounds i8, i8* %1, i64 %82
store i8 %81, i8* %83
%84 = add nuw nsw i64 %60, 2
%85 = icmp eq i64 %84, 16
br i1 %85, label %86, label %59
86: ; preds = %59, %27
%87 = getelementptr inbounds i8, i8* %1, i64 32
store i8 0, i8* %87
%88 = tail call i32 @free(i8* %4)
ret i32 0
}