int read_hex_char(void) {
  int c = get();
  int r = 0;
  if (!isxdigit(c))
    errorf("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/zhuzhaoyuan/8cc/refs/heads/master/lex.c",
           329, "\\x is not followed by a hexadecimal character: %c", c);
  for (;; c = get()) {
    switch (c) {
    case '0' ... '9':
      r = (r << 4) | (c - '0');
      continue;
    case 'a' ... 'f':
      r = (r << 4) | (c - 'a' + 10);
      continue;
    case 'A' ... 'F':
      r = (r << 4) | (c - 'A' + 10);
      continue;
    default:
      unget(c);
      return r;
    }
  }
}


x86 assembly (clang, -O0):
<read_hex_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <get@plt>
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <isxdigit@plt>
cmp    $0x0,%eax
jne    1187 <read_hex_char+0x47>
mov    -0x4(%rbp),%ecx
lea    0xe8c(%rip),%rdi
mov    $0x149,%esi
lea    0xf02(%rip),%rdx
mov    $0x0,%al
call   1030 <errorf@plt>
jmp    118c <read_hex_char+0x4c>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
add    $0xffffffd0,%eax
sub    $0xa,%eax
jb     11cb <read_hex_char+0x8b>
jmp    11a3 <read_hex_char+0x63>
mov    -0xc(%rbp),%eax
add    $0xffffffbf,%eax
sub    $0x6,%eax
jb     11fa <read_hex_char+0xba>
jmp    11b7 <read_hex_char+0x77>
mov    -0xc(%rbp),%eax
add    $0xffffff9f,%eax
sub    $0x6,%eax
jb     11e1 <read_hex_char+0xa1>
jmp    1213 <read_hex_char+0xd3>
mov    -0x8(%rbp),%eax
shl    $0x4,%eax
mov    -0x4(%rbp),%ecx
sub    $0x30,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    1226 <read_hex_char+0xe6>
mov    -0x8(%rbp),%eax
shl    $0x4,%eax
mov    -0x4(%rbp),%ecx
sub    $0x61,%ecx
add    $0xa,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    1226 <read_hex_char+0xe6>
mov    -0x8(%rbp),%eax
shl    $0x4,%eax
mov    -0x4(%rbp),%ecx
sub    $0x41,%ecx
add    $0xa,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    1226 <read_hex_char+0xe6>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1040 <unget@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret
mov    $0x0,%al
call   1050 <get@plt>
mov    %eax,-0x4(%rbp)
jmp    118c <read_hex_char+0x4c>

x86 assembly (clang, -O2):
<read_hex_char>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <get@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <isxdigit@plt>
test   %eax,%eax
jne    1177 <read_hex_char+0x37>
lea    0xe9e(%rip),%rdi
lea    0xf19(%rip),%rdx
mov    $0x149,%esi
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <errorf@plt>
movabs $0x7e0000007e03ff,%r14
lea    0xf2c(%rip),%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    -0x30(%rbx),%eax
cmp    $0x37,%eax
jae    11b4 <read_hex_char+0x74>
bt     %rax,%r14
jae    11b4 <read_hex_char+0x74>
cltq
shl    $0x4,%ebp
add    (%r15,%rax,4),%ebx
or     %ebx,%ebp
xor    %eax,%eax
call   1050 <get@plt>
mov    %eax,%ebx
jmp    1190 <read_hex_char+0x50>
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <unget@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [130 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zhuzhaoyuan/8cc/refs/heads/master/lex.c\00"
@.str.1 = [50 x i8] c"\\x is not followed by a hexadecimal character: %c\00"
define i32 @read_hex_char() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @get()
store i32 %3, i32* %1
store i32 0, i32* %2
%4 = load i32, i32* %1
%5 = call i32 @isxdigit(i32 %4)
%6 = icmp ne i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = load i32, i32* %1
%9 = call i32 (i8*, i32, i8*, i32, ...) bitcast (i32 (...)* @errorf to i32 (i8*, i32, i8*, i32, ...)*)(i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str, i64 0, i64 0), i32 329, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %7, %0
br label %11
11: ; preds = %37, %10
%12 = load i32, i32* %1
switch i32 %12, label %33 [
i32 48, label %13
i32 49, label %13
i32 50, label %13
i32 51, label %13
i32 52, label %13
i32 53, label %13
i32 54, label %13
i32 55, label %13
i32 56, label %13
i32 57, label %13
i32 97, label %19
i32 98, label %19
i32 99, label %19
i32 100, label %19
i32 101, label %19
i32 102, label %19
i32 65, label %26
i32 66, label %26
i32 67, label %26
i32 68, label %26
i32 69, label %26
i32 70, label %26
]
13: ; preds = %11, %11, %11, %11, %11, %11, %11, %11, %11, %11
%14 = load i32, i32* %2
%15 = shl i32 %14, 4
%16 = load i32, i32* %1
%17 = sub nsw i32 %16, 48
%18 = or i32 %15, %17
store i32 %18, i32* %2
br label %37
19: ; preds = %11, %11, %11, %11, %11, %11
%20 = load i32, i32* %2
%21 = shl i32 %20, 4
%22 = load i32, i32* %1
%23 = sub nsw i32 %22, 97
%24 = add nsw i32 %23, 10
%25 = or i32 %21, %24
store i32 %25, i32* %2
br label %37
26: ; preds = %11, %11, %11, %11, %11, %11
%27 = load i32, i32* %2
%28 = shl i32 %27, 4
%29 = load i32, i32* %1
%30 = sub nsw i32 %29, 65
%31 = add nsw i32 %30, 10
%32 = or i32 %28, %31
store i32 %32, i32* %2
br label %37
33: ; preds = %11
%34 = load i32, i32* %1
%35 = call i32 (i32, ...) bitcast (i32 (...)* @unget to i32 (i32, ...)*)(i32 %34)
%36 = load i32, i32* %2
ret i32 %36
37: ; preds = %26, %19, %13
%38 = call i32 (...) @get()
store i32 %38, i32* %1
br label %11
}

LLVM IR (-O2):
@.str = [130 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zhuzhaoyuan/8cc/refs/heads/master/lex.c\00"
@.str.1 = [50 x i8] c"\\x is not followed by a hexadecimal character: %c\00"
@switch.table.read_hex_char = [55 x i32] [i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -55, i32 -55, i32 -55, i32 -55, i32 -55, i32 -55, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -48, i32 -87, i32 -87, i32 -87, i32 -87, i32 -87, i32 -87]
define i32 @read_hex_char() {
%1 = tail call i32 (...) @get()
%2 = tail call i32 @isxdigit(i32 %1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 (i8*, i32, i8*, i32, ...) bitcast (i32 (...)* @errorf to i32 (i8*, i32, i8*, i32, ...)*)(i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str, i64 0, i64 0), i32 329, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %6
6: ; preds = %4, %0
br label %7
7: ; preds = %6, %19
%8 = phi i32 [ %26, %19 ], [ %1, %6 ]
%9 = phi i32 [ %25, %19 ], [ 0, %6 ]
%10 = add i32 %8, -48
%11 = icmp ult i32 %10, 55
br i1 %11, label %14, label %12
12: ; preds = %14, %7
%13 = tail call i32 (i32, ...) bitcast (i32 (...)* @unget to i32 (i32, ...)*)(i32 %8)
ret i32 %9
14: ; preds = %7
%15 = zext i32 %10 to i64
%16 = lshr i64 35465847073801215, %15
%17 = and i64 %16, 1
%18 = icmp eq i64 %17, 0
br i1 %18, label %12, label %19
19: ; preds = %14
%20 = sext i32 %10 to i64
%21 = getelementptr inbounds [55 x i32], [55 x i32]* @switch.table.read_hex_char, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = shl i32 %9, 4
%24 = add nsw i32 %8, %22
%25 = or i32 %23, %24
%26 = tail call i32 (...) @get()
br label %7
}