#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_decode_ch(char const);
void hex_decode(char *hexstr, const char *symstr, size_t hsize) {
  size_t i;
  for (i = 0; 2 * i < hsize; i++)
    hexstr[i] =
        (hex_decode_ch(symstr[2 * i]) << 4) + hex_decode_ch(symstr[2 * i + 1]);
}


x86 assembly (clang, -O0):
<hex_decode>:
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
shl    $0x1,%rax
cmp    -0x18(%rbp),%rax
jae    1194 <hex_decode+0x84>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <hex_decode_ch@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 <hex_decode_ch@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <hex_decode+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

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

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

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