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

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int);
int parse_key(const char *ascii, uint8_t key[0x20]) {
  int i;
  for (i = 0; i < 0x20; i++) {
    char byte[3];
    memcpy(byte, &ascii[2 * i], 2);
    byte[2] = '\0';
    key[i] = strtol(byte, NULL, 16);
    if (key[i] == 0 && !(byte[0] == '0' && byte[1] == '0')) {
      return -1;
    }
  }
  if (ascii[2 * i] != '\0') {
    return -1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<parse_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jge    11cc <parse_key+0xac>
lea    -0x1f(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
movb   $0x0,-0x1d(%rbp)
lea    -0x1f(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11b9 <parse_key+0x99>
movsbl -0x1f(%rbp),%eax
cmp    $0x30,%eax
jne    11ad <parse_key+0x8d>
movsbl -0x1e(%rbp),%eax
cmp    $0x30,%eax
je     11b9 <parse_key+0x99>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <parse_key+0xd9>
jmp    11be <parse_key+0x9e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <parse_key+0x17>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11f2 <parse_key+0xd2>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <parse_key+0xd9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_key>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0x5(%rsp),%r12
jmp    114a <parse_key+0x2a>
nopw   0x0(%rax,%rax,1)
add    $0x2,%rbx
cmp    $0x40,%rbx
je     118c <parse_key+0x6c>
lea    (%r14,%rbx,1),%rsi
mov    %r12,%rdi
mov    $0x2,%edx
call   1040 <memcpy@plt>
movb   $0x0,0x7(%rsp)
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %eax,(%r15,%rbx,2)
test   %eax,%eax
jne    1140 <parse_key+0x20>
cmpb   $0x30,0x5(%rsp)
jne    1185 <parse_key+0x65>
cmpb   $0x30,0x6(%rsp)
je     1140 <parse_key+0x20>
mov    $0xffffffff,%eax
jmp    1194 <parse_key+0x74>
xor    %eax,%eax
cmp    0x40(%r14),%al
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @parse_key(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [3 x i8]
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %6
br label %8
8: ; preds = %44, %2
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 32
br i1 %10, label %11, label %47
11: ; preds = %8
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = load i32, i32* %6
%15 = mul nsw i32 2, %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = call i32 @memcpy(i8* %12, i8* %17, i32 2)
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 2
store i8 0, i8* %19
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%21 = call i32 @strtol(i8* %20, i32* null, i32 16)
%22 = load i32*, i32** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %21, i32* %25
%26 = load i32*, i32** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %43
32: ; preds = %11
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 48
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 48
br i1 %41, label %43, label %42
42: ; preds = %37, %32
store i32 -1, i32* %3
br label %58
43: ; preds = %37, %11
br label %44
44: ; preds = %43
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %8
47: ; preds = %8
%48 = load i8*, i8** %4
%49 = load i32, i32* %6
%50 = mul nsw i32 2, %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %47
store i32 -1, i32* %3
br label %58
57: ; preds = %47
store i32 0, i32* %3
br label %58
58: ; preds = %57, %56, %42
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
define i32 @parse_key(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
br label %7
7: ; preds = %2, %22
%8 = phi i64 [ 0, %2 ], [ %23, %22 ]
%9 = shl nuw nsw i64 %8, 1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = call i32 @memcpy(i8* %4, i8* %10, i32 2)
store i8 0, i8* %5
%12 = call i32 @strtol(i8* nocapture %4, i32* null, i32 16)
%13 = getelementptr inbounds i32, i32* %1, i64 %8
store i32 %12, i32* %13
%14 = icmp eq i32 %12, 0
br i1 %14, label %15, label %22
15: ; preds = %7
%16 = load i8, i8* %4
%17 = icmp eq i8 %16, 48
%18 = load i8, i8* %6
%19 = icmp eq i8 %18, 48
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %22, label %21
21: ; preds = %15
br label %30
22: ; preds = %7, %15
%23 = add nuw nsw i64 %8, 1
%24 = icmp eq i64 %23, 32
br i1 %24, label %25, label %7
25: ; preds = %22
%26 = getelementptr inbounds i8, i8* %0, i64 64
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
%29 = sext i1 %28 to i32
br label %30
30: ; preds = %25, %21
%31 = phi i32 [ -1, %21 ], [ %29, %25 ]
ret i32 %31
}