#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 ConvertHex2Int(unsigned char const);
void ConvertHex2Bin(const unsigned char *hex, int len, unsigned char *bin) {
  int j;
  for (j = 0; j < len; j += 2) {
    bin[j / 2] = (ConvertHex2Int(hex[j]) << 4) | ConvertHex2Int(hex[j + 1]);
  }
}


x86 assembly (clang, -O0):
<ConvertHex2Bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119d <ConvertHex2Bin+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <ConvertHex2Int@plt>
shl    $0x4,%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <ConvertHex2Int@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x29(%rbp),%dl
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <ConvertHex2Bin+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

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

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

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