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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
uint8_t get_nibble(char c) {
  uint8_t nibble;
  if (('0' <= c) && (c <= '9'))
    nibble = c - '0';
  else if (('A' <= c) && (c <= 'F'))
    nibble = 10 + (c - 'A');
  else
    assert(0);
  return nibble;
}


x86 assembly (clang, -O0):
<get_nibble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%ecx
mov    $0x30,%eax
cmp    %ecx,%eax
jg     114b <get_nibble+0x3b>
movsbl -0x1(%rbp),%eax
cmp    $0x39,%eax
jg     114b <get_nibble+0x3b>
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x2(%rbp)
jmp    1187 <get_nibble+0x77>
movsbl -0x1(%rbp),%ecx
mov    $0x41,%eax
cmp    %ecx,%eax
jg     117b <get_nibble+0x6b>
movsbl -0x1(%rbp),%eax
cmp    $0x46,%eax
jg     117b <get_nibble+0x6b>
movsbl -0x1(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %al,-0x2(%rbp)
jmp    1182 <get_nibble+0x72>
xor    %edi,%edi
call   1030 <assert@plt>
jmp    1187 <get_nibble+0x77>
movsbl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_nibble>:
lea    -0x30(%rdi),%eax
cmp    $0xa,%al
jb     1131 <get_nibble+0x21>
lea    -0x41(%rdi),%eax
cmp    $0x5,%al
ja     1125 <get_nibble+0x15>
add    $0xc9,%dil
mov    %edi,%eax
ret
push   %rax
xor    %edi,%edi
call   1030 <assert@plt>
add    $0x8,%rsp
ret

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

LLVM IR (-O2):
define signext i8 @get_nibble(i8 signext %0) {
%2 = add i8 %0, -48
%3 = icmp ult i8 %2, 10
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = add i8 %0, -65
%6 = icmp ult i8 %5, 6
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = add nsw i8 %0, -55
br label %11
9: ; preds = %4
%10 = tail call i32 @assert(i32 0)
br label %11
11: ; preds = %1, %7, %9
%12 = phi i8 [ %8, %7 ], [ undef, %9 ], [ %2, %1 ]
ret i8 %12
}