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

/* Variables and functions */
scalar_t__ hexcpy(int /*<<< orphan*/ *, char const *, int);
int /*<<< orphan*/ *malloc(int);
int strlen(char const *);
int parse_hex(uint8_t **dst, const char *src, uintmax_t *len) {
  *len = strlen(src);
  if (*len % 2)
    return 1;
  *len /= 2;
  if ((*dst = malloc(*len)) == NULL)
    return 1;
  if (hexcpy(*dst, src, *len * 2))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<parse_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1178 <parse_hex+0x48>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <parse_hex+0xc0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1040 <malloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11ba <parse_hex+0x8a>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <parse_hex+0xc0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
shl    $0x1,%edx
call   1050 <hexcpy@plt>
cmp    $0x0,%rax
je     11e9 <parse_hex+0xb9>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <parse_hex+0xc0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_hex>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,0x0(%rbp)
mov    $0x1,%r12d
test   $0x1,%al
jne    118a <parse_hex+0x5a>
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
mov    %ebx,0x0(%rbp)
mov    %ebx,%edi
call   1040 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     118a <parse_hex+0x5a>
add    %ebx,%ebx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <hexcpy@plt>
xor    %r12d,%r12d
test   %rax,%rax
setne  %r12b
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_hex(i32** %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i8*
%7 = alloca i32*
store i32** %0, i32*** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%8 = load i8*, i8** %6
%9 = call i32 @strlen(i8* %8)
%10 = load i32*, i32** %7
store i32 %9, i32* %10
%11 = load i32*, i32** %7
%12 = load i32, i32* %11
%13 = srem i32 %12, 2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 1, i32* %4
br label %37
16: ; preds = %3
%17 = load i32*, i32** %7
%18 = load i32, i32* %17
%19 = sdiv i32 %18, 2
store i32 %19, i32* %17
%20 = load i32*, i32** %7
%21 = load i32, i32* %20
%22 = call i32* @malloc(i32 %21)
%23 = load i32**, i32*** %5
store i32* %22, i32** %23
%24 = icmp eq i32* %22, null
br i1 %24, label %25, label %26
25: ; preds = %16
store i32 1, i32* %4
br label %37
26: ; preds = %16
%27 = load i32**, i32*** %5
%28 = load i32*, i32** %27
%29 = load i8*, i8** %6
%30 = load i32*, i32** %7
%31 = load i32, i32* %30
%32 = mul nsw i32 %31, 2
%33 = call i64 @hexcpy(i32* %28, i8* %29, i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %26
store i32 1, i32* %4
br label %37
36: ; preds = %26
store i32 0, i32* %4
br label %37
37: ; preds = %36, %35, %25, %15
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
define i32 @parse_hex(i32** nocapture writeonly %0, i8* %1, i32* nocapture %2) {
%4 = tail call i32 @strlen(i8* %1)
store i32 %4, i32* %2
%5 = and i32 %4, 1
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %3
%8 = sdiv i32 %4, 2
store i32 %8, i32* %2
%9 = tail call i32* @malloc(i32 %8)
store i32* %9, i32** %0
%10 = icmp eq i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = shl nsw i32 %8, 1
%13 = tail call i64 @hexcpy(i32* %9, i8* %1, i32 %12)
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %11, %7, %3
%17 = phi i32 [ 1, %3 ], [ 1, %7 ], [ %15, %11 ]
ret i32 %17
}