#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(unsigned char);
scalar_t__ isdigit(unsigned char);
int hextoint(int c) {
  if (!isascii((unsigned char)c))
    return -1;
  if (isdigit((unsigned char)c))
    return c - '0';
  if ((c >= 'a') && (c <= 'f'))
    return c + 10 - 'a';
  if ((c >= 'A') && (c <= 'F'))
    return c + 10 - 'A';
  return -1;
}


x86 assembly (clang, -O0):
<hextoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
movzbl %al,%edi
call   1040 <isascii@plt>
cmp    $0x0,%eax
jne    114b <hextoint+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <hextoint+0x9f>
mov    -0x8(%rbp),%eax
movzbl %al,%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     116e <hextoint+0x4e>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11bf <hextoint+0x9f>
cmpl   $0x61,-0x8(%rbp)
jl     1193 <hextoint+0x73>
cmpl   $0x66,-0x8(%rbp)
jg     1193 <hextoint+0x73>
mov    -0x8(%rbp),%eax
add    $0xa,%eax
sub    $0x61,%eax
mov    %eax,-0x4(%rbp)
jmp    11bf <hextoint+0x9f>
cmpl   $0x41,-0x8(%rbp)
jl     11b8 <hextoint+0x98>
cmpl   $0x46,-0x8(%rbp)
jg     11b8 <hextoint+0x98>
mov    -0x8(%rbp),%eax
add    $0xa,%eax
sub    $0x41,%eax
mov    %eax,-0x4(%rbp)
jmp    11bf <hextoint+0x9f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hextoint>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
movzbl %bl,%ebp
mov    %ebp,%edi
call   1040 <isascii@plt>
test   %eax,%eax
je     1144 <hextoint+0x24>
mov    %ebp,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     114b <hextoint+0x2b>
add    $0xffffffd0,%ebx
jmp    116b <hextoint+0x4b>
mov    $0xffffffff,%ebx
jmp    116b <hextoint+0x4b>
lea    -0x61(%rbx),%eax
cmp    $0x5,%eax
ja     1158 <hextoint+0x38>
add    $0xffffffa9,%ebx
jmp    116b <hextoint+0x4b>
lea    -0x41(%rbx),%eax
add    $0xffffffc9,%ebx
cmp    $0x6,%eax
mov    $0xffffffff,%eax
cmovb  %ebx,%eax
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hextoint(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = trunc i32 %4 to i8
%6 = call i32 @isascii(i8 zeroext %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 -1, i32* %2
br label %38
9: ; preds = %1
%10 = load i32, i32* %3
%11 = trunc i32 %10 to i8
%12 = call i64 @isdigit(i8 zeroext %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* %3
%16 = sub nsw i32 %15, 48
store i32 %16, i32* %2
br label %38
17: ; preds = %9
%18 = load i32, i32* %3
%19 = icmp sge i32 %18, 97
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %3
%22 = icmp sle i32 %21, 102
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 10
%26 = sub nsw i32 %25, 97
store i32 %26, i32* %2
br label %38
27: ; preds = %20, %17
%28 = load i32, i32* %3
%29 = icmp sge i32 %28, 65
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i32, i32* %3
%32 = icmp sle i32 %31, 70
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 10
%36 = sub nsw i32 %35, 65
store i32 %36, i32* %2
br label %38
37: ; preds = %30, %27
store i32 -1, i32* %2
br label %38
38: ; preds = %37, %33, %23, %14, %8
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
define i32 @hextoint(i32 %0) {
%2 = trunc i32 %0 to i8
%3 = tail call i32 @isascii(i8 zeroext %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %1
%6 = tail call i64 @isdigit(i8 zeroext %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = add nsw i32 %0, -48
br label %20
10: ; preds = %5
%11 = add i32 %0, -97
%12 = icmp ult i32 %11, 6
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = add nsw i32 %0, -87
br label %20
15: ; preds = %10
%16 = add i32 %0, -65
%17 = icmp ult i32 %16, 6
%18 = add nsw i32 %0, -55
%19 = select i1 %17, i32 %18, i32 -1
br label %20
20: ; preds = %15, %1, %13, %8
%21 = phi i32 [ %9, %8 ], [ %14, %13 ], [ -1, %1 ], [ %19, %15 ]
ret i32 %21
}