#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*/ ft_putendl(char *);
int /*<<< orphan*/ ft_putstr(char *);
int getarrowkey();
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ usleep(int);
int main(void) {
  int key;
  while (1) {
    key = getarrowkey();
    ft_putstr("\nKEY = ");
    if (key == 1)
      ft_putendl("LEFT");
    else if (key == 2)
      ft_putendl("UP");
    else if (key == 3)
      ft_putendl("DOWN");
    else if (key == 4)
      ft_putendl("RIGHT");
    else
      ft_putendl("nothing");
    usleep(100000);
    system("CLEAR");
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <getarrowkey@plt>
mov    %eax,-0x8(%rbp)
lea    0xe90(%rip),%rdi
call   1060 <ft_putstr@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1190 <main+0x40>
lea    0xe82(%rip),%rdi
call   1040 <ft_putendl@plt>
jmp    11fc <main+0xac>
cmpl   $0x2,-0x8(%rbp)
jne    11ab <main+0x5b>
lea    0xe6c(%rip),%rdi
call   1040 <ft_putendl@plt>
jmp    11f7 <main+0xa7>
cmpl   $0x3,-0x8(%rbp)
jne    11c6 <main+0x76>
lea    0xe54(%rip),%rdi
call   1040 <ft_putendl@plt>
jmp    11f2 <main+0xa2>
cmpl   $0x4,-0x8(%rbp)
jne    11e1 <main+0x91>
lea    0xe3e(%rip),%rdi
call   1040 <ft_putendl@plt>
jmp    11ed <main+0x9d>
lea    0xe33(%rip),%rdi
call   1040 <ft_putendl@plt>
jmp    11f2 <main+0xa2>
jmp    11f7 <main+0xa7>
jmp    11fc <main+0xac>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
lea    0xe16(%rip),%rdi
call   1030 <system@plt>
jmp    115f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xea1(%rip),%r14
lea    0xeb5(%rip),%r15
lea    0xebf(%rip),%r12
lea    0xeaf(%rip),%rbx
jmp    1197 <main+0x47>
cs nopw 0x0(%rax,%rax,1)
call   1040 <ft_putendl@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
xor    %eax,%eax
call   1050 <getarrowkey@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <ft_putstr@plt>
add    $0xffffffff,%ebp
mov    %r15,%rdi
cmp    $0x3,%ebp
ja     1180 <main+0x30>
movslq %ebp,%rax
movslq (%r12,%rax,4),%rdi
add    %r12,%rdi
jmp    1180 <main+0x30>

LLVM IR (-O0):
@.str = [8 x i8] c"\0AKEY = \00"
@.str.1 = [5 x i8] c"LEFT\00"
@.str.2 = [3 x i8] c"UP\00"
@.str.3 = [5 x i8] c"DOWN\00"
@.str.4 = [6 x i8] c"RIGHT\00"
@.str.5 = [8 x i8] c"nothing\00"
@.str.6 = [6 x i8] c"CLEAR\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %0, %30
%4 = call i32 (...) @getarrowkey()
store i32 %4, i32* %2
%5 = call i32 @ft_putstr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = call i32 @ft_putendl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %30
10: ; preds = %3
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @ft_putendl(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %29
15: ; preds = %10
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @ft_putendl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %28
20: ; preds = %15
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 4
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @ft_putendl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %27
25: ; preds = %20
%26 = call i32 @ft_putendl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %27
27: ; preds = %25, %23
br label %28
28: ; preds = %27, %18
br label %29
29: ; preds = %28, %13
br label %30
30: ; preds = %29, %8
%31 = call i32 @usleep(i32 100000)
%32 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %3
}

LLVM IR (-O2):
@.str = [8 x i8] c"\0AKEY = \00"
@.str.1 = [5 x i8] c"LEFT\00"
@.str.2 = [3 x i8] c"UP\00"
@.str.3 = [5 x i8] c"DOWN\00"
@.str.4 = [6 x i8] c"RIGHT\00"
@.str.5 = [8 x i8] c"nothing\00"
@.str.6 = [6 x i8] c"CLEAR\00"
@reltable.main = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32)]
define i32 @main() {
br label %1
1: ; preds = %10, %0
%2 = tail call i32 (...) @getarrowkey()
%3 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = add i32 %2, -1
%5 = icmp ult i32 %4, 4
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = sext i32 %4 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.main to i8*), i64 %8)
br label %10
10: ; preds = %1, %6
%11 = phi i8* [ %9, %6 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %1 ]
%12 = tail call i32 @ft_putendl(i8* %11)
%13 = tail call i32 @usleep(i32 100000)
%14 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %1
}