#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_dec(char const);
void from_hex(const char *hex, size_t len, unsigned char *data) {
  size_t i;
  for (i = 0; i < len; i += 2)
    data[i / 2] = (hex_to_dec(hex[i]) << 4) | (hex_to_dec(hex[i + 1]));
}


x86 assembly (clang, -O0):
<from_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118c <from_hex+0x7c>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <hex_to_dec@plt>
shl    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl 0x1(%rax,%rcx,1),%edi
call   1030 <hex_to_dec@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
or     %ecx,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
shr    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <from_hex+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<from_hex>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rsi,%rsi
je     115f <from_hex+0x4f>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r12,%rbx,1),%edi
call   1030 <hex_to_dec@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x1(%r12,%rbx,1),%edi
call   1030 <hex_to_dec@plt>
or     %ebp,%eax
mov    %rbx,%rcx
shr    %rcx
mov    %al,(%r14,%rcx,1)
add    $0x2,%rbx
cmp    %r15,%rbx
jb     1130 <from_hex+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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