#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(int);
scalar_t__ islower(int);
scalar_t__ isupper(int);
int xtoi(int c) {
  if (isdigit(c))
    return c - '0';
  if (islower(c))
    return 10 + c - 'a';
  if (isupper(c))
    return 10 + c - 'A';
  return 0;
}


x86 assembly (clang, -O0):
<xtoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     115b <xtoi+0x2b>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <xtoi+0x78>
mov    -0x8(%rbp),%edi
call   1040 <islower@plt>
cmp    $0x0,%rax
je     117e <xtoi+0x4e>
mov    -0x8(%rbp),%eax
add    $0xa,%eax
sub    $0x61,%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <xtoi+0x78>
mov    -0x8(%rbp),%edi
call   1050 <isupper@plt>
cmp    $0x0,%rax
je     11a1 <xtoi+0x71>
mov    -0x8(%rbp),%eax
add    $0xa,%eax
sub    $0x41,%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <xtoi+0x78>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xtoi>:
push   %rbx
mov    %edi,%ebx
call   1030 <isdigit@plt>
test   %rax,%rax
je     1142 <xtoi+0x12>
add    $0xffffffd0,%ebx
jmp    1165 <xtoi+0x35>
mov    %ebx,%edi
call   1040 <islower@plt>
test   %rax,%rax
je     1153 <xtoi+0x23>
add    $0xffffffa9,%ebx
jmp    1165 <xtoi+0x35>
mov    %ebx,%edi
call   1050 <isupper@plt>
add    $0xffffffc9,%ebx
xor    %ecx,%ecx
test   %rax,%rax
cmove  %ecx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

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