#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 scalar_t__ uint8_t;

/* Variables and functions */
char hexchar_to_nibble(char hexchar, uint8_t *nibble) {
  if ((hexchar >= '0') && (hexchar <= '9')) {
    *nibble = (uint8_t)(hexchar - '0');
    return 0;
  } else if ((hexchar >= 'A') && (hexchar <= 'F')) {
    *nibble = (uint8_t)(hexchar - 'A' + 10);
    return 0;
  } else if ((hexchar >= 'a') && (hexchar <= 'f')) {
    *nibble = (uint8_t)(hexchar - 'a' + 10);
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<hexchar_to_nibble>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
movsbl -0x2(%rbp),%eax
cmp    $0x30,%eax
jl     1142 <hexchar_to_nibble+0x42>
movsbl -0x2(%rbp),%eax
cmp    $0x39,%eax
jg     1142 <hexchar_to_nibble+0x42>
movsbl -0x2(%rbp),%eax
sub    $0x30,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movb   $0x0,-0x1(%rbp)
jmp    11be <hexchar_to_nibble+0xbe>
movsbl -0x2(%rbp),%eax
cmp    $0x41,%eax
jl     1179 <hexchar_to_nibble+0x79>
movsbl -0x2(%rbp),%eax
cmp    $0x46,%eax
jg     1179 <hexchar_to_nibble+0x79>
movsbl -0x2(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movb   $0x0,-0x1(%rbp)
jmp    11be <hexchar_to_nibble+0xbe>
movsbl -0x2(%rbp),%eax
cmp    $0x61,%eax
jl     11b0 <hexchar_to_nibble+0xb0>
movsbl -0x2(%rbp),%eax
cmp    $0x66,%eax
jg     11b0 <hexchar_to_nibble+0xb0>
movsbl -0x2(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movb   $0x0,-0x1(%rbp)
jmp    11be <hexchar_to_nibble+0xbe>
jmp    11b5 <hexchar_to_nibble+0xb5>
jmp    11ba <hexchar_to_nibble+0xba>
movb   $0xff,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexchar_to_nibble>:
mov    $0xffffffa9,%ecx
lea    -0x30(%rdi),%eax
cmp    $0xa,%al
jae    1112 <hexchar_to_nibble+0x12>
add    $0x27,%rcx
jmp    1129 <hexchar_to_nibble+0x29>
lea    -0x41(%rdi),%eax
cmp    $0x6,%al
jae    111f <hexchar_to_nibble+0x1f>
add    $0x20,%rcx
jmp    1129 <hexchar_to_nibble+0x29>
lea    -0x61(%rdi),%edx
mov    $0xff,%al
cmp    $0x5,%dl
ja     1130 <hexchar_to_nibble+0x30>
add    %edi,%ecx
mov    %rcx,(%rsi)
xor    %eax,%eax
ret

LLVM IR (-O0):
define signext i8 @hexchar_to_nibble(i8 signext %0, i64* %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i64*
store i8 %0, i8* %4
store i64* %1, i64** %5
%6 = load i8, i8* %4
%7 = sext i8 %6 to i32
%8 = icmp sge i32 %7, 48
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = load i8, i8* %4
%11 = sext i8 %10 to i32
%12 = icmp sle i32 %11, 57
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i8, i8* %4
%15 = sext i8 %14 to i32
%16 = sub nsw i32 %15, 48
%17 = sext i32 %16 to i64
%18 = load i64*, i64** %5
store i64 %17, i64* %18
store i8 0, i8* %3
br label %52
19: ; preds = %9, %2
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp sge i32 %21, 65
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = load i8, i8* %4
%25 = sext i8 %24 to i32
%26 = icmp sle i32 %25, 70
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = sub nsw i32 %29, 65
%31 = add nsw i32 %30, 10
%32 = sext i32 %31 to i64
%33 = load i64*, i64** %5
store i64 %32, i64* %33
store i8 0, i8* %3
br label %52
34: ; preds = %23, %19
%35 = load i8, i8* %4
%36 = sext i8 %35 to i32
%37 = icmp sge i32 %36, 97
br i1 %37, label %38, label %49
38: ; preds = %34
%39 = load i8, i8* %4
%40 = sext i8 %39 to i32
%41 = icmp sle i32 %40, 102
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = load i8, i8* %4
%44 = sext i8 %43 to i32
%45 = sub nsw i32 %44, 97
%46 = add nsw i32 %45, 10
%47 = sext i32 %46 to i64
%48 = load i64*, i64** %5
store i64 %47, i64* %48
store i8 0, i8* %3
br label %52
49: ; preds = %38, %34
br label %50
50: ; preds = %49
br label %51
51: ; preds = %50
store i8 -1, i8* %3
br label %52
52: ; preds = %51, %42, %27, %13
%53 = load i8, i8* %3
ret i8 %53
}

LLVM IR (-O2):
define signext i8 @hexchar_to_nibble(i8 signext %0, i64* nocapture writeonly %1) {
%3 = sext i8 %0 to i64
%4 = add i8 %0, -48
%5 = icmp ult i8 %4, 10
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = add i8 %0, -65
%8 = icmp ult i8 %7, 6
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = add i8 %0, -97
%11 = icmp ult i8 %10, 6
br i1 %11, label %12, label %16
12: ; preds = %9, %6, %2
%13 = phi i64 [ 4294967248, %2 ], [ 4294967241, %6 ], [ 4294967209, %9 ]
%14 = add nsw i64 %13, %3
%15 = and i64 %14, 4294967295
store i64 %15, i64* %1
br label %16
16: ; preds = %12, %9
%17 = phi i8 [ -1, %9 ], [ 0, %12 ]
ret i8 %17
}