#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*/ exit(int);
scalar_t__ isdigit(int);
int /*<<< orphan*/ printf(char *);
int tolower(char);
int get_string_value(char str) {
  int c;
  int val;
  if (!(c = tolower(str))) {
    printf("Invalid hex value conversion MSB\n");
    exit(1);
  }
  if (isdigit(c)) {
    val = c - '0';
  } else if (c >= 'a' && c <= 'f') {
    val = c - 'a' + 10;
  } else {
    printf("Invalid hex value out of reach MSB\n");
    exit(1);
  }
  return (val);
}


x86 assembly (clang, -O0):
<get_string_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%edi
call   1050 <tolower@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    1179 <get_string_value+0x39>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1199 <get_string_value+0x59>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
jmp    11d9 <get_string_value+0x99>
cmpl   $0x61,-0x8(%rbp)
jl     11be <get_string_value+0x7e>
cmpl   $0x66,-0x8(%rbp)
jg     11be <get_string_value+0x7e>
mov    -0x8(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0xc(%rbp)
jmp    11d4 <get_string_value+0x94>
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11d9 <get_string_value+0x99>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_string_value>:
push   %rbx
call   1050 <tolower@plt>
test   %eax,%eax
je     1170 <get_string_value+0x30>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <isdigit@plt>
mov    $0xffffffd0,%ecx
test   %rax,%rax
jne    116a <get_string_value+0x2a>
lea    -0x61(%rbx),%eax
mov    $0xffffffa9,%ecx
cmp    $0x6,%eax
jae    1179 <get_string_value+0x39>
add    %ecx,%ebx
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe89(%rip),%rdi
jmp    1180 <get_string_value+0x40>
lea    0xea1(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"Invalid hex value conversion MSB\0A\00"
@.str.1 = [36 x i8] c"Invalid hex value out of reach MSB\0A\00"
define i32 @get_string_value(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
store i8 %0, i8* %2
%5 = load i8, i8* %2
%6 = call i32 @tolower(i8 signext %5)
store i32 %6, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call i64 @isdigit(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %3
%17 = sub nsw i32 %16, 48
store i32 %17, i32* %4
br label %32
18: ; preds = %11
%19 = load i32, i32* %3
%20 = icmp sge i32 %19, 97
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %3
%23 = icmp sle i32 %22, 102
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* %3
%26 = sub nsw i32 %25, 97
%27 = add nsw i32 %26, 10
store i32 %27, i32* %4
br label %31
28: ; preds = %21, %18
%29 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %24
br label %32
32: ; preds = %31, %15
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@str = [33 x i8] c"Invalid hex value conversion MSB\00"
@str.2 = [35 x i8] c"Invalid hex value out of reach MSB\00"
define i32 @get_string_value(i8 signext %0) {
%2 = tail call i32 @tolower(i8 signext %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = tail call i64 @isdigit(i32 %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = add i32 %2, -97
%12 = icmp ult i32 %11, 6
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %10, %7
%17 = phi i32 [ -48, %7 ], [ -87, %10 ]
%18 = add nsw i32 %2, %17
ret i32 %18
}