#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 c2n(char c) {
  if (isdigit((unsigned char)c))
    return (int)(c - '0');
  else if (c >= 'a' && c <= 'z')
    return (int)(c - 'a' + 10);
  else if (c >= 'A' && c <= 'Z')
    return (int)(c - 'A' + 10 + 26);
  return -1;
}


x86 assembly (clang, -O0):
<c2n>:
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 <c2n+0x30>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <c2n+0x9c>
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jl     116c <c2n+0x5c>
movsbl -0x5(%rbp),%eax
cmp    $0x7a,%eax
jg     116c <c2n+0x5c>
movsbl -0x5(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <c2n+0x9c>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
jl     119b <c2n+0x8b>
movsbl -0x5(%rbp),%eax
cmp    $0x5a,%eax
jg     119b <c2n+0x8b>
movsbl -0x5(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
add    $0x1a,%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <c2n+0x9c>
jmp    11a0 <c2n+0x90>
jmp    11a5 <c2n+0x95>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define i32 @c2n(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 %41
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, 122
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 %41
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 %38
28: ; preds = %24
%29 = load i8, i8* %3
%30 = sext i8 %29 to i32
%31 = icmp sle i32 %30, 90
br i1 %31, label %32, label %38
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
%37 = add nsw i32 %36, 26
store i32 %37, i32* %2
br label %41
38: ; preds = %28, %24
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39
store i32 -1, i32* %2
br label %41
41: ; preds = %40, %32, %19, %7
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
define i32 @c2n(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, 26
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, 26
%15 = add nsw i32 %4, -29
%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
}