#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);
int /*<<< orphan*/ printf(char *, unsigned char, unsigned char);
unsigned char_to_uns4bit(unsigned char c) {
  unsigned v;
  if (c >= '0' && c <= '9') {
    v = c - '0';
  } else if (c >= 'a' && c <= 'f') {
    v = c - 'a' + 10;
  } else if (c >= 'A' && c <= 'F') {
    v = c - 'A' + 10;
  } else {
    printf("Garbage hex char in %c 0x%x\n", c, c);
    exit(1);
  }
  return v;
}


x86 assembly (clang, -O0):
<char_to_uns4bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0x30,%eax
jl     1157 <char_to_uns4bit+0x37>
movzbl -0x1(%rbp),%eax
cmp    $0x39,%eax
jg     1157 <char_to_uns4bit+0x37>
movzbl -0x1(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x8(%rbp)
jmp    11d9 <char_to_uns4bit+0xb9>
movzbl -0x1(%rbp),%eax
cmp    $0x61,%eax
jl     1183 <char_to_uns4bit+0x63>
movzbl -0x1(%rbp),%eax
cmp    $0x66,%eax
jg     1183 <char_to_uns4bit+0x63>
movzbl -0x1(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x8(%rbp)
jmp    11d4 <char_to_uns4bit+0xb4>
movzbl -0x1(%rbp),%eax
cmp    $0x41,%eax
jl     11af <char_to_uns4bit+0x8f>
movzbl -0x1(%rbp),%eax
cmp    $0x46,%eax
jg     11af <char_to_uns4bit+0x8f>
movzbl -0x1(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x8(%rbp)
jmp    11cf <char_to_uns4bit+0xaf>
mov    -0x1(%rbp),%al
lea    0xe47(%rip),%rdi
movzbl %al,%esi
movzbl -0x1(%rbp),%edx
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    11d4 <char_to_uns4bit+0xb4>
jmp    11d9 <char_to_uns4bit+0xb9>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_to_uns4bit>:
lea    -0x30(%rdi),%eax
mov    $0xffffffd0,%ecx
cmp    $0xa,%al
jb     1144 <char_to_uns4bit+0x24>
lea    -0x61(%rdi),%eax
mov    $0xffffffa9,%ecx
cmp    $0x6,%al
jb     1144 <char_to_uns4bit+0x24>
lea    -0x41(%rdi),%eax
mov    $0xffffffc9,%ecx
cmp    $0x6,%al
jae    114b <char_to_uns4bit+0x2b>
movzbl %dil,%eax
add    %ecx,%eax
ret
push   %rax
movzbl %dil,%edx
lea    0xea9(%rip),%rdi
mov    %edx,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Garbage hex char in %c 0x%x\0A\00"
define i32 @char_to_uns4bit(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
%4 = load i8, i8* %2
%5 = zext i8 %4 to i32
%6 = icmp sge i32 %5, 48
br i1 %6, label %7, label %15
7: ; preds = %1
%8 = load i8, i8* %2
%9 = zext i8 %8 to i32
%10 = icmp sle i32 %9, 57
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i8, i8* %2
%13 = zext i8 %12 to i32
%14 = sub nsw i32 %13, 48
store i32 %14, i32* %3
br label %48
15: ; preds = %7, %1
%16 = load i8, i8* %2
%17 = zext i8 %16 to i32
%18 = icmp sge i32 %17, 97
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i8, i8* %2
%21 = zext i8 %20 to i32
%22 = icmp sle i32 %21, 102
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i8, i8* %2
%25 = zext i8 %24 to i32
%26 = sub nsw i32 %25, 97
%27 = add nsw i32 %26, 10
store i32 %27, i32* %3
br label %47
28: ; preds = %19, %15
%29 = load i8, i8* %2
%30 = zext i8 %29 to i32
%31 = icmp sge i32 %30, 65
br i1 %31, label %32, label %41
32: ; preds = %28
%33 = load i8, i8* %2
%34 = zext i8 %33 to i32
%35 = icmp sle i32 %34, 70
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i8, i8* %2
%38 = zext i8 %37 to i32
%39 = sub nsw i32 %38, 65
%40 = add nsw i32 %39, 10
store i32 %40, i32* %3
br label %46
41: ; preds = %32, %28
%42 = load i8, i8* %2
%43 = load i8, i8* %2
%44 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8 zeroext %42, i8 zeroext %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %36
br label %47
47: ; preds = %46, %23
br label %48
48: ; preds = %47, %11
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [29 x i8] c"Garbage hex char in %c 0x%x\0A\00"
define i32 @char_to_uns4bit(i8 zeroext %0) {
%2 = add i8 %0, -48
%3 = icmp ult i8 %2, 10
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = add i8 %0, -97
%6 = icmp ult i8 %5, 6
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = add i8 %0, -65
%9 = icmp ult i8 %8, 6
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8 zeroext %0, i8 zeroext %0)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7, %4, %1
%14 = phi i32 [ -48, %1 ], [ -87, %4 ], [ -55, %7 ]
%15 = zext i8 %0 to i32
%16 = add nsw i32 %14, %15
ret i32 %16
}