#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*/ doselect();
int /*<<< orphan*/ movedown();
int /*<<< orphan*/ moveleft();
int /*<<< orphan*/ moveright();
int /*<<< orphan*/ moveup();
int /*<<< orphan*/ my_strcmp(char *, char *);
char check_char(char *str) {
  if (str) {
    if (!(my_strcmp(str, "\n\0")))
      return 2;
    else if (!(my_strcmp(str, "\E")))
      return 1;
    else if (!(my_strcmp(str, "\E[A")))
      moveup();
    else if (!(my_strcmp(str, "\E[B")))
      movedown();
    else if (!(my_strcmp(str, "\E[D")))
      moveleft();
    else if (!(my_strcmp(str, "\E[C")))
      moveright();
    else if (!(my_strcmp(str, " \0")))
      doselect();
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<check_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1296 <check_char+0x136>
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1030 <my_strcmp@plt>
cmp    $0x0,%eax
jne    1199 <check_char+0x39>
movb   $0x2,-0x1(%rbp)
jmp    129a <check_char+0x13a>
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1030 <my_strcmp@plt>
cmp    $0x0,%eax
jne    11bb <check_char+0x5b>
movb   $0x1,-0x1(%rbp)
jmp    129a <check_char+0x13a>
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1030 <my_strcmp@plt>
cmp    $0x0,%eax
jne    11e0 <check_char+0x80>
mov    $0x0,%al
call   1040 <moveup@plt>
jmp    1283 <check_char+0x123>
mov    -0x10(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1030 <my_strcmp@plt>
cmp    $0x0,%eax
jne    1205 <check_char+0xa5>
mov    $0x0,%al
call   1060 <movedown@plt>
jmp    127e <check_char+0x11e>
mov    -0x10(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1030 <my_strcmp@plt>
cmp    $0x0,%eax
jne    122a <check_char+0xca>
mov    $0x0,%al
call   1080 <moveleft@plt>
jmp    1279 <check_char+0x119>
mov    -0x10(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   1030 <my_strcmp@plt>
cmp    $0x0,%eax
jne    124f <check_char+0xef>
mov    $0x0,%al
call   1050 <moveright@plt>
jmp    1274 <check_char+0x114>
mov    -0x10(%rbp),%rdi
lea    0xda9(%rip),%rsi
call   1030 <my_strcmp@plt>
cmp    $0x0,%eax
jne    126f <check_char+0x10f>
mov    $0x0,%al
call   1070 <doselect@plt>
jmp    1274 <check_char+0x114>
jmp    1279 <check_char+0x119>
jmp    127e <check_char+0x11e>
jmp    1283 <check_char+0x123>
jmp    1288 <check_char+0x128>
jmp    128d <check_char+0x12d>
movb   $0x0,-0x1(%rbp)
jmp    129a <check_char+0x13a>
movb   $0xff,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_char>:
push   %rbx
test   %rdi,%rdi
je     11fe <check_char+0x9e>
mov    %rdi,%rbx
lea    0xe8c(%rip),%rsi
call   1030 <my_strcmp@plt>
test   %eax,%eax
je     1202 <check_char+0xa2>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <my_strcmp@plt>
test   %eax,%eax
je     1206 <check_char+0xa6>
lea    0xe6d(%rip),%rsi
mov    %rbx,%rdi
call   1030 <my_strcmp@plt>
test   %eax,%eax
je     120a <check_char+0xaa>
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <my_strcmp@plt>
test   %eax,%eax
je     1215 <check_char+0xb5>
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   1030 <my_strcmp@plt>
test   %eax,%eax
je     1220 <check_char+0xc0>
lea    0xe40(%rip),%rsi
mov    %rbx,%rdi
call   1030 <my_strcmp@plt>
test   %eax,%eax
je     122b <check_char+0xcb>
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
call   1030 <my_strcmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    1234 <check_char+0xd4>
xor    %eax,%eax
call   1070 <doselect@plt>
jmp    1234 <check_char+0xd4>
mov    $0xff,%bl
jmp    1234 <check_char+0xd4>
mov    $0x2,%bl
jmp    1234 <check_char+0xd4>
mov    $0x1,%bl
jmp    1234 <check_char+0xd4>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <moveup@plt>
jmp    1234 <check_char+0xd4>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <movedown@plt>
jmp    1234 <check_char+0xd4>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <moveleft@plt>
jmp    1234 <check_char+0xd4>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <moveright@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0A\00\00"
@.str.1 = [2 x i8] c"\1B\00"
@.str.2 = [4 x i8] c"\1B[A\00"
@.str.3 = [4 x i8] c"\1B[B\00"
@.str.4 = [4 x i8] c"\1B[D\00"
@.str.5 = [4 x i8] c"\1B[C\00"
@.str.6 = [3 x i8] c" \00\00"
define signext i8 @check_char(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %53
6: ; preds = %1
%7 = load i8*, i8** %3
%8 = call i32 @my_strcmp(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %6
store i8 2, i8* %2
br label %54
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = call i32 @my_strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %11
store i8 1, i8* %2
br label %54
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = call i32 @my_strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 (...) @moveup()
br label %50
22: ; preds = %16
%23 = load i8*, i8** %3
%24 = call i32 @my_strcmp(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = call i32 (...) @movedown()
br label %49
28: ; preds = %22
%29 = load i8*, i8** %3
%30 = call i32 @my_strcmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = call i32 (...) @moveleft()
br label %48
34: ; preds = %28
%35 = load i8*, i8** %3
%36 = call i32 @my_strcmp(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%37 = icmp ne i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %34
%39 = call i32 (...) @moveright()
br label %47
40: ; preds = %34
%41 = load i8*, i8** %3
%42 = call i32 @my_strcmp(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%43 = icmp ne i32 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %40
%45 = call i32 (...) @doselect()
br label %46
46: ; preds = %44, %40
br label %47
47: ; preds = %46, %38
br label %48
48: ; preds = %47, %32
br label %49
49: ; preds = %48, %26
br label %50
50: ; preds = %49, %20
br label %51
51: ; preds = %50
br label %52
52: ; preds = %51
store i8 0, i8* %2
br label %54
53: ; preds = %1
store i8 -1, i8* %2
br label %54
54: ; preds = %53, %52, %15, %10
%55 = load i8, i8* %2
ret i8 %55
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0A\00\00"
@.str.1 = [2 x i8] c"\1B\00"
@.str.2 = [4 x i8] c"\1B[A\00"
@.str.3 = [4 x i8] c"\1B[B\00"
@.str.4 = [4 x i8] c"\1B[D\00"
@.str.5 = [4 x i8] c"\1B[C\00"
@.str.6 = [3 x i8] c" \00\00"
define signext i8 @check_char(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %34, label %3
3: ; preds = %1
%4 = tail call i32 @my_strcmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %34, label %6
6: ; preds = %3
%7 = tail call i32 @my_strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %34, label %9
9: ; preds = %6
%10 = tail call i32 @my_strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (...) @moveup()
br label %34
14: ; preds = %9
%15 = tail call i32 @my_strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 (...) @movedown()
br label %34
19: ; preds = %14
%20 = tail call i32 @my_strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 (...) @moveleft()
br label %34
24: ; preds = %19
%25 = tail call i32 @my_strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 (...) @moveright()
br label %34
29: ; preds = %24
%30 = tail call i32 @my_strcmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call i32 (...) @doselect()
br label %34
34: ; preds = %1, %12, %22, %29, %32, %27, %17, %6, %3
%35 = phi i8 [ 2, %3 ], [ 1, %6 ], [ 0, %17 ], [ 0, %27 ], [ 0, %32 ], [ 0, %29 ], [ 0, %22 ], [ 0, %12 ], [ -1, %1 ]
ret i8 %35
}