#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 /*<<< orphan*/ memcpy(char *, unsigned char *, int);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
void hextobin(unsigned char *v, unsigned char *s, size_t n) {
  unsigned int i;
  char _t[3];
  unsigned char *p = s;
  for (i = 0; i < n; ++i) {
    memcpy(_t, p, 2);
    _t[2] = '\0';
    v[i] = (int)strtol(_t, NULL, 16);
    p += 2;
  }
}


x86 assembly (clang, -O0):
<hextobin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    119e <hextobin+0x7e>
lea    -0x1f(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
movb   $0x0,-0x1d(%rbp)
lea    -0x1f(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1143 <hextobin+0x23>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hextobin>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %rdx,%rdx
je     1184 <hextobin+0x64>
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
xor    %ebx,%ebx
lea    0xd(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
movb   $0x0,0xf(%rsp)
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,(%r15,%rbx,1)
add    $0x2,%r13
add    $0x1,%ebx
cmp    %r14,%rbx
jb     1150 <hextobin+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @hextobin(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca [3 x i8]
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i8*, i8** %5
store i8* %10, i8** %9
store i32 0, i32* %7
br label %11
11: ; preds = %31, %3
%12 = load i32, i32* %7
%13 = zext i32 %12 to i64
%14 = load i64, i64* %6
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %34
16: ; preds = %11
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%18 = load i8*, i8** %9
%19 = call i32 @memcpy(i8* %17, i8* %18, i32 2)
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 2
store i8 0, i8* %20
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%22 = call i64 @strtol(i8* %21, i32* null, i32 16)
%23 = trunc i64 %22 to i32
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %4
%26 = load i32, i32* %7
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
%29 = load i8*, i8** %9
%30 = getelementptr inbounds i8, i8* %29, i64 2
store i8* %30, i8** %9
br label %31
31: ; preds = %16
%32 = load i32, i32* %7
%33 = add i32 %32, 1
store i32 %33, i32* %7
br label %11
34: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @hextobin(i8* nocapture writeonly %0, i8* %1, i64 %2) {
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%6 = icmp eq i64 %2, 0
br i1 %6, label %20, label %7
7: ; preds = %3
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %18, %9 ]
%11 = phi i8* [ %1, %7 ], [ %16, %9 ]
%12 = call i32 @memcpy(i8* %5, i8* %11, i32 2)
store i8 0, i8* %8
%13 = call i64 @strtol(i8* nocapture %5, i32* null, i32 16)
%14 = trunc i64 %13 to i8
%15 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 %14, i8* %15
%16 = getelementptr inbounds i8, i8* %11, i64 2
%17 = add nuw nsw i64 %10, 1
%18 = and i64 %17, 4294967295
%19 = icmp ult i64 %18, %2
br i1 %19, label %9, label %20
20: ; preds = %9, %3
ret void
}