#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 uint8_t;

/* Variables and functions */
int hexchar(char const);
void tobin(uint8_t *const bin, char const *const hex, size_t const hexlen) {
  for (size_t i = 0; i < hexlen / 2; i++) {
    bin[i] = hexchar(hex[i * 2 + 0]) << 4 | hexchar(hex[i * 2 + 1]) << 0;
  }
}


x86 assembly (clang, -O0):
<tobin>:
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
mov    -0x18(%rbp),%rcx
shr    $0x1,%rcx
cmp    %rcx,%rax
jae    1196 <tobin+0x86>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <hexchar@plt>
shl    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
movsbl 0x1(%rax,%rcx,1),%edi
call   1030 <hexchar@plt>
mov    -0x24(%rbp),%edx
shl    $0x0,%eax
or     %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <tobin+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tobin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%rdx
jb     1159 <tobin+0x49>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
shr    %r14
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r12,%rbx,2),%edi
call   1030 <hexchar@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x1(%r12,%rbx,2),%edi
call   1030 <hexchar@plt>
or     %ebp,%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <tobin+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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