#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 */
typedef char uint8_t;

/* Variables and functions */
char toupper(char);
uint8_t charactere_hex_to_int(char c) {
  if (c >= '0' && c <= '9')
    return c - '0';
  c = toupper(c);
  if (c >= 'A' && c <= 'F')
    return c - 'A' + 10;
  return 0;
}


x86 assembly (clang, -O0):
<charactere_hex_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
cmp    $0x30,%eax
jl     1147 <charactere_hex_to_int+0x37>
movsbl -0x2(%rbp),%eax
cmp    $0x39,%eax
jg     1147 <charactere_hex_to_int+0x37>
movsbl -0x2(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x1(%rbp)
jmp    1183 <charactere_hex_to_int+0x73>
movsbl -0x2(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
cmp    $0x41,%eax
jl     117f <charactere_hex_to_int+0x6f>
movsbl -0x2(%rbp),%eax
cmp    $0x46,%eax
jg     117f <charactere_hex_to_int+0x6f>
movsbl -0x2(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %al,-0x1(%rbp)
jmp    1183 <charactere_hex_to_int+0x73>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charactere_hex_to_int>:
lea    -0x30(%rdi),%eax
cmp    $0xa,%al
jb     1135 <charactere_hex_to_int+0x25>
push   %rax
movsbl %dil,%edi
call   1030 <toupper@plt>
lea    -0x41(%rax),%ecx
add    $0xc9,%al
xor    %edx,%edx
cmp    $0x6,%cl
movzbl %al,%eax
cmovae %edx,%eax
add    $0x8,%rsp
ret

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

LLVM IR (-O2):
define signext i8 @charactere_hex_to_int(i8 signext %0) {
%2 = add i8 %0, -48
%3 = icmp ult i8 %2, 10
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call signext i8 @toupper(i8 signext %0)
%6 = add i8 %5, -65
%7 = icmp ult i8 %6, 6
%8 = add i8 %5, -55
%9 = select i1 %7, i8 %8, i8 0
br label %10
10: ; preds = %1, %4
%11 = phi i8 [ %9, %4 ], [ %2, %1 ]
ret i8 %11
}