#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_val(char const);
void char_unhexdigest(const char *str, const size_t lenbytes, char *bytes) {
  for (size_t i = 0; i < lenbytes; i++) {
    bytes[i] = (hex_val(str[i << 1]) << 4) | (hex_val(str[1 + (i << 1)]));
  }
}


x86 assembly (clang, -O0):
<char_unhexdigest>:
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    1193 <char_unhexdigest+0x83>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <hex_val@plt>
shl    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
add    $0x1,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <hex_val@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
or     %ecx,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <char_unhexdigest+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

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

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

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