#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 */
typedef int /*<<< orphan*/ WINDOW;

/* Variables and functions */
#define ERR 132
#define KEY_DOWN 131
#define KEY_LEFT 130
#define KEY_RIGHT 129
#define KEY_UP 128
int atoi(char *);
int /*<<< orphan*/ curs_set(int /*<<< orphan*/);
int /*<<< orphan*/ endwin();
int getch();
int /*<<< orphan*/ init_colors();
int /*<<< orphan*/ init_tetros();
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ napms(int);
int /*<<< orphan*/ *new_board();
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ timeout(int /*<<< orphan*/);
int /*<<< orphan*/ update_board(int /*<<< orphan*/ *);
int /*<<< orphan*/ wrefresh(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Usage: %s [level]\n", argv[0]);
    return 0;
  }
  int level = atoi(argv[1]);
  if (level < 1 || level > 10) {
    printf("level must be 1-10\n");
    return 0;
  }
  initscr();
  init_colors();
  init_tetros();
  noecho();
  curs_set(0);
  timeout(0);
  WINDOW *board = new_board();
  int done = 0;
  int ticks = 0;
  while (!done) {
    int ch;
    switch (ch = getch()) {
    case 'q':
      done = 1;
      continue;
    case KEY_LEFT:
      continue;
    case KEY_RIGHT:
      continue;
    case KEY_UP:
      continue;
    case KEY_DOWN:
      continue;
    case ERR:
      break;
    default:
      continue;
    }
    if (ticks >= (10 - level)) {
      update_board(board);
      wrefresh(board);
      refresh();
      ticks = 0;
    }
    ticks++;
    napms(50);
  }
  endwin();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1231 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    137b <main+0x18b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     1255 <main+0x65>
cmpl   $0xa,-0x14(%rbp)
jle    126f <main+0x7f>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    137b <main+0x18b>
mov    $0x0,%al
call   1060 <initscr@plt>
mov    $0x0,%al
call   10f0 <init_colors@plt>
mov    $0x0,%al
call   1080 <init_tetros@plt>
mov    $0x0,%al
call   10d0 <noecho@plt>
xor    %edi,%edi
call   1110 <curs_set@plt>
xor    %edi,%edi
call   1070 <timeout@plt>
mov    $0x0,%al
call   1090 <new_board@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12c8 <main+0xd8>
jmp    136d <main+0x17d>
xor    %eax,%eax
call   10b0 <getch@plt>
mov    %eax,-0x2c(%rbp)
add    $0xffffff8f,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x13,%eax
ja     131d <main+0x12d>
mov    -0x38(%rbp),%rax
lea    0xd11(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x24(%rbp)
jmp    12b2 <main+0xc2>
jmp    12b2 <main+0xc2>
jmp    12b2 <main+0xc2>
jmp    12b2 <main+0xc2>
jmp    12b2 <main+0xc2>
jmp    1322 <main+0x132>
jmp    12b2 <main+0xc2>
mov    -0x28(%rbp),%eax
mov    $0xa,%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jl     1355 <main+0x165>
mov    -0x20(%rbp),%rdi
call   1030 <update_board@plt>
mov    -0x20(%rbp),%rdi
call   1040 <wrefresh@plt>
mov    $0x0,%al
call   10a0 <refresh@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    $0x32,%edi
call   1100 <napms@plt>
jmp    12b2 <main+0xc2>
mov    $0x0,%al
call   10c0 <endwin@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    122d <main+0x2d>
mov    0x8(%rsi),%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebx
lea    -0xb(%rbx),%eax
cmp    $0xfffffff5,%eax
ja     1243 <main+0x43>
lea    0xdf0(%rip),%rdi
call   1040 <puts@plt>
jmp    12c6 <main+0xc6>
mov    (%rsi),%rsi
lea    0xdc9(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12c6 <main+0xc6>
xor    %eax,%eax
call   1070 <initscr@plt>
xor    %eax,%eax
call   1100 <init_colors@plt>
xor    %eax,%eax
call   1090 <init_tetros@plt>
xor    %eax,%eax
call   10e0 <noecho@plt>
xor    %edi,%edi
call   1120 <curs_set@plt>
xor    %edi,%edi
call   1080 <timeout@plt>
xor    %eax,%eax
call   10a0 <new_board@plt>
mov    %rax,%r14
mov    $0xa,%ebp
sub    %ebx,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <getch@plt>
cmp    $0x71,%eax
je     12bf <main+0xbf>
cmp    $0x84,%eax
jne    1280 <main+0x80>
cmp    %ebp,%ebx
jl     12b0 <main+0xb0>
mov    %r14,%rdi
call   1030 <update_board@plt>
mov    %r14,%rdi
call   1050 <wrefresh@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   10b0 <refresh@plt>
add    $0x1,%ebx
mov    $0x32,%edi
call   1110 <napms@plt>
jmp    1280 <main+0x80>
xor    %eax,%eax
call   10d0 <endwin@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Usage: %s [level]\0A\00"
@.str.1 = [20 x i8] c"level must be 1-10\0A\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 0, i32* %3
br label %68
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 1
br i1 %24, label %28, label %25
25: ; preds = %18
%26 = load i32, i32* %6
%27 = icmp sgt i32 %26, 10
br i1 %27, label %28, label %30
28: ; preds = %25, %18
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %68
30: ; preds = %25
%31 = call i32 (...) @initscr()
%32 = call i32 (...) @init_colors()
%33 = call i32 (...) @init_tetros()
%34 = call i32 (...) @noecho()
%35 = call i32 @curs_set(i32 0)
%36 = call i32 @timeout(i32 0)
%37 = call i32* (...) @new_board()
store i32* %37, i32** %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %38
38: ; preds = %62, %50, %48, %47, %46, %45, %44, %30
%39 = load i32, i32* %8
%40 = icmp ne i32 %39, 0
%41 = xor i1 %40, true
br i1 %41, label %42, label %66
42: ; preds = %38
%43 = call i32 (...) @getch()
store i32 %43, i32* %10
switch i32 %43, label %50 [
i32 113, label %44
i32 130, label %45
i32 129, label %46
i32 128, label %47
i32 131, label %48
i32 132, label %49
]
44: ; preds = %42
store i32 1, i32* %8
br label %38
45: ; preds = %42
br label %38
46: ; preds = %42
br label %38
47: ; preds = %42
br label %38
48: ; preds = %42
br label %38
49: ; preds = %42
br label %51
50: ; preds = %42
br label %38
51: ; preds = %49
%52 = load i32, i32* %9
%53 = load i32, i32* %6
%54 = sub nsw i32 10, %53
%55 = icmp sge i32 %52, %54
br i1 %55, label %56, label %62
56: ; preds = %51
%57 = load i32*, i32** %7
%58 = call i32 @update_board(i32* %57)
%59 = load i32*, i32** %7
%60 = call i32 @wrefresh(i32* %59)
%61 = call i32 (...) @refresh()
store i32 0, i32* %9
br label %62
62: ; preds = %56, %51
%63 = load i32, i32* %9
%64 = add nsw i32 %63, 1
store i32 %64, i32* %9
%65 = call i32 @napms(i32 50)
br label %38
66: ; preds = %38
%67 = call i32 (...) @endwin()
store i32 0, i32* %3
br label %68
68: ; preds = %66, %28, %13
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [19 x i8] c"Usage: %s [level]\0A\00"
@str = [19 x i8] c"level must be 1-10\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %40
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = add i32 %10, -11
%12 = icmp ult i32 %11, -10
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %40
15: ; preds = %7
%16 = tail call i32 (...) @initscr()
%17 = tail call i32 (...) @init_colors()
%18 = tail call i32 (...) @init_tetros()
%19 = tail call i32 (...) @noecho()
%20 = tail call i32 @curs_set(i32 0)
%21 = tail call i32 @timeout(i32 0)
%22 = tail call i32* (...) @new_board()
%23 = sub nuw nsw i32 10, %10
br label %24
24: ; preds = %34, %15
%25 = phi i32 [ %36, %34 ], [ 0, %15 ]
br label %26
26: ; preds = %24, %26
%27 = tail call i32 (...) @getch()
switch i32 %27, label %26 [
i32 113, label %38
i32 132, label %28
]
28: ; preds = %26
%29 = icmp slt i32 %25, %23
br i1 %29, label %34, label %30
30: ; preds = %28
%31 = tail call i32 @update_board(i32* %22)
%32 = tail call i32 @wrefresh(i32* %22)
%33 = tail call i32 (...) @refresh()
br label %34
34: ; preds = %30, %28
%35 = phi i32 [ 0, %30 ], [ %25, %28 ]
%36 = add nsw i32 %35, 1
%37 = tail call i32 @napms(i32 50)
br label %24
38: ; preds = %26
%39 = tail call i32 (...) @endwin()
br label %40
40: ; preds = %13, %38, %4
ret i32 0
}