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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ print_board_row(int /*<<< orphan*/ *, struct game_2048 *,
                                   size_t);
int /*<<< orphan*/ print_table_row(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ wclear(int /*<<< orphan*/ *);
int /*<<< orphan*/ wmove(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ wnoutrefresh(int /*<<< orphan*/ *);
int /*<<< orphan*/ wprintw(int /*<<< orphan*/ *, char *);
void print_board(WINDOW *w, struct game_2048 *g, bool clear) {
  int height, width, left, top;
  assert(w);
  if (clear)
    wclear(w);
  getmaxyx(w, height, width);
  if (height < ((3 * 4) + (4 + 1)) || width < ((8 * 4) + (4 + 1))) {
    wmove(w, 0, 0);
    wprintw(w, "Terminal window is too small to display gameboard");
    wnoutrefresh(w);
    return;
  }
  top = (height - ((3 * 4) + (4 + 1))) / 2;
  left = (width - ((8 * 4) + (4 + 1))) / 2;
  wmove(w, top, left);
  print_table_row(w, false);
  for (size_t row = 0; row < 4; ++row) {
    for (size_t pad = 0; pad < ((3 - 1) / 2); ++pad) {
      wmove(w, ++top, left);
      print_table_row(w, true);
    }
    wmove(w, ++top, left);
    print_board_row(w, g, row);
    for (size_t pad = 0; pad < ((3 - 1) / 2); ++pad) {
      wmove(w, ++top, left);
      print_table_row(w, true);
    }
    wmove(w, ++top, left);
    print_table_row(w, false);
  }
  wnoutrefresh(w);
}


x86 assembly (clang, -O0):
<print_board>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
je     11af <print_board+0x2f>
mov    -0x8(%rbp),%rdi
call   1090 <wclear@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <getmaxyx@plt>
cmpl   $0x11,-0x18(%rbp)
jl     11d2 <print_board+0x52>
cmpl   $0x25,-0x1c(%rbp)
jge    11fd <print_board+0x7d>
mov    -0x8(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10a0 <wmove@plt>
mov    -0x8(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1050 <wprintw@plt>
mov    -0x8(%rbp),%rdi
call   1060 <wnoutrefresh@plt>
jmp    133a <print_board+0x1ba>
mov    -0x18(%rbp),%eax
sub    $0x11,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x25,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
call   10a0 <wmove@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1070 <print_table_row@plt>
movq   $0x0,-0x30(%rbp)
cmpq   $0x4,-0x30(%rbp)
jae    1331 <print_board+0x1b1>
movq   $0x0,-0x38(%rbp)
cmpq   $0x1,-0x38(%rbp)
jae    1293 <print_board+0x113>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
mov    -0x20(%rbp),%edx
call   10a0 <wmove@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1070 <print_table_row@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1254 <print_board+0xd4>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
mov    -0x20(%rbp),%edx
call   10a0 <wmove@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1080 <print_board_row@plt>
movq   $0x0,-0x40(%rbp)
cmpq   $0x1,-0x40(%rbp)
jae    1300 <print_board+0x180>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
mov    -0x20(%rbp),%edx
call   10a0 <wmove@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1070 <print_table_row@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12c1 <print_board+0x141>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
mov    -0x20(%rbp),%edx
call   10a0 <wmove@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1070 <print_table_row@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1241 <print_board+0xc1>
mov    -0x8(%rbp),%rdi
call   1060 <wnoutrefresh@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_board>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <assert@plt>
test   %ebp,%ebp
je     118d <print_board+0x1d>
mov    %rbx,%rdi
call   1080 <wclear@plt>
mov    %rbx,%rdi
call   1030 <getmaxyx@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1070 <print_board_row@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    $0x1,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <print_board_row@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    $0x2,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <print_board_row@plt>
mov    %rbx,%rdi
mov    $0xb,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
mov    $0xd,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
mov    $0xe,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    $0x3,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <print_board_row@plt>
mov    %rbx,%rdi
mov    $0xf,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <print_table_row@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <wnoutrefresh@plt>

LLVM IR (-O0):
%struct.game_2048 = type { i32 }
@.str = [50 x i8] c"Terminal window is too small to display gameboard\00"
define void @print_board(i32* %0, %struct.game_2048* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca %struct.game_2048*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i32* %0, i32** %4
store %struct.game_2048* %1, %struct.game_2048** %5
store i32 %2, i32* %6
%14 = load i32*, i32** %4
%15 = call i32 @assert(i32* %14)
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i32*, i32** %4
%20 = call i32 @wclear(i32* %19)
br label %21
21: ; preds = %18, %3
%22 = load i32*, i32** %4
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = call i32 @getmaxyx(i32* %22, i32 %23, i32 %24)
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 17
br i1 %27, label %31, label %28
28: ; preds = %21
%29 = load i32, i32* %8
%30 = icmp slt i32 %29, 37
br i1 %30, label %31, label %38
31: ; preds = %28, %21
%32 = load i32*, i32** %4
%33 = call i32 @wmove(i32* %32, i32 0, i32 0)
%34 = load i32*, i32** %4
%35 = call i32 @wprintw(i32* %34, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%36 = load i32*, i32** %4
%37 = call i32 @wnoutrefresh(i32* %36)
br label %107
38: ; preds = %28
%39 = load i32, i32* %7
%40 = sub nsw i32 %39, 17
%41 = sdiv i32 %40, 2
store i32 %41, i32* %10
%42 = load i32, i32* %8
%43 = sub nsw i32 %42, 37
%44 = sdiv i32 %43, 2
store i32 %44, i32* %9
%45 = load i32*, i32** %4
%46 = load i32, i32* %10
%47 = load i32, i32* %9
%48 = call i32 @wmove(i32* %45, i32 %46, i32 %47)
%49 = load i32*, i32** %4
%50 = call i32 @print_table_row(i32* %49, i32 0)
store i64 0, i64* %11
br label %51
51: ; preds = %101, %38
%52 = load i64, i64* %11
%53 = icmp ult i64 %52, 4
br i1 %53, label %54, label %104
54: ; preds = %51
store i64 0, i64* %12
br label %55
55: ; preds = %66, %54
%56 = load i64, i64* %12
%57 = icmp ult i64 %56, 1
br i1 %57, label %58, label %69
58: ; preds = %55
%59 = load i32*, i32** %4
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
%62 = load i32, i32* %9
%63 = call i32 @wmove(i32* %59, i32 %61, i32 %62)
%64 = load i32*, i32** %4
%65 = call i32 @print_table_row(i32* %64, i32 1)
br label %66
66: ; preds = %58
%67 = load i64, i64* %12
%68 = add i64 %67, 1
store i64 %68, i64* %12
br label %55
69: ; preds = %55
%70 = load i32*, i32** %4
%71 = load i32, i32* %10
%72 = add nsw i32 %71, 1
store i32 %72, i32* %10
%73 = load i32, i32* %9
%74 = call i32 @wmove(i32* %70, i32 %72, i32 %73)
%75 = load i32*, i32** %4
%76 = load %struct.game_2048*, %struct.game_2048** %5
%77 = load i64, i64* %11
%78 = call i32 @print_board_row(i32* %75, %struct.game_2048* %76, i64 %77)
store i64 0, i64* %13
br label %79
79: ; preds = %90, %69
%80 = load i64, i64* %13
%81 = icmp ult i64 %80, 1
br i1 %81, label %82, label %93
82: ; preds = %79
%83 = load i32*, i32** %4
%84 = load i32, i32* %10
%85 = add nsw i32 %84, 1
store i32 %85, i32* %10
%86 = load i32, i32* %9
%87 = call i32 @wmove(i32* %83, i32 %85, i32 %86)
%88 = load i32*, i32** %4
%89 = call i32 @print_table_row(i32* %88, i32 1)
br label %90
90: ; preds = %82
%91 = load i64, i64* %13
%92 = add i64 %91, 1
store i64 %92, i64* %13
br label %79
93: ; preds = %79
%94 = load i32*, i32** %4
%95 = load i32, i32* %10
%96 = add nsw i32 %95, 1
store i32 %96, i32* %10
%97 = load i32, i32* %9
%98 = call i32 @wmove(i32* %94, i32 %96, i32 %97)
%99 = load i32*, i32** %4
%100 = call i32 @print_table_row(i32* %99, i32 0)
br label %101
101: ; preds = %93
%102 = load i64, i64* %11
%103 = add i64 %102, 1
store i64 %103, i64* %11
br label %51
104: ; preds = %51
%105 = load i32*, i32** %4
%106 = call i32 @wnoutrefresh(i32* %105)
br label %107
107: ; preds = %104, %31
ret void
}

LLVM IR (-O2):
%struct.game_2048 = type { i32 }
define void @print_board(i32* %0, %struct.game_2048* %1, i32 %2) {
%4 = tail call i32 @assert(i32* %0)
%5 = icmp eq i32 %2, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @wclear(i32* %0)
br label %8
8: ; preds = %6, %3
%9 = tail call i32 @getmaxyx(i32* %0, i32 undef, i32 undef)
%10 = tail call i32 @wmove(i32* %0, i32 0, i32 0)
%11 = tail call i32 @print_table_row(i32* %0, i32 0)
%12 = tail call i32 @wmove(i32* %0, i32 1, i32 0)
%13 = tail call i32 @print_table_row(i32* %0, i32 1)
%14 = tail call i32 @wmove(i32* %0, i32 2, i32 0)
%15 = tail call i32 @print_board_row(i32* %0, %struct.game_2048* %1, i64 0)
%16 = tail call i32 @wmove(i32* %0, i32 3, i32 0)
%17 = tail call i32 @print_table_row(i32* %0, i32 1)
%18 = tail call i32 @wmove(i32* %0, i32 4, i32 0)
%19 = tail call i32 @print_table_row(i32* %0, i32 0)
%20 = tail call i32 @wmove(i32* %0, i32 5, i32 0)
%21 = tail call i32 @print_table_row(i32* %0, i32 1)
%22 = tail call i32 @wmove(i32* %0, i32 6, i32 0)
%23 = tail call i32 @print_board_row(i32* %0, %struct.game_2048* %1, i64 1)
%24 = tail call i32 @wmove(i32* %0, i32 7, i32 0)
%25 = tail call i32 @print_table_row(i32* %0, i32 1)
%26 = tail call i32 @wmove(i32* %0, i32 8, i32 0)
%27 = tail call i32 @print_table_row(i32* %0, i32 0)
%28 = tail call i32 @wmove(i32* %0, i32 9, i32 0)
%29 = tail call i32 @print_table_row(i32* %0, i32 1)
%30 = tail call i32 @wmove(i32* %0, i32 10, i32 0)
%31 = tail call i32 @print_board_row(i32* %0, %struct.game_2048* %1, i64 2)
%32 = tail call i32 @wmove(i32* %0, i32 11, i32 0)
%33 = tail call i32 @print_table_row(i32* %0, i32 1)
%34 = tail call i32 @wmove(i32* %0, i32 12, i32 0)
%35 = tail call i32 @print_table_row(i32* %0, i32 0)
%36 = tail call i32 @wmove(i32* %0, i32 13, i32 0)
%37 = tail call i32 @print_table_row(i32* %0, i32 1)
%38 = tail call i32 @wmove(i32* %0, i32 14, i32 0)
%39 = tail call i32 @print_board_row(i32* %0, %struct.game_2048* %1, i64 3)
%40 = tail call i32 @wmove(i32* %0, i32 15, i32 0)
%41 = tail call i32 @print_table_row(i32* %0, i32 1)
%42 = tail call i32 @wmove(i32* %0, i32 16, i32 0)
%43 = tail call i32 @print_table_row(i32* %0, i32 0)
%44 = tail call i32 @wnoutrefresh(i32* %0)
ret void
}