#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 */
struct timespec {
  int tv_nsec;
  int /*<<< orphan*/ member_0;
};
struct game {
  int dummy;
};

/* Variables and functions */
struct game *game_new(size_t, size_t);
int /*<<< orphan*/ game_reset(struct game *);
int get_input();
int /*<<< orphan*/ io_setup();
int /*<<< orphan*/ make_turn(struct game *, int);
scalar_t__ nanosleep(struct timespec *, struct timespec *);
int /*<<< orphan*/ print_game(struct game *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
size_t strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int update(struct game *);
int main(int argc, char **argv) {
  size_t height = 8, width = 8;
  if (argc > 1) {
    if (argc != 3) {
      printf("Usage: %s height width\n", argv[0]);
      return -1;
    }
    height = strtol(argv[1], NULL, 10);
    width = strtol(argv[2], NULL, 10);
  }
  struct game *game = game_new(height, width);
  int inp, len;
  srand(time(NULL));
  game_reset(game);
  io_setup();
  struct timespec sleeplen = {0};
  print_game(game);
  while (1) {
    sleeplen.tv_nsec = 400000000;
    while (nanosleep(&sleeplen, &sleeplen))
      ;
    while ((inp = get_input())) {
      make_turn(game, inp);
    }
    len = update(game);
    if (len < 0) {
      printf("\n\nYOU LOSE!\nScore: %d\n", -len);
      break;
    }
    print_game(game);
  }
}


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)
movq   $0x8,-0x18(%rbp)
movq   $0x8,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    125f <main+0x8f>
cmpl   $0x3,-0x8(%rbp)
je     122b <main+0x5b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1330 <main+0x160>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10c0 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10c0 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <game_new@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,%edi
call   10b0 <srand@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <game_reset@plt>
mov    $0x0,%al
call   1050 <io_setup@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
mov    -0x28(%rbp),%rdi
call   1040 <print_game@plt>
movl   $0x17d78400,-0x38(%rbp)
lea    -0x38(%rbp),%rsi
mov    %rsi,%rdi
call   1070 <nanosleep@plt>
cmp    $0x0,%rax
je     12cb <main+0xfb>
jmp    12b0 <main+0xe0>
jmp    12d0 <main+0x100>
mov    $0x0,%al
call   10f0 <get_input@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
je     12f4 <main+0x124>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   10e0 <make_turn@plt>
jmp    12d0 <main+0x100>
mov    -0x28(%rbp),%rdi
call   1030 <update@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1322 <main+0x152>
xor    %esi,%esi
sub    -0x30(%rbp),%esi
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1330 <main+0x160>
mov    -0x28(%rbp),%rdi
call   1040 <print_game@plt>
jmp    12a9 <main+0xd9>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    $0x8,%esi
mov    $0x8,%ebx
cmp    $0x2,%edi
jl     1205 <main+0x45>
cmp    $0x3,%edi
jne    12ae <main+0xee>
mov    0x8(%r14),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %rax,%rsi
mov    %rbx,%rdi
call   1080 <game_new@plt>
mov    %rax,%r14
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   10a0 <srand@plt>
mov    %r14,%rdi
call   1090 <game_reset@plt>
xor    %eax,%eax
call   1050 <io_setup@plt>
movq   $0x0,(%rsp)
mov    %r14,%rdi
call   1040 <print_game@plt>
mov    %rsp,%rbx
movl   $0x17d78400,(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1070 <nanosleep@plt>
test   %rax,%rax
jne    1250 <main+0x90>
jmp    1277 <main+0xb7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%esi
call   10d0 <make_turn@plt>
xor    %eax,%eax
call   10e0 <get_input@plt>
mov    %r14,%rdi
test   %eax,%eax
jne    1270 <main+0xb0>
call   1030 <update@plt>
test   %eax,%eax
js     1298 <main+0xd8>
mov    %r14,%rdi
call   1040 <print_game@plt>
jmp    1240 <main+0x80>
neg    %eax
lea    0xd77(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12c4 <main+0x104>
mov    (%r14),%rsi
lea    0xd48(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.game = type { i32 }
%struct.timespec = type { i32, i32 }
@.str = [24 x i8] c"Usage: %s height width\0A\00"
@.str.1 = [23 x i8] c"\0A\0AYOU LOSE!\0AScore: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca %struct.game*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.timespec
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 8, i64* %6
store i64 8, i64* %7
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %31
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 -1, i32* %3
br label %69
22: ; preds = %14
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @strtol(i8* %25, i32* null, i32 10)
store i64 %26, i64* %6
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i64 @strtol(i8* %29, i32* null, i32 10)
store i64 %30, i64* %7
br label %31
31: ; preds = %22, %2
%32 = load i64, i64* %6
%33 = load i64, i64* %7
%34 = call %struct.game* @game_new(i64 %32, i64 %33)
store %struct.game* %34, %struct.game** %8
%35 = call i32 @time(i32* null)
%36 = call i32 @srand(i32 %35)
%37 = load %struct.game*, %struct.game** %8
%38 = call i32 @game_reset(%struct.game* %37)
%39 = call i32 (...) @io_setup()
%40 = bitcast %struct.timespec* %11 to i8*
%41 = load %struct.game*, %struct.game** %8
%42 = call i32 @print_game(%struct.game* %41)
br label %43
43: ; preds = %31, %66
%44 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 0
store i32 400000000, i32* %44
br label %45
45: ; preds = %48, %43
%46 = call i64 @nanosleep(%struct.timespec* %11, %struct.timespec* %11)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %45
br label %45
49: ; preds = %45
br label %50
50: ; preds = %53, %49
%51 = call i32 (...) @get_input()
store i32 %51, i32* %9
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %50
%54 = load %struct.game*, %struct.game** %8
%55 = load i32, i32* %9
%56 = call i32 @make_turn(%struct.game* %54, i32 %55)
br label %50
57: ; preds = %50
%58 = load %struct.game*, %struct.game** %8
%59 = call i32 @update(%struct.game* %58)
store i32 %59, i32* %10
%60 = load i32, i32* %10
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %57
%63 = load i32, i32* %10
%64 = sub nsw i32 0, %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %64)
br label %69
66: ; preds = %57
%67 = load %struct.game*, %struct.game** %8
%68 = call i32 @print_game(%struct.game* %67)
br label %43
69: ; preds = %17, %62
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
%struct.game = type { i32 }
@.str = [24 x i8] c"Usage: %s height width\0A\00"
@.str.1 = [23 x i8] c"\0A\0AYOU LOSE!\0AScore: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.timespec*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %18
6: ; preds = %2
%7 = icmp eq i32 %0, 3
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %49
11: ; preds = %6
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i64 @strtol(i8* nocapture %13, i32* null, i32 10)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i64 @strtol(i8* nocapture %16, i32* null, i32 10)
br label %18
18: ; preds = %11, %2
%19 = phi i64 [ %17, %11 ], [ 8, %2 ]
%20 = phi i64 [ %14, %11 ], [ 8, %2 ]
%21 = tail call %struct.game* @game_new(i64 %20, i64 %19)
%22 = tail call i32 @time(i32* null)
%23 = tail call i32 @srand(i32 %22)
%24 = tail call i32 @game_reset(%struct.game* %21)
%25 = tail call i32 (...) @io_setup()
%26 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%27 = tail call i32 @print_game(%struct.game* %21)
%28 = bitcast i64* %3 to i32*
br label %29
29: ; preds = %47, %18
store i32 400000000, i32* %28
br label %30
30: ; preds = %30, %29
%31 = call i64 @nanosleep(%struct.timespec* %4, %struct.timespec* %4)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %30
33: ; preds = %30
%34 = call i32 (...) @get_input()
%35 = icmp eq i32 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %33, %36
%37 = phi i32 [ %39, %36 ], [ %34, %33 ]
%38 = call i32 @make_turn(%struct.game* %21, i32 %37)
%39 = call i32 (...) @get_input()
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %36
41: ; preds = %36, %33
%42 = call i32 @update(%struct.game* %21)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = sub nsw i32 0, %42
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %45)
br label %49
47: ; preds = %41
%48 = call i32 @print_game(%struct.game* %21)
br label %29
49: ; preds = %44, %8
%50 = phi i32 [ -1, %8 ], [ 0, %44 ]
ret i32 %50
}