#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 sscanf(char const *, char *, int /*<<< orphan*/ *, int *);
int strlen(char const *);
int key_descriptor_to_bytes(const char *hex, uint8_t bytes[8]) {
  if (strlen(hex) != ((2 * 8) + 1) - 1) {
    return -1;
  }
  int i, bytes_converted, chars_read;
  for (i = 0; i < 8; ++i) {
    bytes_converted = sscanf(hex + 2 * i, "%2hhx%n", bytes + i, &chars_read);
    if (bytes_converted != 1 || chars_read != 2) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<key_descriptor_to_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x10,%eax
je     114e <key_descriptor_to_bytes+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <key_descriptor_to_bytes+0xaa>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    11c3 <key_descriptor_to_bytes+0xa3>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe7c(%rip),%rsi
lea    -0x24(%rbp),%rcx
call   1040 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    11a4 <key_descriptor_to_bytes+0x84>
cmpl   $0x2,-0x24(%rbp)
je     11b0 <key_descriptor_to_bytes+0x90>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <key_descriptor_to_bytes+0xaa>
jmp    11b5 <key_descriptor_to_bytes+0x95>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <key_descriptor_to_bytes+0x35>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<key_descriptor_to_bytes>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    $0xffffffff,%ebp
cmp    $0x10,%eax
jne    129e <key_descriptor_to_bytes+0x17e>
lea    0xeb8(%rip),%rsi
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
mov    $0xffffffff,%ebp
cmp    $0x1,%eax
jne    129e <key_descriptor_to_bytes+0x17e>
cmpl   $0x2,0xc(%rsp)
jne    129e <key_descriptor_to_bytes+0x17e>
lea    0x2(%rbx),%rdi
lea    0x4(%r14),%rdx
lea    0xe80(%rip),%rsi
lea    0xc(%rsp),%rcx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    129e <key_descriptor_to_bytes+0x17e>
cmpl   $0x2,0xc(%rsp)
jne    129e <key_descriptor_to_bytes+0x17e>
lea    0x4(%rbx),%rdi
lea    0x8(%r14),%rdx
lea    0xe53(%rip),%rsi
lea    0xc(%rsp),%rcx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    129e <key_descriptor_to_bytes+0x17e>
cmpl   $0x2,0xc(%rsp)
jne    129e <key_descriptor_to_bytes+0x17e>
lea    0x6(%rbx),%rdi
lea    0xc(%r14),%rdx
lea    0xe26(%rip),%rsi
lea    0xc(%rsp),%rcx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    129e <key_descriptor_to_bytes+0x17e>
cmpl   $0x2,0xc(%rsp)
jne    129e <key_descriptor_to_bytes+0x17e>
lea    0x8(%rbx),%rdi
lea    0x10(%r14),%rdx
lea    0xdf9(%rip),%rsi
lea    0xc(%rsp),%rcx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    129e <key_descriptor_to_bytes+0x17e>
cmpl   $0x2,0xc(%rsp)
jne    129e <key_descriptor_to_bytes+0x17e>
lea    0xa(%rbx),%rdi
lea    0x14(%r14),%rdx
lea    0xdd0(%rip),%rsi
lea    0xc(%rsp),%rcx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    129e <key_descriptor_to_bytes+0x17e>
cmpl   $0x2,0xc(%rsp)
jne    129e <key_descriptor_to_bytes+0x17e>
lea    0xc(%rbx),%rdi
lea    0x18(%r14),%rdx
lea    0xdab(%rip),%rsi
lea    0xc(%rsp),%rcx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    129e <key_descriptor_to_bytes+0x17e>
cmpl   $0x2,0xc(%rsp)
jne    129e <key_descriptor_to_bytes+0x17e>
add    $0xe,%rbx
add    $0x1c,%r14
lea    0xd86(%rip),%rsi
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
xor    $0x1,%eax
mov    0xc(%rsp),%ecx
xor    $0x2,%ecx
xor    %ebp,%ebp
or     %eax,%ecx
setne  %bpl
neg    %ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%2hhx%n\00"
define i32 @key_descriptor_to_bytes(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = icmp ne i32 %10, 16
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %39
13: ; preds = %2
store i32 0, i32* %6
br label %14
14: ; preds = %35, %13
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 8
br i1 %16, label %17, label %38
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = load i32, i32* %6
%20 = mul nsw i32 2, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i32*, i32** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %26, i32* %8)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp ne i32 %28, 1
br i1 %29, label %33, label %30
30: ; preds = %17
%31 = load i32, i32* %8
%32 = icmp ne i32 %31, 2
br i1 %32, label %33, label %34
33: ; preds = %30, %17
store i32 -1, i32* %3
br label %39
34: ; preds = %30
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %14
38: ; preds = %14
store i32 0, i32* %3
br label %39
39: ; preds = %38, %33, %12
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [8 x i8] c"%2hhx%n\00"
define i32 @key_descriptor_to_bytes(i8* %0, i32* %1) {
%3 = alloca i32
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 16
br i1 %5, label %6, label %72
6: ; preds = %2
%7 = bitcast i32* %3 to i8*
%8 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %3)
%9 = icmp ne i32 %8, 1
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 2
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %70, label %13
13: ; preds = %6
%14 = getelementptr inbounds i8, i8* %0, i64 2
%15 = getelementptr inbounds i32, i32* %1, i64 1
%16 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %15, i32* %3)
%17 = icmp ne i32 %16, 1
%18 = load i32, i32* %3
%19 = icmp ne i32 %18, 2
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %70, label %21
21: ; preds = %13
%22 = getelementptr inbounds i8, i8* %0, i64 4
%23 = getelementptr inbounds i32, i32* %1, i64 2
%24 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %23, i32* %3)
%25 = icmp ne i32 %24, 1
%26 = load i32, i32* %3
%27 = icmp ne i32 %26, 2
%28 = select i1 %25, i1 true, i1 %27
br i1 %28, label %70, label %29
29: ; preds = %21
%30 = getelementptr inbounds i8, i8* %0, i64 6
%31 = getelementptr inbounds i32, i32* %1, i64 3
%32 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %31, i32* %3)
%33 = icmp ne i32 %32, 1
%34 = load i32, i32* %3
%35 = icmp ne i32 %34, 2
%36 = select i1 %33, i1 true, i1 %35
br i1 %36, label %70, label %37
37: ; preds = %29
%38 = getelementptr inbounds i8, i8* %0, i64 8
%39 = getelementptr inbounds i32, i32* %1, i64 4
%40 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %39, i32* %3)
%41 = icmp ne i32 %40, 1
%42 = load i32, i32* %3
%43 = icmp ne i32 %42, 2
%44 = select i1 %41, i1 true, i1 %43
br i1 %44, label %70, label %45
45: ; preds = %37
%46 = getelementptr inbounds i8, i8* %0, i64 10
%47 = getelementptr inbounds i32, i32* %1, i64 5
%48 = call i32 @sscanf(i8* %46, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %47, i32* %3)
%49 = icmp ne i32 %48, 1
%50 = load i32, i32* %3
%51 = icmp ne i32 %50, 2
%52 = select i1 %49, i1 true, i1 %51
br i1 %52, label %70, label %53
53: ; preds = %45
%54 = getelementptr inbounds i8, i8* %0, i64 12
%55 = getelementptr inbounds i32, i32* %1, i64 6
%56 = call i32 @sscanf(i8* %54, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %55, i32* %3)
%57 = icmp ne i32 %56, 1
%58 = load i32, i32* %3
%59 = icmp ne i32 %58, 2
%60 = select i1 %57, i1 true, i1 %59
br i1 %60, label %70, label %61
61: ; preds = %53
%62 = getelementptr inbounds i8, i8* %0, i64 14
%63 = getelementptr inbounds i32, i32* %1, i64 7
%64 = call i32 @sscanf(i8* %62, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %63, i32* %3)
%65 = icmp ne i32 %64, 1
%66 = load i32, i32* %3
%67 = icmp ne i32 %66, 2
%68 = select i1 %65, i1 true, i1 %67
%69 = sext i1 %68 to i32
br label %70
70: ; preds = %61, %53, %45, %37, %29, %21, %13, %6
%71 = phi i32 [ -1, %6 ], [ -1, %13 ], [ -1, %21 ], [ -1, %29 ], [ -1, %37 ], [ -1, %45 ], [ -1, %53 ], [ %69, %61 ]
br label %72
72: ; preds = %2, %70
%73 = phi i32 [ %71, %70 ], [ -1, %2 ]
ret i32 %73
}