#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 */
scalar_t__ isdigit(char);
int char_to_nibble(char p_char, unsigned int *r_nibble) {
  if (isdigit(p_char))
    *r_nibble = p_char - '0';
  else if (p_char >= 'a' && p_char <= 'f')
    *r_nibble = (p_char - 'a') + 10;
  else if (p_char >= 'A' && p_char <= 'F')
    *r_nibble = (p_char - 'A') + 10;
  else
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<char_to_nibble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1147 <char_to_nibble+0x37>
movsbl -0x5(%rbp),%ecx
sub    $0x30,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    11bb <char_to_nibble+0xab>
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jl     1176 <char_to_nibble+0x66>
movsbl -0x5(%rbp),%eax
cmp    $0x66,%eax
jg     1176 <char_to_nibble+0x66>
movsbl -0x5(%rbp),%ecx
sub    $0x61,%ecx
add    $0xa,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    11b6 <char_to_nibble+0xa6>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
jl     11a5 <char_to_nibble+0x95>
movsbl -0x5(%rbp),%eax
cmp    $0x46,%eax
jg     11a5 <char_to_nibble+0x95>
movsbl -0x5(%rbp),%ecx
sub    $0x41,%ecx
add    $0xa,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    11b1 <char_to_nibble+0xa1>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <char_to_nibble+0xb2>
jmp    11b6 <char_to_nibble+0xa6>
jmp    11bb <char_to_nibble+0xab>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_to_nibble>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
call   1030 <isdigit@plt>
mov    $0xffffffd0,%ecx
test   %rax,%rax
jne    1143 <char_to_nibble+0x33>
lea    -0x61(%rbx),%eax
mov    $0xffffffa9,%ecx
cmp    $0x6,%al
jb     1143 <char_to_nibble+0x33>
lea    -0x41(%rbx),%edx
xor    %eax,%eax
mov    $0xffffffc9,%ecx
cmp    $0x5,%dl
ja     114d <char_to_nibble+0x3d>
add    %ebx,%ecx
mov    %ecx,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @char_to_nibble(i8 signext %0, i32* nocapture writeonly %1) {
%3 = tail call i64 @isdigit(i8 signext %0)
%4 = icmp eq i64 %3, 0
%5 = sext i8 %0 to i32
br i1 %4, label %6, label %12
6: ; preds = %2
%7 = add i8 %0, -97
%8 = icmp ult i8 %7, 6
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = add i8 %0, -65
%11 = icmp ult i8 %10, 6
br i1 %11, label %12, label %15
12: ; preds = %9, %6, %2
%13 = phi i32 [ -48, %2 ], [ -87, %6 ], [ -55, %9 ]
%14 = add nsw i32 %13, %5
store i32 %14, i32* %1
br label %15
15: ; preds = %12, %9
%16 = phi i32 [ 0, %9 ], [ 1, %12 ]
ret i32 %16
}