#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*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int h2c(char *c) {
  int x;
  if (!c)
    goto err;
  x = (int)*c;
  if (x >= 'A' && x <= 'F')
    *c = (char)(x - 'A' + 10);
  else if (x >= '0' && x <= '9')
    *c = (char)(x - '0');
  else
    goto err;
  return 0;
err:
  fputs("Invalid hex bytes\n", stderr);
  return -1;
}


x86 assembly (clang, -O0):
<h2c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    112c <h2c+0x1c>
jmp    119d <h2c+0x8d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x41,-0x14(%rbp)
jl     1160 <h2c+0x50>
cmpl   $0x46,-0x14(%rbp)
jg     1160 <h2c+0x50>
mov    -0x14(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    1191 <h2c+0x81>
cmpl   $0x30,-0x14(%rbp)
jl     1187 <h2c+0x77>
cmpl   $0x39,-0x14(%rbp)
jg     1187 <h2c+0x77>
mov    -0x14(%rbp),%eax
sub    $0x30,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    118c <h2c+0x7c>
jmp    119d <h2c+0x8d>
jmp    1191 <h2c+0x81>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <h2c+0xa9>
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    0xe53(%rip),%rdi
call   1030 <fputs@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<h2c>:
push   %rax
test   %rdi,%rdi
je     1130 <h2c+0x20>
mov    (%rdi),%al
lea    -0x41(%rax),%ecx
cmp    $0x5,%cl
ja     1124 <h2c+0x14>
add    $0xc9,%al
jmp    112a <h2c+0x1a>
add    $0xd0,%al
cmp    $0x9,%al
ja     1130 <h2c+0x20>
mov    %al,(%rdi)
xor    %eax,%eax
pop    %rcx
ret
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
lea    0xec0(%rip),%rdi
call   1030 <fputs@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [19 x i8] c"Invalid hex bytes\0A\00"
@stderr = global i32 0
define i32 @h2c(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = add i8 %4, -65
%6 = icmp ult i8 %5, 6
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = add nsw i8 %4, -55
br label %12
9: ; preds = %3
%10 = add i8 %4, -48
%11 = icmp ult i8 %10, 10
br i1 %11, label %12, label %14
12: ; preds = %9, %7
%13 = phi i8 [ %8, %7 ], [ %10, %9 ]
store i8 %13, i8* %0
br label %17
14: ; preds = %9, %1
%15 = load i32, i32* @stderr
%16 = tail call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %12
%18 = phi i32 [ 0, %12 ], [ -1, %14 ]
ret i32 %18
}