#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 hex_to_bin(int /*<<< orphan*/);
int hex2bin(unsigned char *dst, const char *src, size_t count) {
  while (count--) {
    int hi = hex_to_bin(*src++);
    int lo = hex_to_bin(*src++);
    if ((hi < 0) || (lo < 0))
      return -1;
    *dst++ = (hi << 4) | lo;
  }
  return 0;
}


x86 assembly (clang, -O0):
<hex2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     11b2 <hex2bin+0xa2>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%edi
call   1030 <hex_to_bin@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%edi
call   1030 <hex_to_bin@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1185 <hex2bin+0x75>
cmpl   $0x0,-0x28(%rbp)
jge    1191 <hex2bin+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <hex2bin+0xa9>
mov    -0x24(%rbp),%eax
shl    $0x4,%eax
or     -0x28(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1124 <hex2bin+0x14>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2bin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdx,%rdx
je     1168 <hex2bin+0x58>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r12,%rbx,2),%edi
call   1030 <hex_to_bin@plt>
mov    %eax,%ebp
movsbl 0x1(%r12,%rbx,2),%edi
call   1030 <hex_to_bin@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ebp,%ebp
js     116a <hex2bin+0x5a>
test   %ecx,%ecx
js     116a <hex2bin+0x5a>
shl    $0x4,%ebp
or     %ebp,%ecx
mov    %cl,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <hex2bin+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hex2bin(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
br label %10
10: ; preds = %31, %3
%11 = load i64, i64* %7
%12 = add i64 %11, -1
store i64 %12, i64* %7
%13 = icmp ne i64 %11, 0
br i1 %13, label %14, label %39
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %6
%17 = load i8, i8* %15
%18 = sext i8 %17 to i32
%19 = call i32 @hex_to_bin(i32 %18)
store i32 %19, i32* %8
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %6
%22 = load i8, i8* %20
%23 = sext i8 %22 to i32
%24 = call i32 @hex_to_bin(i32 %23)
store i32 %24, i32* %9
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %14
%28 = load i32, i32* %9
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27, %14
store i32 -1, i32* %4
br label %40
31: ; preds = %27
%32 = load i32, i32* %8
%33 = shl i32 %32, 4
%34 = load i32, i32* %9
%35 = or i32 %33, %34
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %5
store i8 %36, i8* %37
br label %10
39: ; preds = %10
store i32 0, i32* %4
br label %40
40: ; preds = %39, %30
%41 = load i32, i32* %4
ret i32 %41
}

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