#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*/ FALSE;
int /*<<< orphan*/ clear();
int /*<<< orphan*/ curs_set(int /*<<< orphan*/);
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ mvprintw(int, int, char *);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ stdscr;
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  int x = 0, y = 0;
  int max_x = 0, max_y = 0;
  int next_x = 0;
  int next_y = 0;
  int directionX = 1;
  int directionY = 1;
  initscr();
  noecho();
  curs_set(FALSE);
  getmaxyx(stdscr, max_y, max_x);
  x = max_x / 2;
  y = max_y / 2;
  while (1) {
    getmaxyx(stdscr, max_y, max_x);
    clear();
    mvprintw(y, x, "o");
    refresh();
    usleep(35000);
    next_x = x + directionX;
    next_y = y + directionY;
    if (next_x >= max_x || next_x < 0) {
      directionX *= -1;
    } else {
      x += directionX;
    }
    if (next_y >= max_y || next_y < 0) {
      directionY *= -1;
    } else {
      y += directionY;
    }
  }
  endwin();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
mov    $0x0,%al
call   1030 <initscr@plt>
mov    $0x0,%al
call   1060 <noecho@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1080 <curs_set@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <getmaxyx@plt>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <getmaxyx@plt>
mov    $0x0,%al
call   1070 <clear@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
lea    0xdbe(%rip),%rdx
call   1090 <mvprintw@plt>
mov    $0x0,%al
call   1050 <refresh@plt>
mov    $0x88b8,%edi
call   10a0 <usleep@plt>
mov    -0x14(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1280 <main+0x100>
cmpl   $0x0,-0x24(%rbp)
jge    128c <main+0x10c>
imul   $0xffffffff,-0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1295 <main+0x115>
mov    -0x2c(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12ab <main+0x12b>
cmpl   $0x0,-0x28(%rbp)
jge    12b7 <main+0x137>
imul   $0xffffffff,-0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    12c0 <main+0x140>
mov    -0x30(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    121a <main+0x9a>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <initscr@plt>
xor    %eax,%eax
call   1060 <noecho@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1080 <curs_set@plt>
mov    0x2e41(%rip),%r14
mov    (%r14),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <getmaxyx@plt>
lea    0xe46(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    (%r14),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <getmaxyx@plt>
xor    %eax,%eax
call   1070 <clear@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %rbx,%rdx
call   1090 <mvprintw@plt>
xor    %eax,%eax
call   1050 <refresh@plt>
mov    $0x88b8,%edi
call   10a0 <usleep@plt>
jmp    11c0 <main+0x40>

LLVM IR (-O0):
@FALSE = global i32 0
@stdscr = global i32 0
@.str = [2 x i8] c"o\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 1, i32* %12
store i32 1, i32* %13
%14 = call i32 (...) @initscr()
%15 = call i32 (...) @noecho()
%16 = load i32, i32* @FALSE
%17 = call i32 @curs_set(i32 %16)
%18 = load i32, i32* @stdscr
%19 = load i32, i32* %9
%20 = load i32, i32* %8
%21 = call i32 @getmaxyx(i32 %18, i32 %19, i32 %20)
%22 = load i32, i32* %8
%23 = sdiv i32 %22, 2
store i32 %23, i32* %6
%24 = load i32, i32* %9
%25 = sdiv i32 %24, 2
store i32 %25, i32* %7
br label %26
26: ; preds = %2, %70
%27 = load i32, i32* @stdscr
%28 = load i32, i32* %9
%29 = load i32, i32* %8
%30 = call i32 @getmaxyx(i32 %27, i32 %28, i32 %29)
%31 = call i32 (...) @clear()
%32 = load i32, i32* %7
%33 = load i32, i32* %6
%34 = call i32 @mvprintw(i32 %32, i32 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%35 = call i32 (...) @refresh()
%36 = call i32 @usleep(i32 35000)
%37 = load i32, i32* %6
%38 = load i32, i32* %12
%39 = add nsw i32 %37, %38
store i32 %39, i32* %10
%40 = load i32, i32* %7
%41 = load i32, i32* %13
%42 = add nsw i32 %40, %41
store i32 %42, i32* %11
%43 = load i32, i32* %10
%44 = load i32, i32* %8
%45 = icmp sge i32 %43, %44
br i1 %45, label %49, label %46
46: ; preds = %26
%47 = load i32, i32* %10
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46, %26
%50 = load i32, i32* %12
%51 = mul nsw i32 %50, -1
store i32 %51, i32* %12
br label %56
52: ; preds = %46
%53 = load i32, i32* %12
%54 = load i32, i32* %6
%55 = add nsw i32 %54, %53
store i32 %55, i32* %6
br label %56
56: ; preds = %52, %49
%57 = load i32, i32* %11
%58 = load i32, i32* %9
%59 = icmp sge i32 %57, %58
br i1 %59, label %63, label %60
60: ; preds = %56
%61 = load i32, i32* %11
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %60, %56
%64 = load i32, i32* %13
%65 = mul nsw i32 %64, -1
store i32 %65, i32* %13
br label %70
66: ; preds = %60
%67 = load i32, i32* %13
%68 = load i32, i32* %7
%69 = add nsw i32 %68, %67
store i32 %69, i32* %7
br label %70
70: ; preds = %66, %63
br label %26
}

LLVM IR (-O2):
@FALSE = global i32 0
@stdscr = global i32 0
@.str = [2 x i8] c"o\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @initscr()
%4 = tail call i32 (...) @noecho()
%5 = load i32, i32* @FALSE
%6 = tail call i32 @curs_set(i32 %5)
%7 = load i32, i32* @stdscr
%8 = tail call i32 @getmaxyx(i32 %7, i32 0, i32 0)
br label %9
9: ; preds = %9, %2
%10 = load i32, i32* @stdscr
%11 = tail call i32 @getmaxyx(i32 %10, i32 0, i32 0)
%12 = tail call i32 (...) @clear()
%13 = tail call i32 @mvprintw(i32 0, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 (...) @refresh()
%15 = tail call i32 @usleep(i32 35000)
br label %9
}