int read_universal_char(int len) {
  unsigned int r = 0;
  for (int i = 0; i < len; i++) {
    char 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:
      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",
          354, "invalid universal character: %c", c);
    }
  }
  if (!is_valid_ucn(r))
    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",
           358, "invalid universal character: \\%c%0*x", (len == 4) ? 'u' : 'U',
           len, r);
  return r;
}


x86 assembly (clang, -O0):
<read_universal_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    121b <read_universal_char+0xeb>
xor    %eax,%eax
call   1040 <get@plt>
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
mov    %eax,-0x14(%rbp)
add    $0xffffffd0,%eax
sub    $0xa,%eax
jb     119f <read_universal_char+0x6f>
jmp    1177 <read_universal_char+0x47>
mov    -0x14(%rbp),%eax
add    $0xffffffbf,%eax
sub    $0x6,%eax
jb     11d0 <read_universal_char+0xa0>
jmp    118b <read_universal_char+0x5b>
mov    -0x14(%rbp),%eax
add    $0xffffff9f,%eax
sub    $0x6,%eax
jb     11b6 <read_universal_char+0x86>
jmp    11ea <read_universal_char+0xba>
mov    -0x8(%rbp),%eax
shl    $0x4,%eax
movsbl -0xd(%rbp),%ecx
sub    $0x30,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    120d <read_universal_char+0xdd>
mov    -0x8(%rbp),%eax
shl    $0x4,%eax
movsbl -0xd(%rbp),%ecx
sub    $0x61,%ecx
add    $0xa,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    120d <read_universal_char+0xdd>
mov    -0x8(%rbp),%eax
shl    $0x4,%eax
movsbl -0xd(%rbp),%ecx
sub    $0x41,%ecx
add    $0xa,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    120d <read_universal_char+0xdd>
movsbl -0xd(%rbp),%ecx
lea    0xe0b(%rip),%rdi
mov    $0x162,%esi
lea    0xe81(%rip),%rdx
mov    $0x0,%al
call   1030 <errorf@plt>
jmp    120d <read_universal_char+0xdd>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1149 <read_universal_char+0x19>
mov    -0x8(%rbp),%edi
mov    $0x0,%al
call   1050 <is_valid_ucn@plt>
cmp    $0x0,%eax
jne    1263 <read_universal_char+0x133>
mov    -0x4(%rbp),%edx
mov    $0x55,%ecx
mov    $0x75,%eax
cmp    $0x4,%edx
cmove  %eax,%ecx
mov    -0x4(%rbp),%r8d
mov    -0x8(%rbp),%r9d
lea    0xdb0(%rip),%rdi
mov    $0x166,%esi
lea    0xe46(%rip),%rdx
mov    $0x0,%al
call   1030 <errorf@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_universal_char>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
test   %edi,%edi
jle    11d8 <read_universal_char+0xa8>
mov    $0x3ff,%ebx
mov    $0x7e0000,%r13d
movabs $0x7e000000000000,%r14
mov    %r15d,%r12d
xor    %ebp,%ebp
jmp    117d <read_universal_char+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
shl    $0x4,%ebp
or     %ebp,%eax
mov    %eax,%ebp
add    $0xffffffff,%r12d
je     11da <read_universal_char+0xaa>
xor    %eax,%eax
call   1040 <get@plt>
movsbl %al,%ecx
lea    -0x30(%rcx),%eax
cmp    $0x36,%eax
ja     11bc <read_universal_char+0x8c>
bt     %rax,%rbx
jb     1170 <read_universal_char+0x40>
bt     %rax,%r13
jb     11b0 <read_universal_char+0x80>
bt     %rax,%r14
jae    11bc <read_universal_char+0x8c>
shl    $0x4,%ebp
add    $0xffffffa9,%ecx
jmp    11b6 <read_universal_char+0x86>
nopl   0x0(%rax)
shl    $0x4,%ebp
add    $0xffffffc9,%ecx
or     %ebp,%ecx
mov    %ecx,%ebp
jmp    1177 <read_universal_char+0x47>
lea    0xe3d(%rip),%rdi
mov    $0x162,%esi
lea    0xeb3(%rip),%rdx
xor    %eax,%eax
call   1030 <errorf@plt>
jmp    1177 <read_universal_char+0x47>
xor    %ebp,%ebp
mov    %ebp,%edi
xor    %eax,%eax
call   1050 <is_valid_ucn@plt>
test   %eax,%eax
jne    1216 <read_universal_char+0xe6>
xor    %ecx,%ecx
cmp    $0x4,%r15d
sete   %cl
shl    $0x5,%ecx
or     $0x55,%ecx
lea    0xe03(%rip),%rdi
lea    0xe9e(%rip),%rdx
mov    $0x166,%esi
mov    %r15d,%r8d
mov    %ebp,%r9d
xor    %eax,%eax
call   1030 <errorf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 = [32 x i8] c"invalid universal character: %c\00"
@.str.2 = [37 x i8] c"invalid universal character: \\%c%0*x\00"
define i32 @read_universal_char(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %43, %1
%7 = load i32, i32* %4
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %46
10: ; preds = %6
%11 = call i32 (...) @get()
%12 = trunc i32 %11 to i8
store i8 %12, i8* %5
%13 = load i8, i8* %5
%14 = sext i8 %13 to i32
switch i32 %14, label %38 [
i32 48, label %15
i32 49, label %15
i32 50, label %15
i32 51, label %15
i32 52, label %15
i32 53, label %15
i32 54, label %15
i32 55, label %15
i32 56, label %15
i32 57, label %15
i32 97, label %22
i32 98, label %22
i32 99, label %22
i32 100, label %22
i32 101, label %22
i32 102, label %22
i32 65, label %30
i32 66, label %30
i32 67, label %30
i32 68, label %30
i32 69, label %30
i32 70, label %30
]
15: ; preds = %10, %10, %10, %10, %10, %10, %10, %10, %10, %10
%16 = load i32, i32* %3
%17 = shl i32 %16, 4
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
%20 = sub nsw i32 %19, 48
%21 = or i32 %17, %20
store i32 %21, i32* %3
br label %43
22: ; preds = %10, %10, %10, %10, %10, %10
%23 = load i32, i32* %3
%24 = shl i32 %23, 4
%25 = load i8, i8* %5
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 97
%28 = add nsw i32 %27, 10
%29 = or i32 %24, %28
store i32 %29, i32* %3
br label %43
30: ; preds = %10, %10, %10, %10, %10, %10
%31 = load i32, i32* %3
%32 = shl i32 %31, 4
%33 = load i8, i8* %5
%34 = sext i8 %33 to i32
%35 = sub nsw i32 %34, 65
%36 = add nsw i32 %35, 10
%37 = or i32 %32, %36
store i32 %37, i32* %3
br label %43
38: ; preds = %10
%39 = load i8, i8* %5
%40 = sext i8 %39 to i32
%41 = 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 354, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %38
br label %43
43: ; preds = %42, %30, %22, %15
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
br label %6
46: ; preds = %6
%47 = load i32, i32* %3
%48 = call i32 (i32, ...) bitcast (i32 (...)* @is_valid_ucn to i32 (i32, ...)*)(i32 %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %58, label %50
50: ; preds = %46
%51 = load i32, i32* %2
%52 = icmp eq i32 %51, 4
%53 = zext i1 %52 to i64
%54 = select i1 %52, i32 117, i32 85
%55 = load i32, i32* %2
%56 = load i32, i32* %3
%57 = call i32 (i8*, i32, i8*, i32, i32, i32, ...) bitcast (i32 (...)* @errorf to i32 (i8*, i32, i8*, i32, i32, i32, ...)*)(i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str, i64 0, i64 0), i32 358, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %54, i32 %55, i32 %56)
br label %58
58: ; preds = %50, %46
%59 = load i32, i32* %3
ret i32 %59
}

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 = [32 x i8] c"invalid universal character: %c\00"
@.str.2 = [37 x i8] c"invalid universal character: \\%c%0*x\00"
define i32 @read_universal_char(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %7, label %3
3: ; preds = %27, %1
%4 = phi i32 [ 0, %1 ], [ %28, %27 ]
%5 = tail call i32 (i32, ...) bitcast (i32 (...)* @is_valid_ucn to i32 (i32, ...)*)(i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %31, label %35
7: ; preds = %1, %27
%8 = phi i32 [ %28, %27 ], [ 0, %1 ]
%9 = phi i32 [ %29, %27 ], [ 0, %1 ]
%10 = tail call i32 (...) @get()
%11 = shl i32 %10, 24
%12 = ashr exact i32 %11, 24
switch i32 %12, label %25 [
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 %17
i32 98, label %17
i32 99, label %17
i32 100, label %17
i32 101, label %17
i32 102, label %17
i32 65, label %21
i32 66, label %21
i32 67, label %21
i32 68, label %21
i32 69, label %21
i32 70, label %21
]
13: ; preds = %7, %7, %7, %7, %7, %7, %7, %7, %7, %7
%14 = shl i32 %8, 4
%15 = add nsw i32 %12, -48
%16 = or i32 %15, %14
br label %27
17: ; preds = %7, %7, %7, %7, %7, %7
%18 = shl i32 %8, 4
%19 = add nsw i32 %12, -87
%20 = or i32 %19, %18
br label %27
21: ; preds = %7, %7, %7, %7, %7, %7
%22 = shl i32 %8, 4
%23 = add nsw i32 %12, -55
%24 = or i32 %23, %22
br label %27
25: ; preds = %7
%26 = 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 354, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %27
27: ; preds = %25, %21, %17, %13
%28 = phi i32 [ %8, %25 ], [ %24, %21 ], [ %20, %17 ], [ %16, %13 ]
%29 = add nuw nsw i32 %9, 1
%30 = icmp eq i32 %29, %0
br i1 %30, label %3, label %7
31: ; preds = %3
%32 = icmp eq i32 %0, 4
%33 = select i1 %32, i32 117, i32 85
%34 = tail call i32 (i8*, i32, i8*, i32, i32, i32, ...) bitcast (i32 (...)* @errorf to i32 (i8*, i32, i8*, i32, i32, i32, ...)*)(i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str, i64 0, i64 0), i32 358, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %0, i32 %4)
br label %35
35: ; preds = %31, %3
ret i32 %4
}