#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 char2int(char const);
void hex2bin(const char *src, uint8_t *target) {
  while (*src && src[1]) {
    *(target++) = (char2int(src[0]) << 4) | (char2int(src[1]) & 0xff);
    src += 2;
  }
}


x86 assembly (clang, -O0):
<hex2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     1146 <hex2bin+0x36>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1156 <hex2bin+0x46>
jmp    11a1 <hex2bin+0x91>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <char2int@plt>
shl    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <char2int@plt>
mov    -0x18(%rbp),%ecx
and    $0xff,%eax
or     %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    1120 <hex2bin+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2bin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1167 <hex2bin+0x57>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x0,0x1(%r15,%rbx,1)
je     1167 <hex2bin+0x57>
movsbl %al,%edi
call   1030 <char2int@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x1(%r15,%rbx,1),%edi
call   1030 <char2int@plt>
movzbl %al,%eax
or     %ebp,%eax
mov    %eax,(%r14,%rbx,2)
movzbl 0x2(%r15,%rbx,1),%eax
add    $0x2,%rbx
test   %al,%al
jne    1130 <hex2bin+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @hex2bin(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
store i32* %1, i32** %4
br label %5
5: ; preds = %18, %2
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br label %16
16: ; preds = %10, %5
%17 = phi i1 [ false, %5 ], [ %15, %10 ]
br i1 %17, label %18, label %34
18: ; preds = %16
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = call i32 @char2int(i8 signext %21)
%23 = shl i32 %22, 4
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = call i32 @char2int(i8 signext %26)
%28 = and i32 %27, 255
%29 = or i32 %23, %28
%30 = load i32*, i32** %4
%31 = getelementptr inbounds i32, i32* %30, i32 1
store i32* %31, i32** %4
store i32 %29, i32* %30
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 2
store i8* %33, i8** %3
br label %5
34: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @hex2bin(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %2, %12
%6 = phi i8 [ %21, %12 ], [ %3, %2 ]
%7 = phi i32* [ %19, %12 ], [ %1, %2 ]
%8 = phi i8* [ %20, %12 ], [ %0, %2 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %5
%13 = tail call i32 @char2int(i8 signext %6)
%14 = shl i32 %13, 4
%15 = load i8, i8* %9
%16 = tail call i32 @char2int(i8 signext %15)
%17 = and i32 %16, 255
%18 = or i32 %17, %14
%19 = getelementptr inbounds i32, i32* %7, i64 1
store i32 %18, i32* %7
%20 = getelementptr inbounds i8, i8* %8, i64 2
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %5
23: ; preds = %5, %12, %2
ret void
}