#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 */
typedef int int32_t;

/* Variables and functions */
int getchar();
int32_t getchar_ex(void) {
  int32_t c, ret = 0;
  for (int i = 0; i < 4; i++) {
    if ((c = getchar()) == -1)
      return -1;
    ret = (ret << 8) | c;
    switch (i) {
    case 0:
      if (c != 0x1B)
        return ret;
      break;
    case 1:
      if (c != 0x5B && c != 0x4F)
        return ret;
      break;
    case 2:
    case 3:
      if (c >= 0x40 && c <= 0x7e)
        return ret;
      break;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<getchar_ex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    120a <getchar_ex+0xfa>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    114f <getchar_ex+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1210 <getchar_ex+0x100>
mov    -0xc(%rbp),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     1195 <getchar_ex+0x85>
jmp    1170 <getchar_ex+0x60>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     11af <getchar_ex+0x9f>
jmp    1181 <getchar_ex+0x71>
mov    -0x14(%rbp),%eax
add    $0xfffffffe,%eax
sub    $0x2,%eax
jb     11d3 <getchar_ex+0xc3>
jmp    11f7 <getchar_ex+0xe7>
cmpl   $0x1b,-0x8(%rbp)
je     11aa <getchar_ex+0x9a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1210 <getchar_ex+0x100>
jmp    11f7 <getchar_ex+0xe7>
cmpl   $0x5b,-0x8(%rbp)
je     11ce <getchar_ex+0xbe>
cmpl   $0x4f,-0x8(%rbp)
je     11ce <getchar_ex+0xbe>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1210 <getchar_ex+0x100>
jmp    11f7 <getchar_ex+0xe7>
cmpl   $0x40,-0x8(%rbp)
jl     11f2 <getchar_ex+0xe2>
cmpl   $0x7e,-0x8(%rbp)
jg     11f2 <getchar_ex+0xe2>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1210 <getchar_ex+0x100>
jmp    11f7 <getchar_ex+0xe7>
jmp    11fc <getchar_ex+0xec>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <getchar_ex+0x16>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getchar_ex>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %eax,%ebp
cmp    $0x1b,%eax
jne    1173 <getchar_ex+0x63>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     1173 <getchar_ex+0x63>
shl    $0x8,%ebx
or     %eax,%ebx
cmp    $0x5b,%eax
je     1143 <getchar_ex+0x33>
cmp    $0x4f,%eax
jne    115c <getchar_ex+0x4c>
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xffffffff,%eax
je     1173 <getchar_ex+0x63>
shl    $0x8,%ebx
or     %eax,%ebx
add    $0xffffffc0,%eax
cmp    $0x3f,%eax
jae    1160 <getchar_ex+0x50>
mov    %ebx,%ebp
jmp    1173 <getchar_ex+0x63>
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xffffffff,%eax
je     1173 <getchar_ex+0x63>
shl    $0x8,%ebx
or     %ebx,%eax
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getchar_ex() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %43, %0
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 4
br i1 %7, label %8, label %46
8: ; preds = %5
%9 = call i32 (...) @getchar()
store i32 %9, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %8
store i32 -1, i32* %1
br label %48
12: ; preds = %8
%13 = load i32, i32* %3
%14 = shl i32 %13, 8
%15 = load i32, i32* %2
%16 = or i32 %14, %15
store i32 %16, i32* %3
%17 = load i32, i32* %4
switch i32 %17, label %42 [
i32 0, label %18
i32 1, label %24
i32 2, label %33
i32 3, label %33
]
18: ; preds = %12
%19 = load i32, i32* %2
%20 = icmp ne i32 %19, 27
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = load i32, i32* %3
store i32 %22, i32* %1
br label %48
23: ; preds = %18
br label %42
24: ; preds = %12
%25 = load i32, i32* %2
%26 = icmp ne i32 %25, 91
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32, i32* %2
%29 = icmp ne i32 %28, 79
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = load i32, i32* %3
store i32 %31, i32* %1
br label %48
32: ; preds = %27, %24
br label %42
33: ; preds = %12, %12
%34 = load i32, i32* %2
%35 = icmp sge i32 %34, 64
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i32, i32* %2
%38 = icmp sle i32 %37, 126
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = load i32, i32* %3
store i32 %40, i32* %1
br label %48
41: ; preds = %36, %33
br label %42
42: ; preds = %12, %41, %32, %23
br label %43
43: ; preds = %42
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
br label %5
46: ; preds = %5
%47 = load i32, i32* %3
store i32 %47, i32* %1
br label %48
48: ; preds = %46, %39, %30, %21, %11
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
define i32 @getchar_ex() {
%1 = tail call i32 (...) @getchar()
%2 = icmp eq i32 %1, 27
br i1 %2, label %3, label %23
3: ; preds = %0
%4 = tail call i32 (...) @getchar()
%5 = icmp eq i32 %4, -1
br i1 %5, label %23, label %6
6: ; preds = %3
%7 = shl nuw nsw i32 %1, 8
%8 = or i32 %4, %7
switch i32 %4, label %23 [
i32 91, label %9
i32 79, label %9
]
9: ; preds = %6, %6
%10 = tail call i32 (...) @getchar()
%11 = icmp eq i32 %10, -1
br i1 %11, label %23, label %12
12: ; preds = %9
%13 = shl i32 %8, 8
%14 = or i32 %10, %13
%15 = add i32 %10, -64
%16 = icmp ult i32 %15, 63
br i1 %16, label %23, label %17
17: ; preds = %12
%18 = tail call i32 (...) @getchar()
%19 = icmp eq i32 %18, -1
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = shl i32 %14, 8
%22 = or i32 %18, %21
br label %23
23: ; preds = %0, %20, %17, %12, %9, %6, %3
%24 = phi i32 [ -1, %3 ], [ %8, %6 ], [ -1, %9 ], [ %14, %12 ], [ -1, %17 ], [ %22, %20 ], [ %1, %0 ]
ret i32 %24
}