#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 ctou8(char input) {
  unsigned char output = 0;
  if ((input >= 48) && (input <= 57))
    output = input - 48;
  else if ((input >= 65) && (input <= 70))
    output = input - 55;
  else if ((input >= 97) && (input <= 102))
    output = input - 87;
  else {
    printf("input out of range!\n");
    output = -1;
  }
  return output;
}


x86 assembly (clang, -O0):
<ctou8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movb   $0x0,-0x2(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x30,%eax
jl     114b <ctou8+0x3b>
movsbl -0x1(%rbp),%eax
cmp    $0x39,%eax
jg     114b <ctou8+0x3b>
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x2(%rbp)
jmp    11b7 <ctou8+0xa7>
movsbl -0x1(%rbp),%eax
cmp    $0x41,%eax
jl     1174 <ctou8+0x64>
movsbl -0x1(%rbp),%eax
cmp    $0x46,%eax
jg     1174 <ctou8+0x64>
movsbl -0x1(%rbp),%eax
sub    $0x37,%eax
mov    %al,-0x2(%rbp)
jmp    11b2 <ctou8+0xa2>
movsbl -0x1(%rbp),%eax
cmp    $0x61,%eax
jl     119d <ctou8+0x8d>
movsbl -0x1(%rbp),%eax
cmp    $0x66,%eax
jg     119d <ctou8+0x8d>
movsbl -0x1(%rbp),%eax
sub    $0x57,%eax
mov    %al,-0x2(%rbp)
jmp    11ad <ctou8+0x9d>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
movb   $0xff,-0x2(%rbp)
jmp    11b2 <ctou8+0xa2>
jmp    11b7 <ctou8+0xa7>
movzbl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ctou8>:
lea    -0x30(%rdi),%eax
cmp    $0xa,%al
jb     1146 <ctou8+0x36>
lea    -0x41(%rdi),%eax
cmp    $0x5,%al
ja     1125 <ctou8+0x15>
add    $0xc9,%dil
mov    %edi,%eax
ret
lea    -0x61(%rdi),%eax
cmp    $0x5,%al
ja     1133 <ctou8+0x23>
add    $0xa9,%dil
mov    %edi,%eax
ret
push   %rax
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
mov    $0xff,%al
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"input out of range!\0A\00"
define zeroext i8 @ctou8(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8
store i8 %0, i8* %2
store i8 0, i8* %3
%4 = load i8, i8* %2
%5 = sext i8 %4 to i32
%6 = icmp sge i32 %5, 48
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 %46
16: ; preds = %7, %1
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = icmp sge i32 %18, 65
br i1 %19, label %20, label %29
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 %29
24: ; preds = %20
%25 = load i8, i8* %2
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 55
%28 = trunc i32 %27 to i8
store i8 %28, i8* %3
br label %45
29: ; preds = %20, %16
%30 = load i8, i8* %2
%31 = sext i8 %30 to i32
%32 = icmp sge i32 %31, 97
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = load i8, i8* %2
%35 = sext i8 %34 to i32
%36 = icmp sle i32 %35, 102
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i8, i8* %2
%39 = sext i8 %38 to i32
%40 = sub nsw i32 %39, 87
%41 = trunc i32 %40 to i8
store i8 %41, i8* %3
br label %44
42: ; preds = %33, %29
%43 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i8 -1, i8* %3
br label %44
44: ; preds = %42, %37
br label %45
45: ; preds = %44, %24
br label %46
46: ; preds = %45, %11
%47 = load i8, i8* %3
ret i8 %47
}

LLVM IR (-O2):
@str = [20 x i8] c"input out of range!\00"
define zeroext i8 @ctou8(i8 signext %0) {
%2 = add i8 %0, -48
%3 = icmp ult i8 %2, 10
br i1 %3, label %16, 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 %16
9: ; preds = %4
%10 = add i8 %0, -97
%11 = icmp ult i8 %10, 6
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = add nsw i8 %0, -87
br label %16
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %1, %7, %14, %12
%17 = phi i8 [ %8, %7 ], [ %13, %12 ], [ -1, %14 ], [ %2, %1 ]
ret i8 %17
}