#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*/ readLine(char);
void processChar(char c) {
  static int state = 0;
  if (state == 0) {
    if (c == 0x1B) {
      state = 1;
    } else {
      readLine(c);
    }
  } else if (state == 1) {
    if (c == 0x5B) {
      state = 2;
    } else {
      readLine(0x1B);
      state = 0;
    }
  } else {
    if (c == 0x41) {
      readLine(0x15);
    } else if (c == 0x42) {
      readLine(0x04);
    } else {
      readLine(0x1B);
      readLine(0x5B);
      readLine(c);
    }
    state = 0;
  }
}


x86 assembly (clang, -O0):
<processChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
cmpl   $0x0,0x2f07(%rip)
jne    1155 <processChar+0x45>
movsbl -0x1(%rbp),%eax
cmp    $0x1b,%eax
jne    1147 <processChar+0x37>
movl   $0x1,0x2eea(%rip)
jmp    1150 <processChar+0x40>
movsbl -0x1(%rbp),%edi
call   1030 <readLine@plt>
jmp    1200 <processChar+0xf0>
cmpl   $0x1,0x2ed0(%rip)
jne    1197 <processChar+0x87>
movsbl -0x1(%rbp),%eax
cmp    $0x5b,%eax
jne    117e <processChar+0x6e>
movl   $0x2,0x2eb3(%rip)
jmp    1192 <processChar+0x82>
mov    $0x1b,%edi
call   1030 <readLine@plt>
movl   $0x0,0x2e9a(%rip)
jmp    11fb <processChar+0xeb>
movsbl -0x1(%rbp),%eax
cmp    $0x41,%eax
jne    11b3 <processChar+0xa3>
mov    $0x15,%edi
call   1030 <readLine@plt>
jmp    11f1 <processChar+0xe1>
movsbl -0x1(%rbp),%eax
cmp    $0x42,%eax
jne    11cf <processChar+0xbf>
mov    $0x4,%edi
call   1030 <readLine@plt>
jmp    11ec <processChar+0xdc>
mov    $0x1b,%edi
call   1030 <readLine@plt>
mov    $0x5b,%edi
call   1030 <readLine@plt>
movsbl -0x1(%rbp),%edi
call   1030 <readLine@plt>
jmp    11f1 <processChar+0xe1>
movl   $0x0,0x2e31(%rip)
jmp    1200 <processChar+0xf0>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processChar>:
push   %rbx
mov    %edi,%ebx
mov    0x2f13(%rip),%eax
cmp    $0x1,%eax
je     1133 <processChar+0x23>
test   %eax,%eax
jne    1144 <processChar+0x34>
cmp    $0x1b,%bl
jne    1152 <processChar+0x42>
movl   $0x1,0x2efb(%rip)
pop    %rbx
ret
cmp    $0x5b,%bl
jne    115b <processChar+0x4b>
movl   $0x2,0x2eea(%rip)
pop    %rbx
ret
cmp    $0x41,%bl
je     1162 <processChar+0x52>
cmp    $0x42,%bl
jne    1166 <processChar+0x56>
mov    $0x4,%bl
jmp    117a <processChar+0x6a>
movsbl %bl,%edi
pop    %rbx
jmp    1030 <readLine@plt>
mov    $0x1b,%edi
jmp    117d <processChar+0x6d>
mov    $0x15,%bl
jmp    117a <processChar+0x6a>
mov    $0x1b,%edi
call   1030 <readLine@plt>
mov    $0x5b,%edi
call   1030 <readLine@plt>
movsbl %bl,%edi
call   1030 <readLine@plt>
movl   $0x0,0x2ea0(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@processChar.state = internal global i32 0
define void @processChar(i8 signext %0) {
%2 = alloca i8
store i8 %0, i8* %2
%3 = load i32, i32* @processChar.state
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %1
%6 = load i8, i8* %2
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 27
br i1 %8, label %9, label %10
9: ; preds = %5
store i32 1, i32* @processChar.state
br label %13
10: ; preds = %5
%11 = load i8, i8* %2
%12 = call i32 @readLine(i8 signext %11)
br label %13
13: ; preds = %10, %9
br label %45
14: ; preds = %1
%15 = load i32, i32* @processChar.state
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 91
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 2, i32* @processChar.state
br label %24
22: ; preds = %17
%23 = call i32 @readLine(i8 signext 27)
store i32 0, i32* @processChar.state
br label %24
24: ; preds = %22, %21
br label %44
25: ; preds = %14
%26 = load i8, i8* %2
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 65
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @readLine(i8 signext 21)
br label %43
31: ; preds = %25
%32 = load i8, i8* %2
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 66
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @readLine(i8 signext 4)
br label %42
37: ; preds = %31
%38 = call i32 @readLine(i8 signext 27)
%39 = call i32 @readLine(i8 signext 91)
%40 = load i8, i8* %2
%41 = call i32 @readLine(i8 signext %40)
br label %42
42: ; preds = %37, %35
br label %43
43: ; preds = %42, %29
store i32 0, i32* @processChar.state
br label %44
44: ; preds = %43, %24
br label %45
45: ; preds = %44, %13
ret void
}

LLVM IR (-O2):
@processChar.state = internal unnamed_addr global i32 0
define void @processChar(i8 signext %0) {
%2 = load i32, i32* @processChar.state
switch i32 %2, label %13 [
i32 0, label %3
i32 1, label %8
]
3: ; preds = %1
%4 = icmp eq i8 %0, 27
br i1 %4, label %5, label %6
5: ; preds = %3
store i32 1, i32* @processChar.state
br label %21
6: ; preds = %3
%7 = tail call i32 @readLine(i8 signext %0)
br label %21
8: ; preds = %1
%9 = icmp eq i8 %0, 91
br i1 %9, label %10, label %11
10: ; preds = %8
store i32 2, i32* @processChar.state
br label %21
11: ; preds = %8
%12 = tail call i32 @readLine(i8 signext 27)
store i32 0, i32* @processChar.state
br label %21
13: ; preds = %1
switch i8 %0, label %15 [
i8 65, label %18
i8 66, label %14
]
14: ; preds = %13
br label %18
15: ; preds = %13
%16 = tail call i32 @readLine(i8 signext 27)
%17 = tail call i32 @readLine(i8 signext 91)
br label %18
18: ; preds = %13, %14, %15
%19 = phi i8 [ 4, %14 ], [ %0, %15 ], [ 21, %13 ]
%20 = tail call i32 @readLine(i8 signext %19)
store i32 0, i32* @processChar.state
br label %21
21: ; preds = %18, %11, %10, %5, %6
ret void
}