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


x86 assembly (clang, -O0):
<hextoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1140 <hextoi+0x30>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    119f <hextoi+0x8f>
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jl     116c <hextoi+0x5c>
movsbl -0x5(%rbp),%eax
cmp    $0x66,%eax
jg     116c <hextoi+0x5c>
movsbl -0x5(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    119f <hextoi+0x8f>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
jl     1198 <hextoi+0x88>
movsbl -0x5(%rbp),%eax
cmp    $0x46,%eax
jg     1198 <hextoi+0x88>
movsbl -0x5(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    119f <hextoi+0x8f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hextoi>:
push   %rbx
mov    %edi,%ebx
movzbl %bl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1125 <hextoi+0x15>
add    $0xffffffd0,%ebx
jmp    1143 <hextoi+0x33>
lea    -0x61(%rbx),%eax
cmp    $0x5,%al
ja     1131 <hextoi+0x21>
add    $0xffffffa9,%ebx
jmp    1143 <hextoi+0x33>
lea    -0x41(%rbx),%eax
add    $0xffffffc9,%ebx
cmp    $0x6,%al
mov    $0xffffffff,%eax
cmovb  %ebx,%eax
mov    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

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