#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 */
#define KEY_DOWN 129
#define KEY_UP 128
int getc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
void listen_to_arrow_keys() {
  int c;
  while ((c = getc(stdin)) != '#') {
    switch (c) {
    case KEY_UP:
      printf("up\n");
    case KEY_DOWN:
      printf("down\n");
    default:
      printf("c = %d\n");
    }
  }
}


x86 assembly (clang, -O0):
<listen_to_arrow_keys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
call   1040 <getc@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x23,%eax
je     1194 <listen_to_arrow_keys+0x74>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x80,%eax
je     116b <listen_to_arrow_keys+0x4b>
jmp    1158 <listen_to_arrow_keys+0x38>
mov    -0x8(%rbp),%eax
sub    $0x81,%eax
je     1177 <listen_to_arrow_keys+0x57>
jmp    1183 <listen_to_arrow_keys+0x63>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
jmp    1128 <listen_to_arrow_keys+0x8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listen_to_arrow_keys>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2ea9(%rip),%r12
lea    0xec7(%rip),%r14
lea    0xebb(%rip),%r15
lea    0xeac(%rip),%rbx
jmp    1170 <listen_to_arrow_keys+0x40>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    (%r12),%edi
call   1050 <getc@plt>
cmp    $0x80,%eax
je     1190 <listen_to_arrow_keys+0x60>
cmp    $0x81,%eax
je     1160 <listen_to_arrow_keys+0x30>
cmp    $0x23,%eax
jne    1168 <listen_to_arrow_keys+0x38>
jmp    119a <listen_to_arrow_keys+0x6a>
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1160 <listen_to_arrow_keys+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"up\0A\00"
@.str.1 = [6 x i8] c"down\0A\00"
@.str.2 = [8 x i8] c"c = %d\0A\00"
define void @listen_to_arrow_keys() {
%1 = alloca i32
br label %2
2: ; preds = %14, %0
%3 = load i32, i32* @stdin
%4 = call i32 @getc(i32 %3)
store i32 %4, i32* %1
%5 = icmp ne i32 %4, 35
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = load i32, i32* %1
switch i32 %7, label %12 [
i32 128, label %8
i32 129, label %10
]
8: ; preds = %6
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %6, %8
%11 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %6, %10
%13 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12
br label %2
15: ; preds = %2
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.2 = [8 x i8] c"c = %d\0A\00"
@str = [5 x i8] c"down\00"
@str.3 = [3 x i8] c"up\00"
define void @listen_to_arrow_keys() {
br label %1
1: ; preds = %8, %0
%2 = load i32, i32* @stdin
%3 = tail call i32 @getc(i32 %2)
switch i32 %3, label %8 [
i32 35, label %10
i32 128, label %4
i32 129, label %6
]
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.3, i64 0, i64 0))
br label %6
6: ; preds = %1, %4
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %1, %6
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %1
10: ; preds = %1
ret void
}