#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*/ assert(char const **);
int _xte_utf8_read_hex_to_unicode(char const **io_hex) {
  assert(io_hex);
  if (!(*io_hex))
    return 0;
  const char *hex = *io_hex;
  int value = 0;
  while (*hex) {
    int half_value;
    switch (*hex) {
    case '0':
      half_value = 0;
      break;
    case '1':
      half_value = 1;
      break;
    case '2':
      half_value = 2;
      break;
    case '3':
      half_value = 3;
      break;
    case '4':
      half_value = 4;
      break;
    case '5':
      half_value = 5;
      break;
    case '6':
      half_value = 6;
      break;
    case '7':
      half_value = 7;
      break;
    case '8':
      half_value = 8;
      break;
    case '9':
      half_value = 9;
      break;
    case 'A':
    case 'a':
      half_value = 0xA;
      break;
    case 'B':
    case 'b':
      half_value = 0xB;
      break;
    case 'C':
    case 'c':
      half_value = 0xC;
      break;
    case 'D':
    case 'd':
      half_value = 0xD;
      break;
    case 'E':
    case 'e':
      half_value = 0xE;
      break;
    case 'F':
    case 'f':
      half_value = 0xF;
      break;
    default:
      *io_hex = hex;
      return value;
    }
    value <<= 4;
    value += half_value;
    hex++;
  }
  return value;
}


x86 assembly (clang, -O0):
<_xte_utf8_read_hex_to_unicode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    113f <_xte_utf8_read_hex_to_unicode+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    128a <_xte_utf8_read_hex_to_unicode+0x17a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1284 <_xte_utf8_read_hex_to_unicode+0x174>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x36,%eax
ja     124b <_xte_utf8_read_hex_to_unicode+0x13b>
mov    -0x28(%rbp),%rax
lea    0xe7e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0x1,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0x2,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0x3,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0x4,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0x5,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0x6,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0x7,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0x8,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0x9,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0xa,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0xb,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0xc,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0xd,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0xe,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
movl   $0xf,-0x20(%rbp)
jmp    1261 <_xte_utf8_read_hex_to_unicode+0x151>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128a <_xte_utf8_read_hex_to_unicode+0x17a>
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <_xte_utf8_read_hex_to_unicode+0x41>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_xte_utf8_read_hex_to_unicode>:
push   %rbx
mov    %rdi,%rbx
call   1030 <assert@plt>
mov    (%rbx),%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1166 <_xte_utf8_read_hex_to_unicode+0x56>
mov    (%rcx),%dl
test   %dl,%dl
je     1166 <_xte_utf8_read_hex_to_unicode+0x56>
xor    %eax,%eax
movabs $0x7e0000007e03ff,%rdi
lea    0xec4(%rip),%rsi
nopl   0x0(%rax)
movsbl %dl,%edx
add    $0xffffffd0,%edx
cmp    $0x37,%edx
jae    1168 <_xte_utf8_read_hex_to_unicode+0x58>
bt     %rdx,%rdi
jae    1168 <_xte_utf8_read_hex_to_unicode+0x58>
movslq %edx,%rdx
shl    $0x4,%eax
or     (%rsi,%rdx,4),%eax
movzbl 0x1(%rcx),%edx
add    $0x1,%rcx
test   %dl,%dl
jne    1140 <_xte_utf8_read_hex_to_unicode+0x30>
pop    %rbx
ret
mov    %rcx,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define i32 @_xte_utf8_read_hex_to_unicode(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %3
%7 = load i8**, i8*** %3
%8 = call i32 @assert(i8** %7)
%9 = load i8**, i8*** %3
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store i32 0, i32* %2
br label %54
13: ; preds = %1
%14 = load i8**, i8*** %3
%15 = load i8*, i8** %14
store i8* %15, i8** %4
store i32 0, i32* %5
br label %16
16: ; preds = %44, %13
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %52
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
switch i32 %23, label %40 [
i32 48, label %24
i32 49, label %25
i32 50, label %26
i32 51, label %27
i32 52, label %28
i32 53, label %29
i32 54, label %30
i32 55, label %31
i32 56, label %32
i32 57, label %33
i32 65, label %34
i32 97, label %34
i32 66, label %35
i32 98, label %35
i32 67, label %36
i32 99, label %36
i32 68, label %37
i32 100, label %37
i32 69, label %38
i32 101, label %38
i32 70, label %39
i32 102, label %39
]
24: ; preds = %20
store i32 0, i32* %6
br label %44
25: ; preds = %20
store i32 1, i32* %6
br label %44
26: ; preds = %20
store i32 2, i32* %6
br label %44
27: ; preds = %20
store i32 3, i32* %6
br label %44
28: ; preds = %20
store i32 4, i32* %6
br label %44
29: ; preds = %20
store i32 5, i32* %6
br label %44
30: ; preds = %20
store i32 6, i32* %6
br label %44
31: ; preds = %20
store i32 7, i32* %6
br label %44
32: ; preds = %20
store i32 8, i32* %6
br label %44
33: ; preds = %20
store i32 9, i32* %6
br label %44
34: ; preds = %20, %20
store i32 10, i32* %6
br label %44
35: ; preds = %20, %20
store i32 11, i32* %6
br label %44
36: ; preds = %20, %20
store i32 12, i32* %6
br label %44
37: ; preds = %20, %20
store i32 13, i32* %6
br label %44
38: ; preds = %20, %20
store i32 14, i32* %6
br label %44
39: ; preds = %20, %20
store i32 15, i32* %6
br label %44
40: ; preds = %20
%41 = load i8*, i8** %4
%42 = load i8**, i8*** %3
store i8* %41, i8** %42
%43 = load i32, i32* %5
store i32 %43, i32* %2
br label %54
44: ; preds = %39, %38, %37, %36, %35, %34, %33, %32, %31, %30, %29, %28, %27, %26, %25, %24
%45 = load i32, i32* %5
%46 = shl i32 %45, 4
store i32 %46, i32* %5
%47 = load i32, i32* %6
%48 = load i32, i32* %5
%49 = add nsw i32 %48, %47
store i32 %49, i32* %5
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %4
br label %16
52: ; preds = %16
%53 = load i32, i32* %5
store i32 %53, i32* %2
br label %54
54: ; preds = %52, %40, %12
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
@switch.table._xte_utf8_read_hex_to_unicode = [55 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15]
define i32 @_xte_utf8_read_hex_to_unicode(i8** %0) {
%2 = tail call i32 @assert(i8** %0)
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %30, label %5
5: ; preds = %1
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
br i1 %7, label %30, label %8
8: ; preds = %5, %21
%9 = phi i8 [ %28, %21 ], [ %6, %5 ]
%10 = phi i32 [ %26, %21 ], [ 0, %5 ]
%11 = phi i8* [ %27, %21 ], [ %3, %5 ]
%12 = sext i8 %9 to i32
%13 = add nsw i32 %12, -48
%14 = icmp ult i32 %13, 55
br i1 %14, label %16, label %15
15: ; preds = %16, %8
store i8* %11, i8** %0
br label %30
16: ; preds = %8
%17 = zext i32 %13 to i64
%18 = lshr i64 35465847073801215, %17
%19 = and i64 %18, 1
%20 = icmp eq i64 %19, 0
br i1 %20, label %15, label %21
21: ; preds = %16
%22 = sext i32 %13 to i64
%23 = getelementptr inbounds [55 x i32], [55 x i32]* @switch.table._xte_utf8_read_hex_to_unicode, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = shl i32 %10, 4
%26 = or i32 %24, %25
%27 = getelementptr inbounds i8, i8* %11, i64 1
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %8
30: ; preds = %21, %5, %15, %1
%31 = phi i32 [ 0, %1 ], [ %10, %15 ], [ 0, %5 ], [ %26, %21 ]
ret i32 %31
}