#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 */
void hex_char_value(uint8_t c, uint8_t *value, bool *valid) {
  if ('0' <= c && c <= '9') {
    *value = c - '0';
    *valid = true;
  } else if ('a' <= c && c <= 'f') {
    *value = 10 + c - 'a';
    *valid = true;
  } else {
    *valid = false;
  }
}


x86 assembly (clang, -O0):
<hex_char_value>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsbl -0x1(%rbp),%ecx
mov    $0x30,%eax
cmp    %ecx,%eax
jg     114e <hex_char_value+0x4e>
movsbl -0x1(%rbp),%eax
cmp    $0x39,%eax
jg     114e <hex_char_value+0x4e>
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    119c <hex_char_value+0x9c>
movsbl -0x1(%rbp),%ecx
mov    $0x61,%eax
cmp    %ecx,%eax
jg     118d <hex_char_value+0x8d>
movsbl -0x1(%rbp),%eax
cmp    $0x66,%eax
jg     118d <hex_char_value+0x8d>
movsbl -0x1(%rbp),%eax
add    $0xa,%eax
sub    $0x61,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1197 <hex_char_value+0x97>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    119c <hex_char_value+0x9c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_char_value>:
lea    -0x30(%rdi),%eax
cmp    $0xa,%al
jb     1117 <hex_char_value+0x17>
lea    -0x61(%rdi),%ecx
xor    %eax,%eax
cmp    $0x5,%cl
ja     111e <hex_char_value+0x1e>
add    $0xa9,%dil
mov    %edi,%eax
mov    %al,(%rsi)
mov    $0x1,%eax
mov    %eax,(%rdx)
ret

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

LLVM IR (-O2):
define void @hex_char_value(i8 signext %0, i8* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = add i8 %0, -48
%5 = icmp ult i8 %4, 10
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = add i8 %0, -97
%8 = icmp ult i8 %7, 6
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = add nsw i8 %0, -87
br label %11
11: ; preds = %3, %9
%12 = phi i8 [ %10, %9 ], [ %4, %3 ]
store i8 %12, i8* %1
br label %13
13: ; preds = %11, %6
%14 = phi i32 [ 0, %6 ], [ 1, %11 ]
store i32 %14, i32* %2
ret void
}