#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 COLS;
int LINES;
int /*<<< orphan*/ board(int /*<<< orphan*/, int, int, int, int, int, int);
int /*<<< orphan*/ mvprintw(int, int, char *, int);
int /*<<< orphan*/ stdscr;
void magic_board(int **a, int n) {
  int i, j, deltax, deltay;
  int startx, starty;
  starty = (LINES - n * 4) / 2;
  startx = (COLS - n * 6) / 2;
  board(stdscr, starty, startx, n, n, 6, 4);
  deltay = 4 / 2;
  deltax = 6 / 2;
  for (i = 0; i < n; ++i)
    for (j = 0; j < n; ++j)
      mvprintw(starty + j * 4 + deltay, startx + i * 6 + deltax, "%d", a[i][j]);
}


x86 assembly (clang, -O0):
<magic_board>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
imul   $0x6,-0xc(%rbp),%ecx
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    $0x6,%r9d
movl   $0x4,(%rsp)
call   1030 <board@plt>
movl   $0x2,-0x1c(%rbp)
movl   $0x3,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121b <magic_board+0xfb>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1208 <magic_board+0xe8>
mov    -0x24(%rbp),%edi
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
add    %eax,%edi
add    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
imul   $0x6,-0x10(%rbp),%eax
add    %eax,%esi
add    -0x18(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe0b(%rip),%rdx
call   1040 <mvprintw@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b5 <magic_board+0x95>
jmp    120d <magic_board+0xed>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a2 <magic_board+0x82>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<magic_board>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r15d
mov    %rdi,0x20(%rsp)
mov    0x2eab(%rip),%rax
mov    (%rax),%eax
lea    0x0(,%r15,4),%ecx
sub    %ecx,%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
lea    (%r15,%r15,1),%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
movl   $0x4,(%rsp)
mov    %ebp,%esi
mov    %rdx,0x10(%rsp)
mov    %r15d,%ecx
mov    %r15d,%r8d
mov    $0x6,%r9d
call   1030 <board@plt>
test   %r15d,%r15d
jle    123c <magic_board+0x11c>
mov    0x10(%rsp),%rax
add    $0x3,%eax
mov    %rax,0x10(%rsp)
mov    %r15d,%eax
movslq %ebp,%r12
add    $0x2,%r12
mov    %rax,0x18(%rsp)
lea    0x0(,%rax,4),%r14
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0xe30(%rip),%r13
mov    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rsp),%rax
lea    (%rax,%rax,2),%eax
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,2),%ebp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r12,%r15,1),%edi
mov    0x8(%rsp),%rax
mov    (%rbx,%rax,8),%rax
mov    (%rax,%r15,1),%ecx
mov    %ebp,%esi
mov    %r13,%rdx
call   1040 <mvprintw@plt>
add    $0x4,%r15
cmp    %r15,%r14
jne    1200 <magic_board+0xe0>
mov    0x8(%rsp),%rcx
add    $0x1,%rcx
mov    %rcx,%rax
mov    %rcx,0x8(%rsp)
cmp    0x18(%rsp),%rcx
jne    11e0 <magic_board+0xc0>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@LINES = global i32 0
@COLS = global i32 0
@stdscr = global i32 0
@.str = [3 x i8] c"%d\00"
define void @magic_board(i32** nocapture %0, i32 %1) {
%3 = load i32, i32* @LINES
%4 = mul i32 %1, -4
%5 = add i32 %3, %4
%6 = sdiv i32 %5, 2
%7 = load i32, i32* @COLS
%8 = mul i32 %1, -6
%9 = add i32 %7, %8
%10 = sdiv i32 %9, 2
%11 = load i32, i32* @stdscr
%12 = tail call i32 @board(i32 %11, i32 %6, i32 %10, i32 %1, i32 %1, i32 6, i32 4)
%13 = icmp sgt i32 %1, 0
br i1 %13, label %14, label %38
14: ; preds = %2
%15 = add nsw i32 %6, 2
%16 = add nsw i32 %10, 3
%17 = zext i32 %1 to i64
br label %18
18: ; preds = %35, %14
%19 = phi i64 [ 0, %14 ], [ %36, %35 ]
%20 = trunc i64 %19 to i32
%21 = mul nsw i32 %20, 6
%22 = add i32 %16, %21
%23 = getelementptr inbounds i32*, i32** %0, i64 %19
br label %24
24: ; preds = %18, %24
%25 = phi i64 [ 0, %18 ], [ %33, %24 ]
%26 = trunc i64 %25 to i32
%27 = shl i32 %26, 2
%28 = add i32 %15, %27
%29 = load i32*, i32** %23
%30 = getelementptr inbounds i32, i32* %29, i64 %25
%31 = load i32, i32* %30
%32 = tail call i32 @mvprintw(i32 %28, i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i64 %25, 1
%34 = icmp eq i64 %33, %17
br i1 %34, label %35, label %24
35: ; preds = %24
%36 = add nuw nsw i64 %19, 1
%37 = icmp eq i64 %36, %17
br i1 %37, label %38, label %18
38: ; preds = %35, %2
ret void
}