#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 */
char EOF;
int /*<<< orphan*/ bas();
int /*<<< orphan*/ droite();
int /*<<< orphan*/ gauche();
char getchar();
int /*<<< orphan*/ haut();
void thread_input() {
  char c;
  int r;
  do {
    c = getchar();
    switch (c) {
    case 'z':
      haut();
      break;
    case 's':
      bas();
      break;
    case 'd':
      droite();
      break;
    case 'q':
      gauche();
      break;
    case 27:
      r = 1;
      while ((c = getchar()) != -1) {
        if (c == 27) {
          r = 1;
          continue;
        }
        r = r * 128 + c;
      }
      switch (r) {
      case 28097:
        haut();
        break;
      case 28098:
        bas();
        break;
      case 28099:
        droite();
        break;
      case 28100:
        gauche();
        break;
      }
    }
  } while (c != EOF);
}


x86 assembly (clang, -O0):
<thread_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x1b,%eax
je     11eb <thread_input+0x9b>
jmp    1177 <thread_input+0x27>
mov    -0xc(%rbp),%eax
sub    $0x64,%eax
je     11d3 <thread_input+0x83>
jmp    1188 <thread_input+0x38>
mov    -0xc(%rbp),%eax
sub    $0x71,%eax
je     11df <thread_input+0x8f>
jmp    1199 <thread_input+0x49>
mov    -0xc(%rbp),%eax
sub    $0x73,%eax
je     11c7 <thread_input+0x77>
jmp    11aa <thread_input+0x5a>
mov    -0xc(%rbp),%eax
sub    $0x7a,%eax
jne    1290 <thread_input+0x140>
jmp    11bb <thread_input+0x6b>
mov    $0x0,%al
call   1030 <haut@plt>
jmp    1290 <thread_input+0x140>
mov    $0x0,%al
call   1060 <bas@plt>
jmp    1290 <thread_input+0x140>
mov    $0x0,%al
call   1040 <droite@plt>
jmp    1290 <thread_input+0x140>
mov    $0x0,%al
call   1070 <gauche@plt>
jmp    1290 <thread_input+0x140>
movl   $0x1,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     1235 <thread_input+0xe5>
movsbl -0x1(%rbp),%eax
cmp    $0x1b,%eax
jne    1221 <thread_input+0xd1>
movl   $0x1,-0x8(%rbp)
jmp    11f2 <thread_input+0xa2>
mov    -0x8(%rbp),%eax
shl    $0x7,%eax
movsbl -0x1(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    11f2 <thread_input+0xa2>
mov    -0x8(%rbp),%eax
add    $0xffff923f,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     128b <thread_input+0x13b>
mov    -0x18(%rbp),%rax
lea    0xda9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1030 <haut@plt>
jmp    128b <thread_input+0x13b>
mov    $0x0,%al
call   1060 <bas@plt>
jmp    128b <thread_input+0x13b>
mov    $0x0,%al
call   1040 <droite@plt>
jmp    128b <thread_input+0x13b>
mov    $0x0,%al
call   1070 <gauche@plt>
jmp    1290 <thread_input+0x140>
jmp    1295 <thread_input+0x145>
movsbl -0x1(%rbp),%eax
mov    0x2d48(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1158 <thread_input+0x8>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_input>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xefd(%rip),%r14
mov    0x2e82(%rip),%r15
lea    0xe93(%rip),%r12
jmp    1189 <thread_input+0x39>
xor    %eax,%eax
call   1070 <gauche@plt>
cs nopw 0x0(%rax,%rax,1)
cmp    (%r15),%bpl
je     1211 <thread_input+0xc1>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
movsbl %al,%eax
lea    -0x64(%rax),%ecx
cmp    $0x16,%ecx
ja     11b0 <thread_input+0x60>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
xor    %eax,%eax
call   1040 <droite@plt>
jmp    1180 <thread_input+0x30>
nop
cmp    $0x1b,%eax
jne    1180 <thread_input+0x30>
mov    $0x1,%ecx
nopw   0x0(%rax,%rax,1)
mov    %ecx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    $0x1,%ecx
cmp    $0x1b,%al
je     11c0 <thread_input+0x70>
cmp    $0xff,%al
je     11e2 <thread_input+0x92>
movsbl %al,%eax
shl    $0x7,%ebx
add    %eax,%ebx
mov    %ebx,%ecx
jmp    11c0 <thread_input+0x70>
mov    $0xff,%bpl
add    $0xffff923f,%ebx
cmp    $0x3,%ebx
ja     1180 <thread_input+0x30>
movslq (%r14,%rbx,4),%rax
add    %r14,%rax
jmp    *%rax
xor    %eax,%eax
call   1030 <haut@plt>
jmp    1180 <thread_input+0x30>
xor    %eax,%eax
call   1060 <bas@plt>
jmp    1180 <thread_input+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
define void @thread_input() {
%1 = alloca i8
%2 = alloca i32
br label %3
3: ; preds = %43, %0
%4 = call signext i8 (...) @getchar()
store i8 %4, i8* %1
%5 = load i8, i8* %1
%6 = sext i8 %5 to i32
switch i32 %6, label %42 [
i32 122, label %7
i32 115, label %9
i32 100, label %11
i32 113, label %13
i32 27, label %15
]
7: ; preds = %3
%8 = call i32 (...) @haut()
br label %42
9: ; preds = %3
%10 = call i32 (...) @bas()
br label %42
11: ; preds = %3
%12 = call i32 (...) @droite()
br label %42
13: ; preds = %3
%14 = call i32 (...) @gauche()
br label %42
15: ; preds = %3
store i32 1, i32* %2
br label %16
16: ; preds = %25, %24, %15
%17 = call signext i8 (...) @getchar()
store i8 %17, i8* %1
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = load i8, i8* %1
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 27
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 1, i32* %2
br label %16
25: ; preds = %20
%26 = load i32, i32* %2
%27 = mul nsw i32 %26, 128
%28 = load i8, i8* %1
%29 = sext i8 %28 to i32
%30 = add nsw i32 %27, %29
store i32 %30, i32* %2
br label %16
31: ; preds = %16
%32 = load i32, i32* %2
switch i32 %32, label %41 [
i32 28097, label %33
i32 28098, label %35
i32 28099, label %37
i32 28100, label %39
]
33: ; preds = %31
%34 = call i32 (...) @haut()
br label %41
35: ; preds = %31
%36 = call i32 (...) @bas()
br label %41
37: ; preds = %31
%38 = call i32 (...) @droite()
br label %41
39: ; preds = %31
%40 = call i32 (...) @gauche()
br label %41
41: ; preds = %31, %39, %37, %35, %33
br label %42
42: ; preds = %41, %3, %13, %11, %9, %7
br label %43
43: ; preds = %42
%44 = load i8, i8* %1
%45 = sext i8 %44 to i32
%46 = load i8, i8* @EOF
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %45, %47
br i1 %48, label %3, label %49
49: ; preds = %43
ret void
}

LLVM IR (-O2):
@EOF = global i8 0
define void @thread_input() {
br label %1
1: ; preds = %30, %0
%2 = tail call signext i8 (...) @getchar()
%3 = sext i8 %2 to i32
switch i32 %3, label %30 [
i32 122, label %4
i32 115, label %6
i32 100, label %8
i32 113, label %10
i32 27, label %12
]
4: ; preds = %1
%5 = tail call i32 (...) @haut()
br label %30
6: ; preds = %1
%7 = tail call i32 (...) @bas()
br label %30
8: ; preds = %1
%9 = tail call i32 (...) @droite()
br label %30
10: ; preds = %1
%11 = tail call i32 (...) @gauche()
br label %30
12: ; preds = %1, %19
%13 = phi i32 [ %20, %19 ], [ 1, %1 ]
%14 = tail call signext i8 (...) @getchar()
switch i8 %14, label %15 [
i8 -1, label %21
i8 27, label %19
]
15: ; preds = %12
%16 = sext i8 %14 to i32
%17 = shl nsw i32 %13, 7
%18 = add nsw i32 %17, %16
br label %19
19: ; preds = %15, %12
%20 = phi i32 [ %18, %15 ], [ 1, %12 ]
br label %12
21: ; preds = %12
switch i32 %13, label %30 [
i32 28097, label %22
i32 28098, label %24
i32 28099, label %26
i32 28100, label %28
]
22: ; preds = %21
%23 = tail call i32 (...) @haut()
br label %30
24: ; preds = %21
%25 = tail call i32 (...) @bas()
br label %30
26: ; preds = %21
%27 = tail call i32 (...) @droite()
br label %30
28: ; preds = %21
%29 = tail call i32 (...) @gauche()
br label %30
30: ; preds = %4, %6, %8, %10, %1, %21, %28, %26, %24, %22
%31 = phi i8 [ %2, %1 ], [ -1, %21 ], [ -1, %28 ], [ -1, %26 ], [ -1, %24 ], [ -1, %22 ], [ %2, %10 ], [ %2, %8 ], [ %2, %6 ], [ %2, %4 ]
%32 = load i8, i8* @EOF
%33 = icmp eq i8 %31, %32
br i1 %33, label %34, label %1
34: ; preds = %30
ret void
}