#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 /*<<< orphan*/ u_int8_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/ const *, unsigned int);
unsigned int strtoul(char *, char **, int);
int hextoint(const u_int8_t *p, unsigned int l) {
  char buf[16], *e;
  unsigned int r;
  memcpy(buf, p, l);
  buf[l] = 0;
  r = strtoul(buf, &e, 16);
  if (*e)
    return -1;
  return r;
}


x86 assembly (clang, -O0):
<hextoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x14(%rbp),%eax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     1175 <hextoint+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    117b <hextoint+0x5b>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hextoint>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %rdi,%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <memcpy@plt>
mov    %ebx,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    0x8(%rsp),%rcx
xor    %edx,%edx
cmp    (%rcx),%dl
sbb    %ecx,%ecx
or     %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @hextoint(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [16 x i8]
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%10 = load i32*, i32** %4
%11 = load i32, i32* %5
%12 = call i32 @memcpy(i8* %9, i32* %10, i32 %11)
%13 = load i32, i32* %5
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %14
store i8 0, i8* %15
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%17 = call i32 @strtoul(i8* %16, i8** %7, i32 16)
store i32 %17, i32* %8
%18 = load i8*, i8** %7
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %2
store i32 -1, i32* %3
br label %24
22: ; preds = %2
%23 = load i32, i32* %8
store i32 %23, i32* %3
br label %24
24: ; preds = %22, %21
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
define i32 @hextoint(i32* %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = call i32 @memcpy(i8* %5, i32* %0, i32 %1)
%8 = zext i32 %1 to i64
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %8
store i8 0, i8* %9
%10 = call i32 @strtoul(i8* %5, i8** %4, i32 16)
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
%14 = select i1 %13, i32 %10, i32 -1
ret i32 %14
}