#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_LEFT 129
#define KEY_RIGHT 128
int /*<<< orphan*/ clear();
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ mvprintw(int, int, char *);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ stdscr;
int /*<<< orphan*/ timeout(int);
int /*<<< orphan*/ usleep(int);
int wgetch(int /*<<< orphan*/);
void run() {
  int platform_x, platform_y;
  int ball_x = 0;
  int ball_y = 0;
  getmaxyx(stdscr, platform_y, platform_x);
  platform_x /= 2;
  platform_y -= 5;
  int c;
  while (1) {
    usleep(350000);
    timeout(1);
    c = wgetch(stdscr);
    switch (c) {
    case KEY_RIGHT: {
      platform_x += 3;
      break;
    }
    case KEY_LEFT: {
      platform_x -= 3;
      break;
    }
    }
    clear();
    mvprintw(ball_y++, ball_x++, "o");
    mvprintw(platform_y, platform_x, "XXX");
    refresh();
  }
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1040 <getmaxyx@plt>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x8(%rbp)
mov    $0x55730,%edi
call   1090 <usleep@plt>
mov    $0x1,%edi
call   1030 <timeout@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1060 <wgetch@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x80,%eax
je     11ff <run+0x8f>
jmp    11ec <run+0x7c>
mov    -0x18(%rbp),%eax
sub    $0x81,%eax
je     120d <run+0x9d>
jmp    1216 <run+0xa6>
mov    -0x4(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x4(%rbp)
jmp    1216 <run+0xa6>
mov    -0x4(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1070 <clear@plt>
mov    -0x10(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xdc6(%rip),%rdx
call   1080 <mvprintw@plt>
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
lea    0xdb6(%rip),%rdx
call   1080 <mvprintw@plt>
mov    $0x0,%al
call   1050 <refresh@plt>
jmp    11b1 <run+0x41>

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e66(%rip),%r12
mov    (%r12),%edi
call   1040 <getmaxyx@plt>
lea    0xe6e(%rip),%r14
lea    0xe69(%rip),%r15
xor    %ebx,%ebx
xor    %r13d,%r13d
jmp    11ce <run+0x5e>
add    $0xfffffffd,%r13d
xor    %eax,%eax
call   1070 <clear@plt>
lea    0x1(%rbx),%ebp
mov    %ebx,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1080 <mvprintw@plt>
mov    %r13d,%esi
mov    %r15,%rdx
call   1080 <mvprintw@plt>
xor    %eax,%eax
call   1050 <refresh@plt>
mov    %ebp,%ebx
mov    $0x55730,%edi
call   1090 <usleep@plt>
mov    $0x1,%edi
call   1030 <timeout@plt>
mov    (%r12),%edi
call   1060 <wgetch@plt>
cmp    $0x81,%eax
je     11a0 <run+0x30>
cmp    $0x80,%eax
jne    11a4 <run+0x34>
add    $0x3,%r13d
jmp    11a4 <run+0x34>

LLVM IR (-O0):
@stdscr = global i32 0
@.str = [2 x i8] c"o\00"
@.str.1 = [4 x i8] c"XXX\00"
define void @run() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %3
store i32 0, i32* %4
%6 = load i32, i32* @stdscr
%7 = load i32, i32* %2
%8 = load i32, i32* %1
%9 = call i32 @getmaxyx(i32 %6, i32 %7, i32 %8)
%10 = load i32, i32* %1
%11 = sdiv i32 %10, 2
store i32 %11, i32* %1
%12 = load i32, i32* %2
%13 = sub nsw i32 %12, 5
store i32 %13, i32* %2
br label %14
14: ; preds = %0, %26
%15 = call i32 @usleep(i32 350000)
%16 = call i32 @timeout(i32 1)
%17 = load i32, i32* @stdscr
%18 = call i32 @wgetch(i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
switch i32 %19, label %26 [
i32 128, label %20
i32 129, label %23
]
20: ; preds = %14
%21 = load i32, i32* %1
%22 = add nsw i32 %21, 3
store i32 %22, i32* %1
br label %26
23: ; preds = %14
%24 = load i32, i32* %1
%25 = sub nsw i32 %24, 3
store i32 %25, i32* %1
br label %26
26: ; preds = %14, %23, %20
%27 = call i32 (...) @clear()
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
%32 = call i32 @mvprintw(i32 %28, i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* %2
%34 = load i32, i32* %1
%35 = call i32 @mvprintw(i32 %33, i32 %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 (...) @refresh()
br label %14
}

LLVM IR (-O2):
@stdscr = global i32 0
@.str = [2 x i8] c"o\00"
@.str.1 = [4 x i8] c"XXX\00"
define void @run() {
%1 = load i32, i32* @stdscr
%2 = tail call i32 @getmaxyx(i32 %1, i32 undef, i32 undef)
br label %3
3: ; preds = %14, %0
%4 = phi i32 [ 0, %0 ], [ %17, %14 ]
%5 = phi i32 [ 0, %0 ], [ %15, %14 ]
%6 = tail call i32 @usleep(i32 350000)
%7 = tail call i32 @timeout(i32 1)
%8 = load i32, i32* @stdscr
%9 = tail call i32 @wgetch(i32 %8)
switch i32 %9, label %14 [
i32 128, label %10
i32 129, label %12
]
10: ; preds = %3
%11 = add nsw i32 %5, 3
br label %14
12: ; preds = %3
%13 = add nsw i32 %5, -3
br label %14
14: ; preds = %3, %12, %10
%15 = phi i32 [ %5, %3 ], [ %13, %12 ], [ %11, %10 ]
%16 = tail call i32 (...) @clear()
%17 = add nuw nsw i32 %4, 1
%18 = tail call i32 @mvprintw(i32 %4, i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @mvprintw(i32 undef, i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 (...) @refresh()
br label %3
}