#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);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ strtol(char *, char **, int);
void parseKey(char *key, unsigned char *const keyArray) {
  char *temp = key;
  int i = 0;
  char substring[3] = {0, 0, 0};
  while (*temp) {
    temp++;
    i++;
  }
  if (i == 32) {
    for (i = 15; i >= 0; i--) {
      temp -= 2;
      memcpy(substring, temp, 2);
      keyArray[i] = (unsigned char)strtol(&substring[0], &key, 16);
    }
  } else if (i == 16) {
    for (i = 0; i < 16; i++) {
      keyArray[i] = (unsigned char)key[i];
    }
  } else {
    printf("ERROR: Invalid key. Accepted lengths: 16-char plaintext or 32-char "
           "HEX. Input length: %i\r\n",
           i);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<parseKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x1f(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a6 <parseKey+0x56>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117f <parseKey+0x2f>
cmpl   $0x20,-0x1c(%rbp)
jne    1211 <parseKey+0xc1>
movl   $0xf,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     120c <parseKey+0xbc>
mov    -0x18(%rbp),%rax
add    $0xfffffffffffffffe,%rax
mov    %rax,-0x18(%rbp)
lea    -0x1f(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1060 <memcpy@plt>
lea    -0x1f(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b7 <parseKey+0x67>
jmp    1273 <parseKey+0x123>
cmpl   $0x10,-0x1c(%rbp)
jne    1255 <parseKey+0x105>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    1250 <parseKey+0x100>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1222 <parseKey+0xd2>
jmp    126e <parseKey+0x11e>
mov    -0x1c(%rbp),%esi
lea    0xda1(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    1273 <parseKey+0x123>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseKey>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,0x8(%rsp)
movb   $0x0,0x6(%rsp)
movw   $0x0,0x4(%rsp)
mov    (%rdi),%al
test   %al,%al
je     125b <parseKey+0x11b>
mov    %rsi,%r14
lea    -0x2(%rdi),%rbx
mov    $0xffffffff,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%esi
cmpb   $0x0,0x3(%rbx)
lea    0x1(%rbx),%rbx
jne    1180 <parseKey+0x40>
cmp    $0xf,%esi
je     11e1 <parseKey+0xa1>
cmp    $0x1f,%esi
jne    125f <parseKey+0x11f>
mov    $0x10,%r13d
lea    0x4(%rsp),%r15
lea    0x8(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,-0x1(%r14,%r13,1)
add    $0xfffffffffffffffe,%rbx
add    $0xffffffffffffffff,%r13
jne    11b0 <parseKey+0x70>
jmp    124d <parseKey+0x10d>
mov    %al,(%r14)
mov    0x1(%rdi),%al
mov    %al,0x1(%r14)
mov    0x2(%rdi),%al
mov    %al,0x2(%r14)
mov    0x3(%rdi),%al
mov    %al,0x3(%r14)
mov    0x4(%rdi),%al
mov    %al,0x4(%r14)
mov    0x5(%rdi),%al
mov    %al,0x5(%r14)
mov    0x6(%rdi),%al
mov    %al,0x6(%r14)
mov    0x7(%rdi),%al
mov    %al,0x7(%r14)
mov    0x8(%rdi),%al
mov    %al,0x8(%r14)
mov    0x9(%rdi),%al
mov    %al,0x9(%r14)
mov    0xa(%rdi),%al
mov    %al,0xa(%r14)
mov    0xb(%rdi),%al
mov    %al,0xb(%r14)
mov    0xc(%rdi),%al
mov    %al,0xc(%r14)
mov    0xd(%rdi),%al
mov    %al,0xd(%r14)
mov    0xe(%rdi),%al
mov    %al,0xe(%r14)
mov    0xf(%rdi),%al
mov    %al,0xf(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %esi,%esi
jmp    1262 <parseKey+0x122>
add    $0x1,%esi
lea    0xd97(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [91 x i8] c"ERROR: Invalid key. Accepted lengths: 16-char plaintext or 32-char HEX. Input length: %i\0D\0A\00"
define void @parseKey(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [3 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
store i8* %8, i8** %5
store i32 0, i32* %6
%9 = bitcast [3 x i8]* %7 to i8*
br label %10
10: ; preds = %14, %2
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %5
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %6
br label %10
19: ; preds = %10
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 32
br i1 %21, label %22, label %43
22: ; preds = %19
store i32 15, i32* %6
br label %23
23: ; preds = %39, %22
%24 = load i32, i32* %6
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %42
26: ; preds = %23
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 -2
store i8* %28, i8** %5
%29 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%30 = load i8*, i8** %5
%31 = call i32 @memcpy(i8* %29, i8* %30, i32 2)
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%33 = call i64 @strtol(i8* %32, i8** %3, i32 16)
%34 = trunc i64 %33 to i8
%35 = load i8*, i8** %4
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
br label %39
39: ; preds = %26
%40 = load i32, i32* %6
%41 = add nsw i32 %40, -1
store i32 %41, i32* %6
br label %23
42: ; preds = %23
br label %69
43: ; preds = %19
%44 = load i32, i32* %6
%45 = icmp eq i32 %44, 16
br i1 %45, label %46, label %64
46: ; preds = %43
store i32 0, i32* %6
br label %47
47: ; preds = %60, %46
%48 = load i32, i32* %6
%49 = icmp slt i32 %48, 16
br i1 %49, label %50, label %63
50: ; preds = %47
%51 = load i8*, i8** %3
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = load i8*, i8** %4
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 %55, i8* %59
br label %60
60: ; preds = %50
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %47
63: ; preds = %47
br label %68
64: ; preds = %43
%65 = load i32, i32* %6
%66 = call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i32 %65)
%67 = call i32 @exit(i32 -1)
unreachable
68: ; preds = %63
br label %69
69: ; preds = %68, %42
ret void
}

LLVM IR (-O2):
@.str = [91 x i8] c"ERROR: Invalid key. Accepted lengths: 16-char plaintext or 32-char HEX. Input length: %i\0D\0A\00"
define void @parseKey(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca i8*
%4 = alloca [3 x i8]
store i8* %0, i8** %3
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %72, label %8
8: ; preds = %2, %8
%9 = phi i32 [ %12, %8 ], [ 0, %2 ]
%10 = phi i8* [ %11, %8 ], [ %0, %2 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = add nuw nsw i32 %9, 1
%13 = load i8, i8* %11
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %8
15: ; preds = %8
switch i32 %9, label %72 [
i32 31, label %62
i32 15, label %16
]
16: ; preds = %15
store i8 %6, i8* %1
%17 = getelementptr inbounds i8, i8* %0, i64 1
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %18, i8* %19
%20 = getelementptr inbounds i8, i8* %0, i64 2
%21 = load i8, i8* %20
%22 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %21, i8* %22
%23 = getelementptr inbounds i8, i8* %0, i64 3
%24 = load i8, i8* %23
%25 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %24, i8* %25
%26 = getelementptr inbounds i8, i8* %0, i64 4
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %27, i8* %28
%29 = getelementptr inbounds i8, i8* %0, i64 5
%30 = load i8, i8* %29
%31 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %30, i8* %31
%32 = getelementptr inbounds i8, i8* %0, i64 6
%33 = load i8, i8* %32
%34 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %33, i8* %34
%35 = getelementptr inbounds i8, i8* %0, i64 7
%36 = load i8, i8* %35
%37 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %36, i8* %37
%38 = getelementptr inbounds i8, i8* %0, i64 8
%39 = load i8, i8* %38
%40 = getelementptr inbounds i8, i8* %1, i64 8
store i8 %39, i8* %40
%41 = getelementptr inbounds i8, i8* %0, i64 9
%42 = load i8, i8* %41
%43 = getelementptr inbounds i8, i8* %1, i64 9
store i8 %42, i8* %43
%44 = getelementptr inbounds i8, i8* %0, i64 10
%45 = load i8, i8* %44
%46 = getelementptr inbounds i8, i8* %1, i64 10
store i8 %45, i8* %46
%47 = getelementptr inbounds i8, i8* %0, i64 11
%48 = load i8, i8* %47
%49 = getelementptr inbounds i8, i8* %1, i64 11
store i8 %48, i8* %49
%50 = getelementptr inbounds i8, i8* %0, i64 12
%51 = load i8, i8* %50
%52 = getelementptr inbounds i8, i8* %1, i64 12
store i8 %51, i8* %52
%53 = getelementptr inbounds i8, i8* %0, i64 13
%54 = load i8, i8* %53
%55 = getelementptr inbounds i8, i8* %1, i64 13
store i8 %54, i8* %55
%56 = getelementptr inbounds i8, i8* %0, i64 14
%57 = load i8, i8* %56
%58 = getelementptr inbounds i8, i8* %1, i64 14
store i8 %57, i8* %58
%59 = getelementptr inbounds i8, i8* %0, i64 15
%60 = load i8, i8* %59
%61 = getelementptr inbounds i8, i8* %1, i64 15
store i8 %60, i8* %61
br label %76
62: ; preds = %15, %62
%63 = phi i64 [ %70, %62 ], [ 15, %15 ]
%64 = phi i8* [ %65, %62 ], [ %11, %15 ]
%65 = getelementptr inbounds i8, i8* %64, i64 -2
%66 = call i32 @memcpy(i8* %5, i8* %65, i32 2)
%67 = call i64 @strtol(i8* %5, i8** %3, i32 16)
%68 = trunc i64 %67 to i8
%69 = getelementptr inbounds i8, i8* %1, i64 %63
store i8 %68, i8* %69
%70 = add nsw i64 %63, -1
%71 = icmp eq i64 %63, 0
br i1 %71, label %76, label %62
72: ; preds = %2, %15
%73 = phi i32 [ %12, %15 ], [ 0, %2 ]
%74 = tail call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i32 %73)
%75 = tail call i32 @exit(i32 -1)
unreachable
76: ; preds = %62, %16
ret void
}