#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 *, char const *, int);
scalar_t__ strtoul(char *, char **, int);
int hexcpy(void *dst, const void *src, size_t len) {
  char buf[3] = {0}, *endptr = &buf[2];
  unsigned char *ptr = dst;
  size_t i;
  if (len % 2)
    return 1;
  for (i = 0; i < len / 2; ++i) {
    memcpy(buf, ((const char *)src) + (i * 2), 2);
    ptr[i] = (unsigned char)strtoul(buf, &endptr, 16);
    if (*endptr)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<hexcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x23(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <memset@plt>
lea    -0x23(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1186 <hexcpy+0x56>
movl   $0x1,-0x4(%rbp)
jmp    1215 <hexcpy+0xe5>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x20(%rbp),%rcx
shr    $0x1,%rcx
cmp    %rcx,%rax
jae    120e <hexcpy+0xde>
lea    -0x23(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%rax
shl    $0x1,%rax
add    %rax,%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
lea    -0x23(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %al,%dl
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f8 <hexcpy+0xc8>
movl   $0x1,-0x4(%rbp)
jmp    1215 <hexcpy+0xe5>
jmp    11fd <hexcpy+0xcd>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    118e <hexcpy+0x5e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexcpy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
movb   $0x0,0xe(%rsp)
movw   $0x0,0xc(%rsp)
lea    0xe(%rsp),%rax
mov    %rax,0x10(%rsp)
test   $0x1,%r14b
jne    11af <hexcpy+0x8f>
xor    %eax,%eax
cmp    $0x2,%r14
jb     11b4 <hexcpy+0x94>
mov    %rsi,%rbx
mov    %rdi,%r15
shr    %r14
xor    %ebp,%ebp
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <memcpy@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %al,(%r15,%rbp,1)
mov    0x10(%rsp),%rax
cmpb   $0x0,(%rax)
jne    11af <hexcpy+0x8f>
add    $0x1,%rbp
add    $0x2,%rbx
cmp    %rbp,%r14
jne    1170 <hexcpy+0x50>
xor    %eax,%eax
jmp    11b4 <hexcpy+0x94>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hexcpy(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [3 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%12 = bitcast [3 x i8]* %8 to i8*
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 2
store i8* %13, i8** %9
%14 = load i8*, i8** %5
store i8* %14, i8** %10
%15 = load i64, i64* %7
%16 = urem i64 %15, 2
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 1, i32* %4
br label %47
19: ; preds = %3
store i64 0, i64* %11
br label %20
20: ; preds = %43, %19
%21 = load i64, i64* %11
%22 = load i64, i64* %7
%23 = udiv i64 %22, 2
%24 = icmp ult i64 %21, %23
br i1 %24, label %25, label %46
25: ; preds = %20
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%27 = load i8*, i8** %6
%28 = load i64, i64* %11
%29 = mul i64 %28, 2
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = call i32 @memcpy(i8* %26, i8* %30, i32 2)
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%33 = call i64 @strtoul(i8* %32, i8** %9, i32 16)
%34 = trunc i64 %33 to i8
%35 = load i8*, i8** %10
%36 = load i64, i64* %11
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8 %34, i8* %37
%38 = load i8*, i8** %9
%39 = load i8, i8* %38
%40 = icmp ne i8 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %25
store i32 1, i32* %4
br label %47
42: ; preds = %25
br label %43
43: ; preds = %42
%44 = load i64, i64* %11
%45 = add i64 %44, 1
store i64 %45, i64* %11
br label %20
46: ; preds = %20
store i32 0, i32* %4
br label %47
47: ; preds = %46, %41, %18
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
define i32 @hexcpy(i8* nocapture writeonly %0, i8* %1, i64 %2) {
%4 = alloca [3 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%7 = bitcast i8** %5 to i8*
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
store i8* %8, i8** %5
%9 = and i64 %2, 1
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %29
11: ; preds = %3
%12 = icmp ult i64 %2, 2
br i1 %12, label %29, label %13
13: ; preds = %11
%14 = lshr i64 %2, 1
br label %17
15: ; preds = %17
%16 = icmp eq i64 %28, %14
br i1 %16, label %29, label %17
17: ; preds = %13, %15
%18 = phi i64 [ %28, %15 ], [ 0, %13 ]
%19 = shl nuw i64 %18, 1
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = call i32 @memcpy(i8* %6, i8* %20, i32 2)
%22 = call i64 @strtoul(i8* %6, i8** %5, i32 16)
%23 = trunc i64 %22 to i8
%24 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 %23, i8* %24
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
%28 = add nuw nsw i64 %18, 1
br i1 %27, label %15, label %29
29: ; preds = %17, %15, %11, %3
%30 = phi i32 [ 1, %3 ], [ 0, %11 ], [ 1, %17 ], [ 0, %15 ]
ret i32 %30
}