#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*/ printf(char *, unsigned char);
int get_nybble(unsigned char *s) {
  int value;
  if (*s >= '0' && *s <= '9') {
    value = *s - '0';
  } else if (*s >= 'a' && *s <= 'f') {
    value = *s - 'a' + 10;
  } else if (*s >= 'A' && *s <= 'F') {
    value = *s - 'A' + 10;
  } else {
    printf("Invalid hex character: %c\n", *s);
    value = 0;
  }
  return value;
}


x86 assembly (clang, -O0):
<get_nybble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x30,%eax
jl     114e <get_nybble+0x3e>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x39,%eax
jg     114e <get_nybble+0x3e>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
jmp    11dc <get_nybble+0xcc>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x61,%eax
jl     1183 <get_nybble+0x73>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x66,%eax
jg     1183 <get_nybble+0x73>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0xc(%rbp)
jmp    11d7 <get_nybble+0xc7>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x41,%eax
jl     11b8 <get_nybble+0xa8>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x46,%eax
jg     11b8 <get_nybble+0xa8>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0xc(%rbp)
jmp    11d2 <get_nybble+0xc2>
mov    -0x8(%rbp),%rax
lea    0xe3d(%rip),%rdi
movzbl (%rax),%esi
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    11d7 <get_nybble+0xc7>
jmp    11dc <get_nybble+0xcc>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_nybble>:
push   %rax
movzbl (%rdi),%eax
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
ja     1121 <get_nybble+0x11>
add    $0xffffffd0,%eax
pop    %rcx
ret
lea    -0x61(%rax),%ecx
cmp    $0x5,%cl
ja     112e <get_nybble+0x1e>
add    $0xffffffa9,%eax
pop    %rcx
ret
lea    -0x41(%rax),%ecx
cmp    $0x5,%cl
ja     113b <get_nybble+0x2b>
add    $0xffffffc9,%eax
pop    %rcx
ret
lea    0xebe(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Invalid hex character: %c\0A\00"
define i32 @get_nybble(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i8, i8* %4
%6 = zext i8 %5 to i32
%7 = icmp sge i32 %6, 48
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = icmp sle i32 %11, 57
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = sub nsw i32 %16, 48
store i32 %17, i32* %3
br label %56
18: ; preds = %8, %1
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = icmp sge i32 %21, 97
br i1 %22, label %23, label %34
23: ; preds = %18
%24 = load i8*, i8** %2
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = icmp sle i32 %26, 102
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = load i8*, i8** %2
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = sub nsw i32 %31, 97
%33 = add nsw i32 %32, 10
store i32 %33, i32* %3
br label %55
34: ; preds = %23, %18
%35 = load i8*, i8** %2
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = icmp sge i32 %37, 65
br i1 %38, label %39, label %50
39: ; preds = %34
%40 = load i8*, i8** %2
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = icmp sle i32 %42, 70
br i1 %43, label %44, label %50
44: ; preds = %39
%45 = load i8*, i8** %2
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = sub nsw i32 %47, 65
%49 = add nsw i32 %48, 10
store i32 %49, i32* %3
br label %54
50: ; preds = %39, %34
%51 = load i8*, i8** %2
%52 = load i8, i8* %51
%53 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8 zeroext %52)
store i32 0, i32* %3
br label %54
54: ; preds = %50, %44
br label %55
55: ; preds = %54, %28
br label %56
56: ; preds = %55, %13
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [27 x i8] c"Invalid hex character: %c\0A\00"
define i32 @get_nybble(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = zext i8 %2 to i32
%4 = add i8 %2, -48
%5 = icmp ult i8 %4, 10
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = add nsw i32 %3, -48
br label %20
8: ; preds = %1
%9 = add i8 %2, -97
%10 = icmp ult i8 %9, 6
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = add nsw i32 %3, -87
br label %20
13: ; preds = %8
%14 = add i8 %2, -65
%15 = icmp ult i8 %14, 6
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = add nsw i32 %3, -55
br label %20
18: ; preds = %13
%19 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8 zeroext %2)
br label %20
20: ; preds = %11, %18, %16, %6
%21 = phi i32 [ %7, %6 ], [ %12, %11 ], [ %17, %16 ], [ 0, %18 ]
ret i32 %21
}