#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 char2int(unsigned char const);
void hex2bin(unsigned char *target, const unsigned char *src, int srcLen) {
  for (int i = 0; i < srcLen; i = i + 2) {
    *(target++) = char2int(*src) * 16 + char2int(src[1]);
    src += 2;
  }
}


x86 assembly (clang, -O0):
<hex2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1189 <hex2bin+0x79>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <char2int@plt>
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%edi
call   1030 <char2int@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <hex2bin+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2bin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
jle    115d <hex2bin+0x4d>
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbp,1),%edi
call   1030 <char2int@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
movzbl 0x1(%r15,%rbp,1),%edi
call   1030 <char2int@plt>
add    %ebx,%eax
mov    %al,(%r12)
add    $0x1,%r12
add    $0x2,%rbp
cmp    %r14d,%ebp
jl     1130 <hex2bin+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @hex2bin(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %27, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %30
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = call i32 @char2int(i8 zeroext %14)
%16 = mul nsw i32 %15, 16
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = call i32 @char2int(i8 zeroext %19)
%21 = add nsw i32 %16, %20
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
store i8 %22, i8* %23
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 2
store i8* %26, i8** %5
br label %27
27: ; preds = %12
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 2
store i32 %29, i32* %7
br label %8
30: ; preds = %8
ret void
}

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