#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*/ print_err(char *, unsigned char, char const *);
int hex_digit(unsigned char c, const char *path) {
  if (c <= '9') {
    if (c >= '0')
      return c - '0';
  } else {
    unsigned char uc = c & ~32U;
    if (uc >= 'A' && uc <= 'F')
      return uc - 'A' + 10;
  }
  print_err("bad hex digit '%c' in \"%s\"", c, path);
  return -1;
}


x86 assembly (clang, -O0):
<hex_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0x39,%eax
jg     1150 <hex_digit+0x40>
movzbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jl     114b <hex_digit+0x3b>
movzbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <hex_digit+0x98>
jmp    118b <hex_digit+0x7b>
movzbl -0x5(%rbp),%eax
and    $0xffffffdf,%eax
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x41,%eax
jl     1186 <hex_digit+0x76>
movzbl -0x11(%rbp),%eax
cmp    $0x46,%eax
jg     1186 <hex_digit+0x76>
movzbl -0x11(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <hex_digit+0x98>
jmp    118b <hex_digit+0x7b>
mov    -0x5(%rbp),%al
mov    -0x10(%rbp),%rdx
lea    0xe67(%rip),%rdi
movzbl %al,%esi
call   1030 <print_err@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_digit>:
mov    %rsi,%rdx
mov    %edi,%eax
cmp    $0x39,%al
ja     1121 <hex_digit+0x11>
cmp    $0x30,%al
jb     112f <hex_digit+0x1f>
add    $0xffffffd0,%eax
ret
mov    %eax,%ecx
and    $0xdf,%cl
lea    -0x47(%rcx),%esi
cmp    $0xf9,%sil
ja     1149 <hex_digit+0x39>
push   %rax
movzbl %al,%esi
lea    0xec6(%rip),%rdi
call   1030 <print_err@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
ret
movzbl %cl,%eax
add    $0xffffffc9,%eax
ret

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

LLVM IR (-O2):
@.str = [27 x i8] c"bad hex digit '%c' in \22%s\22\00"
define i32 @hex_digit(i8 zeroext %0, i8* %1) {
%3 = zext i8 %0 to i32
%4 = icmp ult i8 %0, 58
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = icmp ugt i8 %0, 47
br i1 %6, label %7, label %15
7: ; preds = %5
%8 = add nsw i32 %3, -48
br label %17
9: ; preds = %2
%10 = and i8 %0, -33
%11 = add i8 %10, -71
%12 = icmp ult i8 %11, -6
%13 = zext i8 %10 to i32
%14 = add nsw i32 %13, -55
br i1 %12, label %15, label %17
15: ; preds = %9, %5
%16 = tail call i32 @print_err(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8 zeroext %0, i8* %1)
br label %17
17: ; preds = %9, %15, %7
%18 = phi i32 [ %8, %7 ], [ -1, %15 ], [ %14, %9 ]
ret i32 %18
}