#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 */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int hexchar2int(int xdigit) {
  if (xdigit >= 'A' && xdigit <= 'F')
    return xdigit - 'A' + 10;
  if (xdigit >= 'a' && xdigit <= 'f')
    return xdigit - 'a' + 10;
  assert(xdigit >= '0' && xdigit <= '9' && "invalid digit character");
  return xdigit - '0';
}


x86 assembly (clang, -O0):
<hexchar2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x41,-0x8(%rbp)
jl     1140 <hexchar2int+0x30>
cmpl   $0x46,-0x8(%rbp)
jg     1140 <hexchar2int+0x30>
mov    -0x8(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11a3 <hexchar2int+0x93>
cmpl   $0x61,-0x8(%rbp)
jl     1165 <hexchar2int+0x55>
cmpl   $0x66,-0x8(%rbp)
jg     1165 <hexchar2int+0x55>
mov    -0x8(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11a3 <hexchar2int+0x93>
xor    %eax,%eax
cmpl   $0x30,-0x8(%rbp)
mov    %al,-0x9(%rbp)
jl     118d <hexchar2int+0x7d>
xor    %eax,%eax
cmpl   $0x39,-0x8(%rbp)
mov    %al,-0x9(%rbp)
jg     118d <hexchar2int+0x7d>
mov    $0x1,%al
mov    %al,-0x9(%rbp)
jmp    118d <hexchar2int+0x7d>
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexchar2int>:
push   %rbx
mov    %edi,%ebx
lea    -0x41(%rbx),%eax
cmp    $0x5,%eax
ja     1120 <hexchar2int+0x10>
add    $0xffffffc9,%ebx
jmp    113e <hexchar2int+0x2e>
lea    -0x61(%rbx),%eax
cmp    $0x5,%eax
ja     112d <hexchar2int+0x1d>
add    $0xffffffa9,%ebx
jmp    113e <hexchar2int+0x2e>
add    $0xffffffd0,%ebx
xor    %edi,%edi
cmp    $0xa,%ebx
setb   %dil
call   1030 <assert@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"invalid digit character\00"
define i32 @hexchar2int(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sge i32 %4, 65
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 70
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sub nsw i32 %10, 65
%12 = add nsw i32 %11, 10
store i32 %12, i32* %2
br label %36
13: ; preds = %6, %1
%14 = load i32, i32* %3
%15 = icmp sge i32 %14, 97
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i32, i32* %3
%18 = icmp sle i32 %17, 102
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 97
%22 = add nsw i32 %21, 10
store i32 %22, i32* %2
br label %36
23: ; preds = %16, %13
%24 = load i32, i32* %3
%25 = icmp sge i32 %24, 48
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i32, i32* %3
%28 = icmp sle i32 %27, 57
br i1 %28, label %29, label %30
29: ; preds = %26
br label %30
30: ; preds = %29, %26, %23
%31 = phi i1 [ false, %26 ], [ false, %23 ], [ true, %29 ]
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i32, i32* %3
%35 = sub nsw i32 %34, 48
store i32 %35, i32* %2
br label %36
36: ; preds = %30, %19, %9
%37 = load i32, i32* %2
ret i32 %37
}

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