#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 toupper(char);
int s_mp_tovalue(char ch, int r) {
  int val, xch;
  if (r > 36)
    xch = ch;
  else
    xch = toupper(ch);
  if (isdigit(xch))
    val = xch - '0';
  else if (isupper(xch))
    val = xch - 'A' + 10;
  else if (islower(xch))
    val = xch - 'a' + 36;
  else if (xch == '+')
    val = 62;
  else if (xch == '/')
    val = 63;
  else
    return -1;
  if (val < 0 || val >= r)
    return -1;
  return val;
}


x86 assembly (clang, -O0):
<s_mp_tovalue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x24,-0xc(%rbp)
jle    1167 <s_mp_tovalue+0x27>
movsbl -0x5(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1173 <s_mp_tovalue+0x33>
movsbl -0x5(%rbp),%edi
call   1050 <toupper@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1193 <s_mp_tovalue+0x53>
mov    -0x14(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x10(%rbp)
jmp    1225 <s_mp_tovalue+0xe5>
mov    -0x14(%rbp),%edi
call   1060 <isupper@plt>
cmp    $0x0,%rax
je     11b6 <s_mp_tovalue+0x76>
mov    -0x14(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x10(%rbp)
jmp    1220 <s_mp_tovalue+0xe0>
mov    -0x14(%rbp),%edi
call   1040 <islower@plt>
cmp    $0x0,%rax
je     11d9 <s_mp_tovalue+0x99>
mov    -0x14(%rbp),%eax
sub    $0x61,%eax
add    $0x24,%eax
mov    %eax,-0x10(%rbp)
jmp    121b <s_mp_tovalue+0xdb>
cmpl   $0x2b,-0x14(%rbp)
jne    11ef <s_mp_tovalue+0xaf>
movl   $0x3e,-0x10(%rbp)
jmp    1216 <s_mp_tovalue+0xd6>
cmpl   $0x2f,-0x14(%rbp)
jne    1205 <s_mp_tovalue+0xc5>
movl   $0x3f,-0x10(%rbp)
jmp    1211 <s_mp_tovalue+0xd1>
movl   $0xffffffff,-0x4(%rbp)
jmp    124d <s_mp_tovalue+0x10d>
jmp    1216 <s_mp_tovalue+0xd6>
jmp    121b <s_mp_tovalue+0xdb>
jmp    1220 <s_mp_tovalue+0xe0>
jmp    1225 <s_mp_tovalue+0xe5>
cmpl   $0x0,-0x10(%rbp)
jl     123b <s_mp_tovalue+0xfb>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1247 <s_mp_tovalue+0x107>
movl   $0xffffffff,-0x4(%rbp)
jmp    124d <s_mp_tovalue+0x10d>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_mp_tovalue>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
cmp    $0x25,%esi
jl     1150 <s_mp_tovalue+0x10>
movsbl %dil,%ebp
jmp    115b <s_mp_tovalue+0x1b>
movsbl %dil,%edi
call   1050 <toupper@plt>
mov    %eax,%ebp
mov    %ebp,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     116c <s_mp_tovalue+0x2c>
add    $0xffffffd0,%ebp
jmp    118c <s_mp_tovalue+0x4c>
mov    %ebp,%edi
call   1060 <isupper@plt>
test   %rax,%rax
je     117d <s_mp_tovalue+0x3d>
add    $0xffffffc9,%ebp
jmp    118c <s_mp_tovalue+0x4c>
mov    %ebp,%edi
call   1040 <islower@plt>
test   %rax,%rax
je     11a7 <s_mp_tovalue+0x67>
add    $0xffffffc3,%ebp
cmp    %ebx,%ebp
mov    $0xffffffff,%eax
cmovl  %ebp,%eax
mov    $0xffffffff,%ecx
test   %ebp,%ebp
cmovs  %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
cmp    $0x2b,%ebp
je     11bd <s_mp_tovalue+0x7d>
mov    $0xffffffff,%eax
cmp    $0x2f,%ebp
jne    11a0 <s_mp_tovalue+0x60>
mov    $0x3f,%ebp
jmp    118c <s_mp_tovalue+0x4c>
mov    $0x3e,%ebp
jmp    118c <s_mp_tovalue+0x4c>

LLVM IR (-O0):
define i32 @s_mp_tovalue(i8 signext %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8 %0, i8* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp sgt i32 %8, 36
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
store i32 %12, i32* %7
br label %16
13: ; preds = %2
%14 = load i8, i8* %4
%15 = call i32 @toupper(i8 signext %14)
store i32 %15, i32* %7
br label %16
16: ; preds = %13, %10
%17 = load i32, i32* %7
%18 = call i64 @isdigit(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* %7
%22 = sub nsw i32 %21, 48
store i32 %22, i32* %6
br label %52
23: ; preds = %16
%24 = load i32, i32* %7
%25 = call i64 @isupper(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* %7
%29 = sub nsw i32 %28, 65
%30 = add nsw i32 %29, 10
store i32 %30, i32* %6
br label %51
31: ; preds = %23
%32 = load i32, i32* %7
%33 = call i64 @islower(i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i32, i32* %7
%37 = sub nsw i32 %36, 97
%38 = add nsw i32 %37, 36
store i32 %38, i32* %6
br label %50
39: ; preds = %31
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, 43
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 62, i32* %6
br label %49
43: ; preds = %39
%44 = load i32, i32* %7
%45 = icmp eq i32 %44, 47
br i1 %45, label %46, label %47
46: ; preds = %43
store i32 63, i32* %6
br label %48
47: ; preds = %43
store i32 -1, i32* %3
br label %62
48: ; preds = %46
br label %49
49: ; preds = %48, %42
br label %50
50: ; preds = %49, %35
br label %51
51: ; preds = %50, %27
br label %52
52: ; preds = %51, %20
%53 = load i32, i32* %6
%54 = icmp slt i32 %53, 0
br i1 %54, label %59, label %55
55: ; preds = %52
%56 = load i32, i32* %6
%57 = load i32, i32* %5
%58 = icmp sge i32 %56, %57
br i1 %58, label %59, label %60
59: ; preds = %55, %52
store i32 -1, i32* %3
br label %62
60: ; preds = %55
%61 = load i32, i32* %6
store i32 %61, i32* %3
br label %62
62: ; preds = %60, %59, %47
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
define i32 @s_mp_tovalue(i8 signext %0, i32 %1) {
%3 = icmp sgt i32 %1, 36
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = sext i8 %0 to i32
br label %8
6: ; preds = %2
%7 = tail call i32 @toupper(i8 signext %0)
br label %8
8: ; preds = %6, %4
%9 = phi i32 [ %5, %4 ], [ %7, %6 ]
%10 = tail call i64 @isdigit(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = add nsw i32 %9, -48
br label %26
14: ; preds = %8
%15 = tail call i64 @isupper(i32 %9)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = add nsw i32 %9, -55
br label %26
19: ; preds = %14
%20 = tail call i64 @islower(i32 %9)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = add nsw i32 %9, -61
br label %26
24: ; preds = %19
switch i32 %9, label %32 [
i32 43, label %26
i32 47, label %25
]
25: ; preds = %24
br label %26
26: ; preds = %24, %17, %25, %22, %12
%27 = phi i32 [ %13, %12 ], [ %18, %17 ], [ %23, %22 ], [ 63, %25 ], [ 62, %24 ]
%28 = icmp sgt i32 %27, -1
%29 = icmp slt i32 %27, %1
%30 = and i1 %28, %29
%31 = select i1 %30, i32 %27, i32 -1
br label %32
32: ; preds = %26, %24
%33 = phi i32 [ -1, %24 ], [ %31, %26 ]
ret i32 %33
}