#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 */
int /*<<< orphan*/ isalnum(char);
scalar_t__ isdigit(char);
int xtov(char s) {
  if (!isalnum(s))
    return -1;
  if (isdigit(s))
    return s - '0';
  if (s >= 'a' && s <= 'f')
    return 10 + (s - 'a');
  if (s >= 'A' && s <= 'F')
    return 10 + (s - 'A');
  return -1;
}


x86 assembly (clang, -O0):
<xtov>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    114c <xtov+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cd <xtov+0xad>
movsbl -0x5(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     116e <xtov+0x4e>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11cd <xtov+0xad>
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jl     119a <xtov+0x7a>
movsbl -0x5(%rbp),%eax
cmp    $0x66,%eax
jg     119a <xtov+0x7a>
movsbl -0x5(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11cd <xtov+0xad>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
jl     11c6 <xtov+0xa6>
movsbl -0x5(%rbp),%eax
cmp    $0x46,%eax
jg     11c6 <xtov+0xa6>
movsbl -0x5(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11cd <xtov+0xad>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xtov>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
call   1040 <isalnum@plt>
test   %eax,%eax
je     1145 <xtov+0x25>
movsbl %r14b,%ebx
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     114c <xtov+0x2c>
add    $0xffffffd0,%ebx
jmp    116c <xtov+0x4c>
mov    $0xffffffff,%ebx
jmp    116c <xtov+0x4c>
lea    -0x61(%r14),%eax
cmp    $0x5,%al
ja     1159 <xtov+0x39>
add    $0xffffffa9,%ebx
jmp    116c <xtov+0x4c>
add    $0xbf,%r14b
add    $0xffffffc9,%ebx
cmp    $0x6,%r14b
mov    $0xffffffff,%eax
cmovae %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @xtov(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = call i32 @isalnum(i8 signext %4)
%6 = icmp ne i32 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %1
store i32 -1, i32* %2
br label %43
8: ; preds = %1
%9 = load i8, i8* %3
%10 = call i64 @isdigit(i8 signext %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = sub nsw i32 %14, 48
store i32 %15, i32* %2
br label %43
16: ; preds = %8
%17 = load i8, i8* %3
%18 = sext i8 %17 to i32
%19 = icmp sge i32 %18, 97
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = icmp sle i32 %22, 102
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i8, i8* %3
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 97
%28 = add nsw i32 10, %27
store i32 %28, i32* %2
br label %43
29: ; preds = %20, %16
%30 = load i8, i8* %3
%31 = sext i8 %30 to i32
%32 = icmp sge i32 %31, 65
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = load i8, i8* %3
%35 = sext i8 %34 to i32
%36 = icmp sle i32 %35, 70
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i8, i8* %3
%39 = sext i8 %38 to i32
%40 = sub nsw i32 %39, 65
%41 = add nsw i32 10, %40
store i32 %41, i32* %2
br label %43
42: ; preds = %33, %29
store i32 -1, i32* %2
br label %43
43: ; preds = %42, %37, %24, %12, %7
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
define i32 @xtov(i8 signext %0) {
%2 = tail call i32 @isalnum(i8 signext %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = tail call i64 @isdigit(i8 signext %0)
%6 = icmp eq i64 %5, 0
%7 = sext i8 %0 to i32
br i1 %6, label %10, label %8
8: ; preds = %4
%9 = add nsw i32 %7, -48
br label %20
10: ; preds = %4
%11 = add i8 %0, -97
%12 = icmp ult i8 %11, 6
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = add nsw i32 %7, -87
br label %20
15: ; preds = %10
%16 = add i8 %0, -65
%17 = icmp ult i8 %16, 6
%18 = add nsw i32 %7, -55
%19 = select i1 %17, i32 %18, i32 -1
br label %20
20: ; preds = %15, %1, %13, %8
%21 = phi i32 [ %9, %8 ], [ %14, %13 ], [ -1, %1 ], [ %19, %15 ]
ret i32 %21
}