#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 hexCharToNibble(char);
void utilHexToBin(char *hexIn, unsigned char *binOut, int len) {
  unsigned char b;
  char lo, hi;
  for (b = 0; b < len; b++) {
    hi = hexIn[b * 2];
    lo = hexIn[(b * 2) + 1];
    binOut[b] = (hexCharToNibble(hi) * 16) + hexCharToNibble(lo);
  }
}


x86 assembly (clang, -O0):
<utilHexToBin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1198 <utilHexToBin+0x88>
mov    -0x8(%rbp),%rax
movzbl -0x15(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x17(%rbp)
mov    -0x8(%rbp),%rax
movzbl -0x15(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x16(%rbp)
movsbl -0x17(%rbp),%edi
call   1030 <hexCharToNibble@plt>
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x16(%rbp),%edi
call   1030 <hexCharToNibble@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movzbl -0x15(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x15(%rbp),%al
add    $0x1,%al
mov    %al,-0x15(%rbp)
jmp    1127 <utilHexToBin+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utilHexToBin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    116e <utilHexToBin+0x5e>
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,%r13
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%r14d
lea    (%r14,%r14,1),%rax
movsbl 0x0(%r13,%r14,2),%edi
mov    %eax,%eax
movsbl 0x1(%r13,%rax,1),%eax
mov    %eax,0x4(%rsp)
call   1030 <hexCharToNibble@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
mov    0x4(%rsp),%edi
call   1030 <hexCharToNibble@plt>
add    %ebx,%eax
mov    %al,(%r15,%r14,1)
add    $0x1,%ebp
movzbl %bpl,%ebp
cmp    %r12d,%ebp
jl     1130 <utilHexToBin+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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