#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);
int digittoint(int c) {
  return isdigit(c)             ? c - '0'
         : 'A' <= c && c <= 'Z' ? c - 'A'
         : 'a' <= c && c <= 'z' ? c - 'a'
                                : 99;
}


x86 assembly (clang, -O0):
<digittoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     113b <digittoint+0x2b>
mov    -0x4(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x8(%rbp)
jmp    11a0 <digittoint+0x90>
mov    $0x41,%eax
cmp    -0x4(%rbp),%eax
jg     1161 <digittoint+0x51>
cmpl   $0x5a,-0x4(%rbp)
jg     1161 <digittoint+0x51>
mov    -0x4(%rbp),%eax
sub    $0x41,%eax
mov    %eax,-0xc(%rbp)
jmp    119a <digittoint+0x8a>
mov    $0x61,%eax
cmp    -0x4(%rbp),%eax
jg     1187 <digittoint+0x77>
cmpl   $0x7a,-0x4(%rbp)
jg     1187 <digittoint+0x77>
mov    -0x4(%rbp),%eax
sub    $0x61,%eax
mov    %eax,-0x10(%rbp)
jmp    1194 <digittoint+0x84>
mov    $0x63,%eax
mov    %eax,-0x10(%rbp)
jmp    1194 <digittoint+0x84>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<digittoint>:
push   %rbx
mov    %edi,%ebx
call   1030 <isdigit@plt>
test   %rax,%rax
je     1124 <digittoint+0x14>
add    $0xffffffd0,%ebx
mov    %ebx,%eax
pop    %rbx
ret
lea    -0x41(%rbx),%eax
cmp    $0x1a,%eax
jb     113a <digittoint+0x2a>
add    $0xffffff9f,%ebx
cmp    $0x1a,%ebx
mov    $0x63,%eax
cmovb  %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @digittoint(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i64 @isdigit(i32 %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* %2
%8 = sub nsw i32 %7, 48
br label %32
9: ; preds = %1
%10 = load i32, i32* %2
%11 = icmp sle i32 65, %10
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load i32, i32* %2
%14 = icmp sle i32 %13, 90
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %2
%17 = sub nsw i32 %16, 65
br label %30
18: ; preds = %12, %9
%19 = load i32, i32* %2
%20 = icmp sle i32 97, %19
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* %2
%23 = icmp sle i32 %22, 122
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %2
%26 = sub nsw i32 %25, 97
br label %28
27: ; preds = %21, %18
br label %28
28: ; preds = %27, %24
%29 = phi i32 [ %26, %24 ], [ 99, %27 ]
br label %30
30: ; preds = %28, %15
%31 = phi i32 [ %17, %15 ], [ %29, %28 ]
br label %32
32: ; preds = %30, %6
%33 = phi i32 [ %8, %6 ], [ %31, %30 ]
ret i32 %33
}

LLVM IR (-O2):
define i32 @digittoint(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 %13
6: ; preds = %1
%7 = add i32 %0, -65
%8 = icmp ult i32 %7, 26
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = add i32 %0, -97
%11 = icmp ult i32 %10, 26
%12 = select i1 %11, i32 %10, i32 99
br label %13
13: ; preds = %6, %9, %4
%14 = phi i32 [ %5, %4 ], [ %12, %9 ], [ %7, %6 ]
ret i32 %14
}