#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(char);
char toupper(char);
int FormatDataCharToDigitValue(char chr) {
  int ret = -1;
  if (isdigit(chr))
    ret = chr - '0';
  else {
    chr = toupper(chr);
    if (chr >= 'A' && chr <= 'Z')
      ret = 10 + chr - 'A';
  }
  return ret;
}


x86 assembly (clang, -O0):
<FormatDataCharToDigitValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1157 <FormatDataCharToDigitValue+0x37>
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x8(%rbp)
jmp    118f <FormatDataCharToDigitValue+0x6f>
movsbl -0x1(%rbp),%edi
call   1040 <toupper@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x41,%eax
jl     118a <FormatDataCharToDigitValue+0x6a>
movsbl -0x1(%rbp),%eax
cmp    $0x5a,%eax
jg     118a <FormatDataCharToDigitValue+0x6a>
movsbl -0x1(%rbp),%eax
add    $0xa,%eax
sub    $0x41,%eax
mov    %eax,-0x8(%rbp)
jmp    118f <FormatDataCharToDigitValue+0x6f>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FormatDataCharToDigitValue>:
push   %rbx
mov    %edi,%ebx
call   1030 <isdigit@plt>
test   %rax,%rax
je     1135 <FormatDataCharToDigitValue+0x15>
movsbl %bl,%eax
add    $0xffffffd0,%eax
pop    %rbx
ret
movsbl %bl,%edi
call   1040 <toupper@plt>
mov    %eax,%ecx
lea    -0x41(%rcx),%edx
mov    $0xffffffff,%eax
cmp    $0x19,%dl
ja     1152 <FormatDataCharToDigitValue+0x32>
movzbl %cl,%eax
add    $0xffffffc9,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @FormatDataCharToDigitValue(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
store i32 -1, i32* %3
%4 = load i8, i8* %2
%5 = call i64 @isdigit(i8 signext %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = sub nsw i32 %9, 48
store i32 %10, i32* %3
br label %27
11: ; preds = %1
%12 = load i8, i8* %2
%13 = call signext i8 @toupper(i8 signext %12)
store i8 %13, i8* %2
%14 = load i8, i8* %2
%15 = sext i8 %14 to i32
%16 = icmp sge i32 %15, 65
br i1 %16, label %17, label %26
17: ; preds = %11
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
%20 = icmp sle i32 %19, 90
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i8, i8* %2
%23 = sext i8 %22 to i32
%24 = add nsw i32 10, %23
%25 = sub nsw i32 %24, 65
store i32 %25, i32* %3
br label %26
26: ; preds = %21, %17, %11
br label %27
27: ; preds = %26, %7
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @FormatDataCharToDigitValue(i8 signext %0) {
%2 = tail call i64 @isdigit(i8 signext %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = sext i8 %0 to i32
%6 = add nsw i32 %5, -48
br label %14
7: ; preds = %1
%8 = tail call signext i8 @toupper(i8 signext %0)
%9 = add i8 %8, -65
%10 = icmp ult i8 %9, 26
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = zext i8 %8 to i32
%13 = add nsw i32 %12, -55
br label %14
14: ; preds = %7, %11, %4
%15 = phi i32 [ %6, %4 ], [ %13, %11 ], [ -1, %7 ]
ret i32 %15
}