#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;
typedef int ssize_t;

/* Variables and functions */
int _xctoi(int /*<<< orphan*/);
ssize_t unhexlify(uint8_t *out, size_t out_len, const uint8_t *in,
                  size_t in_len) {
  uint8_t c1, c2;
  size_t len;
  if (in_len % 2 != 0)
    return -1;
  len = in_len / 2;
  if (out_len < len)
    return -1;
  while (in_len > 0) {
    c1 = *in++;
    c2 = *in++;
    *out++ = (_xctoi(c1) << 4) + _xctoi(c2);
    in_len -= 2;
  }
  return len;
}


x86 assembly (clang, -O0):
<unhexlify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1146 <unhexlify+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <unhexlify+0xd8>
mov    -0x28(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    116c <unhexlify+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <unhexlify+0xd8>
jmp    1171 <unhexlify+0x61>
cmpq   $0x0,-0x28(%rbp)
jbe    11e1 <unhexlify+0xd1>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <_xctoi@plt>
shl    $0x4,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%edi
call   1030 <_xctoi@plt>
mov    -0x3c(%rbp),%ecx
add    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
sub    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    1171 <unhexlify+0x61>
mov    -0x38(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unhexlify>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    $0xffffffff,%eax
test   $0x1,%r14b
jne    117d <unhexlify+0x6d>
mov    %r14,%rcx
shr    %rcx
cmp    %rsi,%rcx
ja     117d <unhexlify+0x6d>
mov    %rcx,(%rsp)
test   %r14,%r14
je     1179 <unhexlify+0x69>
mov    %rdx,%r12
mov    %rdi,%r15
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
mov    (%r12,%r13,4),%edi
mov    0x4(%r12,%r13,4),%ebp
call   1030 <_xctoi@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
mov    %ebp,%edi
call   1030 <_xctoi@plt>
add    %ebx,%eax
mov    %eax,(%r15,%r13,2)
add    $0x2,%r13
cmp    %r13,%r14
jne    1150 <unhexlify+0x40>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @unhexlify(i32* %0, i64 %1, i32* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
store i32* %0, i32** %6
store i64 %1, i64* %7
store i32* %2, i32** %8
store i64 %3, i64* %9
%13 = load i64, i64* %9
%14 = urem i64 %13, 2
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -1, i32* %5
br label %48
17: ; preds = %4
%18 = load i64, i64* %9
%19 = udiv i64 %18, 2
store i64 %19, i64* %12
%20 = load i64, i64* %7
%21 = load i64, i64* %12
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 -1, i32* %5
br label %48
24: ; preds = %17
br label %25
25: ; preds = %28, %24
%26 = load i64, i64* %9
%27 = icmp ugt i64 %26, 0
br i1 %27, label %28, label %45
28: ; preds = %25
%29 = load i32*, i32** %8
%30 = getelementptr inbounds i32, i32* %29, i32 1
store i32* %30, i32** %8
%31 = load i32, i32* %29
store i32 %31, i32* %10
%32 = load i32*, i32** %8
%33 = getelementptr inbounds i32, i32* %32, i32 1
store i32* %33, i32** %8
%34 = load i32, i32* %32
store i32 %34, i32* %11
%35 = load i32, i32* %10
%36 = call i32 @_xctoi(i32 %35)
%37 = shl i32 %36, 4
%38 = load i32, i32* %11
%39 = call i32 @_xctoi(i32 %38)
%40 = add nsw i32 %37, %39
%41 = load i32*, i32** %6
%42 = getelementptr inbounds i32, i32* %41, i32 1
store i32* %42, i32** %6
store i32 %40, i32* %41
%43 = load i64, i64* %9
%44 = sub i64 %43, 2
store i64 %44, i64* %9
br label %25
45: ; preds = %25
%46 = load i64, i64* %12
%47 = trunc i64 %46 to i32
store i32 %47, i32* %5
br label %48
48: ; preds = %45, %23, %16
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
define i32 @unhexlify(i32* nocapture writeonly %0, i64 %1, i32* nocapture %2, i64 %3) {
%5 = and i64 %3, 1
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %29
7: ; preds = %4
%8 = lshr i64 %3, 1
%9 = icmp ugt i64 %8, %1
br i1 %9, label %29, label %10
10: ; preds = %7
%11 = icmp eq i64 %3, 0
br i1 %11, label %27, label %12
12: ; preds = %10, %12
%13 = phi i32* [ %24, %12 ], [ %0, %10 ]
%14 = phi i32* [ %18, %12 ], [ %2, %10 ]
%15 = phi i64 [ %25, %12 ], [ %3, %10 ]
%16 = getelementptr inbounds i32, i32* %14, i64 1
%17 = load i32, i32* %14
%18 = getelementptr inbounds i32, i32* %14, i64 2
%19 = load i32, i32* %16
%20 = tail call i32 @_xctoi(i32 %17)
%21 = shl i32 %20, 4
%22 = tail call i32 @_xctoi(i32 %19)
%23 = add nsw i32 %21, %22
%24 = getelementptr inbounds i32, i32* %13, i64 1
store i32 %23, i32* %13
%25 = add i64 %15, -2
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %12
27: ; preds = %12, %10
%28 = trunc i64 %8 to i32
br label %29
29: ; preds = %7, %4, %27
%30 = phi i32 [ %28, %27 ], [ -1, %4 ], [ -1, %7 ]
ret i32 %30
}