#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 */
typedef int uint8_t;

/* Variables and functions */
int hex_to_bin(int);
int hexascii_to_binary(uint8_t bin_buf[], uint8_t hex_buf[], int n_hex) {
  int i, j;
  for (i = 0, j = 0; i < n_hex; i += 2, j++) {
    bin_buf[j] = (hex_to_bin(hex_buf[i + 1]) << 4) | hex_to_bin(hex_buf[i]);
  }
  return j;
}


x86 assembly (clang, -O0):
<hexascii_to_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118f <hexascii_to_binary+0x7f>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <hex_to_bin@plt>
shl    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <hex_to_bin@plt>
mov    -0x20(%rbp),%edx
or     %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <hexascii_to_binary+0x21>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexascii_to_binary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    115f <hexascii_to_binary+0x4f>
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    0x4(%r12,%rbp,8),%edi
call   1030 <hex_to_bin@plt>
mov    %eax,%r13d
shl    $0x4,%r13d
mov    (%r12,%rbp,8),%edi
call   1030 <hex_to_bin@plt>
or     %r13d,%eax
mov    %eax,(%r15,%rbp,4)
add    $0x1,%rbp
add    $0x2,%ebx
cmp    %r14d,%ebx
jl     1130 <hexascii_to_binary+0x20>
jmp    1161 <hexascii_to_binary+0x51>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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