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


x86 assembly (clang, -O0):
<hex2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shr    $0x1,%rax
cmp    -0x18(%rbp),%rax
jae    1180 <hex2bin+0x70>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl %dl,%edi
movsbl 0x1(%rax,%rcx,1),%esi
call   1030 <chars_to_byte@plt>
mov    %al,%dl
mov    -0x8(%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 <hex2bin+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2bin>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdx,%rdx
je     1154 <hex2bin+0x44>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    $0x2,%r13d
xor    %ebx,%ebx
nop
movsbl -0x2(%r12,%r13,1),%edi
movsbl -0x1(%r12,%r13,1),%esi
call   1030 <chars_to_byte@plt>
mov    %al,(%r15,%rbx,1)
mov    %r13,%rbx
shr    %rbx
add    $0x2,%r13
cmp    %r14,%rbx
jb     1130 <hex2bin+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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