#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 */
scalar_t__ isxdigit(char);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int /*<<< orphan*/ strtoul(char *, int /*<<< orphan*/ *, int);
int parse_key(const char *string, uint8_t key[16]) {
  int i;
  char temp[3];
  for (i = 0; i < 16; i++) {
    strncpy(temp, string + (i * 2), 2);
    temp[2] = '\0';
    if (isxdigit(temp[0]) && isxdigit(temp[1])) {
      key[i] = strtoul(temp, NULL, 16);
    } else {
      return 0;
    }
  }
  return 1;
}


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   $0x10,-0x1c(%rbp)
jge    11db <parse_key+0xab>
lea    -0x1f(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x1d(%rbp)
movsbl -0x1f(%rbp),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%rax
je     11bc <parse_key+0x8c>
movsbl -0x1e(%rbp),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%rax
je     11bc <parse_key+0x8c>
lea    -0x1f(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11c8 <parse_key+0x98>
movl   $0x0,-0x4(%rbp)
jmp    11e2 <parse_key+0xb2>
jmp    11cd <parse_key+0x9d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1147 <parse_key+0x17>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_key>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r13
xor    %r14d,%r14d
lea    0xd(%rsp),%r12
xor    %ebx,%ebx
nopl   (%rax)
lea    (%rbx,%r13,1),%rsi
mov    %r12,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xf(%rsp)
movsbl 0xd(%rsp),%edi
call   1050 <isxdigit@plt>
test   %rax,%rax
je     11a7 <parse_key+0x77>
movsbl 0xe(%rsp),%edi
call   1050 <isxdigit@plt>
test   %rax,%rax
je     11a7 <parse_key+0x77>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %eax,(%r15,%rbx,2)
add    $0x2,%rbx
cmp    $0x20,%rbx
jne    1150 <parse_key+0x20>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 = %38, %2
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 16
br i1 %10, label %11, label %41
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 %14, 2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = call i32 @strncpy(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 = load i8, i8* %20
%22 = call i64 @isxdigit(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %11
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 1
%26 = load i8, i8* %25
%27 = call i64 @isxdigit(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%31 = call i32 @strtoul(i8* %30, i32* null, i32 16)
%32 = load i32*, i32** %5
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 %31, i32* %35
br label %37
36: ; preds = %24, %11
store i32 0, i32* %3
br label %42
37: ; preds = %29
br label %38
38: ; preds = %37
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %8
41: ; preds = %8
store i32 1, i32* %3
br label %42
42: ; preds = %41, %36
%43 = load i32, i32* %3
ret i32 %43
}

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 1
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
br label %7
7: ; preds = %2, %19
%8 = phi i64 [ 0, %2 ], [ %22, %19 ]
%9 = shl nuw nsw i64 %8, 1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = call i32 @strncpy(i8* %4, i8* %10, i32 2)
store i8 0, i8* %6
%12 = load i8, i8* %4
%13 = call i64 @isxdigit(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %7
%16 = load i8, i8* %5
%17 = call i64 @isxdigit(i8 signext %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = call i32 @strtoul(i8* nocapture %4, i32* null, i32 16)
%21 = getelementptr inbounds i32, i32* %1, i64 %8
store i32 %20, i32* %21
%22 = add nuw nsw i64 %8, 1
%23 = icmp eq i64 %22, 16
br i1 %23, label %24, label %7
24: ; preds = %19, %7, %15
%25 = phi i32 [ 0, %15 ], [ 0, %7 ], [ 1, %19 ]
ret i32 %25
}