#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*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
void printWindow(char grid[21][21], int windowWidth, int windowHeight) {
  int x, y, right, top, middleRow, middleColumn;
  right = (21 - windowWidth) / 2;
  top = (21 - windowHeight) / 2;
  middleRow = (windowHeight - 1) / 2 + right;
  middleColumn = (windowWidth - 1) / 2 + top;
  system("cls");
  for (x = 0; x < (windowWidth + 2); ++x)
    printf("-");
  printf("\n");
  for (y = top; y < (top + windowHeight); y++) {
    printf("|");
    for (x = right; x < (right + windowWidth); x++)
      if ((x == middleColumn) && (y == middleRow))
        printf("P");
      else
        printf("%c", grid[x][y]);
    printf("|\n");
  }
  for (x = 0; x < (windowWidth + 2); ++x)
    printf("-");
  printf("\n");
  return;
}


x86 assembly (clang, -O0):
<printWindow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    $0x15,%eax
sub    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    $0x15,%eax
sub    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    0xe79(%rip),%rdi
call   1030 <system@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    11c0 <printWindow+0xa0>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <printWindow+0x73>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x20(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    1289 <printWindow+0x169>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    -0xc(%rbp),%ecx
cmp    %ecx,%eax
jge    126d <printWindow+0x14d>
mov    -0x14(%rbp),%eax
cmp    -0x28(%rbp),%eax
jne    1235 <printWindow+0x115>
mov    -0x18(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    1235 <printWindow+0x115>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125a <printWindow+0x13a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x15,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125f <printWindow+0x13f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f9 <printWindow+0xd9>
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d4 <printWindow+0xb4>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    12bd <printWindow+0x19d>
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1290 <printWindow+0x170>
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printWindow>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
lea    0xeb3(%rip),%rdi
call   1050 <system@plt>
lea    0x2(%rbp),%ebx
mov    %rbp,(%rsp)
cmp    $0xffffffff,%ebp
jl     117f <printWindow+0x4f>
cmp    $0x2,%ebx
mov    $0x1,%ebp
cmovge %ebx,%ebp
nopl   0x0(%rax)
mov    $0x2d,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1170 <printWindow+0x40>
mov    %ebx,0xc(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
jle    1286 <printWindow+0x156>
mov    $0x15,%ebp
lea    -0x1(%r14),%edx
mov    (%rsp),%r8
lea    -0x1(%r8),%esi
mov    $0x15,%edi
sub    %r8d,%edi
sub    %r14d,%ebp
shr    $0x1f,%edx
shr    $0x1f,%esi
mov    %edi,%eax
shr    $0x1f,%eax
mov    %ebp,%ecx
shr    $0x1f,%ecx
add    %edi,%eax
add    %ebp,%ecx
add    %r14d,%edx
add    $0xffffffff,%edx
add    %r8d,%esi
add    $0xffffffff,%esi
sar    %eax
sar    %ecx
sar    %edx
sar    %esi
add    %eax,%edx
add    %ecx,%esi
add    %ecx,%r14d
movslq %eax,%rdi
add    %r8d,%eax
movslq %eax,%rbp
movslq %ecx,%r12
movslq %r14d,%rax
mov    %rax,0x20(%rsp)
movslq %edx,%r13
movslq %esi,%r14
lea    (%rdi,%rdi,4),%rax
mov    %rdi,0x18(%rsp)
lea    (%rdi,%rax,4),%rax
add    %rax,%r15
add    %r12,%r15
mov    %r15,0x10(%rsp)
jmp    123d <printWindow+0x10d>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xddd(%rip),%rdi
call   1040 <puts@plt>
add    $0x1,%r12
addq   $0x1,0x10(%rsp)
cmp    0x20(%rsp),%r12
jge    1286 <printWindow+0x156>
mov    $0x7c,%edi
call   1030 <putchar@plt>
cmpl   $0x0,(%rsp)
jle    1220 <printWindow+0xf0>
mov    0x10(%rsp),%rbx
mov    0x18(%rsp),%r15
jmp    1275 <printWindow+0x145>
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1030 <putchar@plt>
add    $0x1,%r15
add    $0x15,%rbx
cmp    %rbp,%r15
jge    1220 <printWindow+0xf0>
cmp    %r15,%r14
jne    1260 <printWindow+0x130>
mov    $0x50,%edi
cmp    %r13,%r12
je     1263 <printWindow+0x133>
jmp    1260 <printWindow+0x130>
cmpl   $0xffffffff,(%rsp)
jl     12af <printWindow+0x17f>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
mov    $0x1,%ebx
cmovge %eax,%ebx
nopl   0x0(%rax,%rax,1)
mov    $0x2d,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    12a0 <printWindow+0x170>
mov    $0xa,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"cls\00"
@str = [2 x i8] c"|\00"
define void @printWindow([21 x i8]* nocapture %0, i32 %1, i32 %2) {
%4 = sub nsw i32 21, %1
%5 = sdiv i32 %4, 2
%6 = sub nsw i32 21, %2
%7 = sdiv i32 %6, 2
%8 = add nsw i32 %2, -1
%9 = sdiv i32 %8, 2
%10 = add nsw i32 %9, %5
%11 = add nsw i32 %1, -1
%12 = sdiv i32 %11, 2
%13 = add nsw i32 %7, %12
%14 = tail call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = add i32 %1, 2
%16 = icmp sgt i32 %1, -2
br i1 %16, label %17, label %24
17: ; preds = %3
%18 = call i32 @llvm.smax.i32(i32 %15, i32 1)
br label %19
19: ; preds = %17, %19
%20 = phi i32 [ %22, %19 ], [ 0, %17 ]
%21 = tail call i32 @putchar(i32 45)
%22 = add nuw nsw i32 %20, 1
%23 = icmp eq i32 %22, %18
br i1 %23, label %24, label %19
24: ; preds = %19, %3
%25 = tail call i32 @putchar(i32 10)
%26 = icmp sgt i32 %2, 0
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = add nsw i32 %7, %2
%29 = add nsw i32 %5, %1
%30 = icmp sgt i32 %1, 0
%31 = sext i32 %5 to i64
%32 = sext i32 %29 to i64
%33 = sext i32 %7 to i64
%34 = sext i32 %28 to i64
%35 = sext i32 %10 to i64
%36 = sext i32 %13 to i64
br label %40
37: ; preds = %58, %24
br i1 %16, label %38, label %67
38: ; preds = %37
%39 = call i32 @llvm.smax.i32(i32 %15, i32 1)
br label %62
40: ; preds = %27, %58
%41 = phi i64 [ %33, %27 ], [ %60, %58 ]
%42 = tail call i32 @putchar(i32 124)
br i1 %30, label %43, label %58
43: ; preds = %40
%44 = icmp eq i64 %41, %35
br label %45
45: ; preds = %43, %53
%46 = phi i64 [ %31, %43 ], [ %56, %53 ]
%47 = icmp eq i64 %46, %36
%48 = select i1 %47, i1 %44, i1 false
br i1 %48, label %53, label %49
49: ; preds = %45
%50 = getelementptr inbounds [21 x i8], [21 x i8]* %0, i64 %46, i64 %41
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
br label %53
53: ; preds = %45, %49
%54 = phi i32 [ %52, %49 ], [ 80, %45 ]
%55 = tail call i32 @putchar(i32 %54)
%56 = add nsw i64 %46, 1
%57 = icmp slt i64 %56, %32
br i1 %57, label %45, label %58
58: ; preds = %53, %40
%59 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%60 = add nsw i64 %41, 1
%61 = icmp slt i64 %60, %34
br i1 %61, label %40, label %37
62: ; preds = %38, %62
%63 = phi i32 [ %65, %62 ], [ 0, %38 ]
%64 = tail call i32 @putchar(i32 45)
%65 = add nuw nsw i32 %63, 1
%66 = icmp eq i32 %65, %39
br i1 %66, label %67, label %62
67: ; preds = %62, %37
%68 = tail call i32 @putchar(i32 10)
ret void
}