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


x86 assembly (clang, -O0):
<ir_hex_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jl     1147 <ir_hex_to_int+0x37>
movzbl -0x5(%rbp),%eax
cmp    $0x39,%eax
jg     1147 <ir_hex_to_int+0x37>
movzbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    1186 <ir_hex_to_int+0x76>
movzbl -0x5(%rbp),%edi
call   1030 <tolower@plt>
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jl     117f <ir_hex_to_int+0x6f>
movzbl -0x5(%rbp),%eax
cmp    $0x66,%eax
jg     117f <ir_hex_to_int+0x6f>
movzbl -0x5(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    1186 <ir_hex_to_int+0x76>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ir_hex_to_int>:
lea    -0x30(%rdi),%eax
cmp    $0x9,%al
ja     111f <ir_hex_to_int+0xf>
movzbl %dil,%eax
add    $0xffffffd0,%eax
ret
push   %rax
movzbl %dil,%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
lea    -0x61(%rcx),%edx
xor    %eax,%eax
cmp    $0x5,%dl
lea    0x8(%rsp),%rsp
ja     1140 <ir_hex_to_int+0x30>
movzbl %cl,%eax
add    $0xffffffa9,%eax
ret

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

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