#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*/ isascii(int);
scalar_t__ isdigit(int);
int tolower(int);
int hex2int(int c) {
  int l = tolower(c);
  if (!isascii(l))
    return -1;
  if (isdigit(l))
    return l - '0';
  if ((l >= 'a') && (l <= 'f'))
    return l + 10 - 'a';
  return -1;
}


x86 assembly (clang, -O0):
<hex2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <tolower@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <isascii@plt>
cmp    $0x0,%eax
jne    1163 <hex2int+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <hex2int+0x7f>
mov    -0xc(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1183 <hex2int+0x53>
mov    -0xc(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11af <hex2int+0x7f>
cmpl   $0x61,-0xc(%rbp)
jl     11a8 <hex2int+0x78>
cmpl   $0x66,-0xc(%rbp)
jg     11a8 <hex2int+0x78>
mov    -0xc(%rbp),%eax
add    $0xa,%eax
sub    $0x61,%eax
mov    %eax,-0x4(%rbp)
jmp    11af <hex2int+0x7f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2int>:
push   %rbx
call   1040 <tolower@plt>
mov    %eax,%ebx
mov    $0xffffffff,%eax
cmp    $0x7f,%ebx
ja     1156 <hex2int+0x36>
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1145 <hex2int+0x25>
add    $0xffffffd0,%ebx
mov    %ebx,%eax
pop    %rbx
ret
lea    -0x61(%rbx),%eax
add    $0xffffffa9,%ebx
cmp    $0x6,%eax
mov    $0xffffffff,%eax
cmovb  %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @hex2int(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @tolower(i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = call i32 @isascii(i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 -1, i32* %2
br label %29
11: ; preds = %1
%12 = load i32, i32* %4
%13 = call i64 @isdigit(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 48
store i32 %17, i32* %2
br label %29
18: ; preds = %11
%19 = load i32, i32* %4
%20 = icmp sge i32 %19, 97
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %4
%23 = icmp sle i32 %22, 102
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 10
%27 = sub nsw i32 %26, 97
store i32 %27, i32* %2
br label %29
28: ; preds = %21, %18
store i32 -1, i32* %2
br label %29
29: ; preds = %28, %24, %15, %10
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @hex2int(i32 %0) {
%2 = tail call i32 @tolower(i32 %0)
%3 = icmp ult i32 %2, 128
br i1 %3, label %4, label %14
4: ; preds = %1
%5 = tail call i64 @isdigit(i32 %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = add nsw i32 %2, -48
br label %14
9: ; preds = %4
%10 = add nsw i32 %2, -97
%11 = icmp ult i32 %10, 6
%12 = add nsw i32 %2, -87
%13 = select i1 %11, i32 %12, i32 -1
br label %14
14: ; preds = %9, %1, %7
%15 = phi i32 [ %8, %7 ], [ -1, %1 ], [ %13, %9 ]
ret i32 %15
}