#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 */
char tolower(char);
int hexchar_to_int(char c) {
  c = tolower(c);
  if (c >= 'a' && c <= 'f') {
    return c - 'a' + 10;
  } else if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}


x86 assembly (clang, -O0):
<hexchar_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <tolower@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jl     1156 <hexchar_to_int+0x46>
movsbl -0x5(%rbp),%eax
cmp    $0x66,%eax
jg     1156 <hexchar_to_int+0x46>
movsbl -0x5(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    118b <hexchar_to_int+0x7b>
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jl     117f <hexchar_to_int+0x6f>
movsbl -0x5(%rbp),%eax
cmp    $0x39,%eax
jg     117f <hexchar_to_int+0x6f>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    118b <hexchar_to_int+0x7b>
jmp    1184 <hexchar_to_int+0x74>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexchar_to_int>:
push   %rax
call   1030 <tolower@plt>
movsbl %al,%eax
lea    -0x61(%rax),%ecx
cmp    $0x5,%cl
ja     1126 <hexchar_to_int+0x16>
add    $0xffffffa9,%eax
pop    %rcx
ret
lea    -0x30(%rax),%ecx
add    $0xffffffd0,%eax
xor    %edx,%edx
cmp    $0xa,%cl
cmovb  %eax,%edx
mov    %edx,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
define i32 @hexchar_to_int(i8 signext %0) {
%2 = tail call signext i8 @tolower(i8 signext %0)
%3 = sext i8 %2 to i32
%4 = add i8 %2, -97
%5 = icmp ult i8 %4, 6
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = add nsw i32 %3, -87
br label %13
8: ; preds = %1
%9 = add i8 %2, -48
%10 = icmp ult i8 %9, 10
%11 = add nsw i32 %3, -48
%12 = select i1 %10, i32 %11, i32 0
br label %13
13: ; preds = %8, %6
%14 = phi i32 [ %7, %6 ], [ %12, %8 ]
ret i32 %14
}