#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__ isupper(int);
int /*<<< orphan*/ isxdigit(int);
int _digittoint(int c) {
  if (!isxdigit(c))
    return 0;
  if (isdigit(c))
    return c - '0';
  else
    return isupper(c) ? c - 'A' + 10 : c - 'a' + 10;
}


x86 assembly (clang, -O0):
<_digittoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%eax
jne    1158 <_digittoint+0x28>
movl   $0x0,-0x4(%rbp)
jmp    11ad <_digittoint+0x7d>
mov    -0x8(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1178 <_digittoint+0x48>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <_digittoint+0x7d>
mov    -0x8(%rbp),%edi
call   1040 <isupper@plt>
cmp    $0x0,%rax
je     119b <_digittoint+0x6b>
mov    -0x8(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0xc(%rbp)
jmp    11a7 <_digittoint+0x77>
mov    -0x8(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_digittoint>:
push   %rbx
mov    %edi,%ebx
call   1050 <isxdigit@plt>
test   %eax,%eax
je     114d <_digittoint+0x1d>
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1151 <_digittoint+0x21>
add    $0xffffffd0,%ebx
jmp    1168 <_digittoint+0x38>
xor    %ebx,%ebx
jmp    1168 <_digittoint+0x38>
mov    %ebx,%edi
call   1040 <isupper@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
shl    $0x5,%ecx
add    %ecx,%ebx
add    $0xffffffa9,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

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