#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);
scalar_t__ isupper(char);
int /*<<< orphan*/ isxdigit(char);
int Hex2Dec(char C) {
  if (!isxdigit(C))
    return (0);
  if (isdigit(C))
    return (C - '0');
  if (isupper(C))
    return (C - 'A' + 10);
  return (C - 'a' + 10);
}


x86 assembly (clang, -O0):
<Hex2Dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%eax
jne    115c <Hex2Dec+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <Hex2Dec+0x80>
movsbl -0x5(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     117e <Hex2Dec+0x4e>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11b0 <Hex2Dec+0x80>
movsbl -0x5(%rbp),%edi
call   1040 <isupper@plt>
cmp    $0x0,%rax
je     11a3 <Hex2Dec+0x73>
movsbl -0x5(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11b0 <Hex2Dec+0x80>
movsbl -0x5(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Hex2Dec>:
push   %rbx
mov    %edi,%ebx
call   1050 <isxdigit@plt>
test   %eax,%eax
je     1150 <Hex2Dec+0x20>
movsbl %bl,%ebx
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1154 <Hex2Dec+0x24>
add    $0xffffffd0,%ebx
jmp    1168 <Hex2Dec+0x38>
xor    %ebx,%ebx
jmp    1168 <Hex2Dec+0x38>
mov    %ebx,%edi
call   1040 <isupper@plt>
test   %rax,%rax
je     1165 <Hex2Dec+0x35>
add    $0xffffffc9,%ebx
jmp    1168 <Hex2Dec+0x38>
add    $0xffffffa9,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @Hex2Dec(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = call i32 @isxdigit(i8 signext %4)
%6 = icmp ne i32 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %1
store i32 0, i32* %2
br label %30
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 %30
16: ; preds = %8
%17 = load i8, i8* %3
%18 = call i64 @isupper(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = sub nsw i32 %22, 65
%24 = add nsw i32 %23, 10
store i32 %24, i32* %2
br label %30
25: ; preds = %16
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = sub nsw i32 %27, 97
%29 = add nsw i32 %28, 10
store i32 %29, i32* %2
br label %30
30: ; preds = %25, %20, %12, %7
%31 = load i32, i32* %2
ret i32 %31
}

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