#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
char map_get(int, int);
void print_map(FILE *out, int y, int x) {
  int i, j;
  fprintf(out, "\e[%d;%dH", y + 22 + 1, x);
  for (j = 0; j < 80; j++)
    fputs("=", out);
  for (i = 0; i < 22; i++) {
    fprintf(out, "\e[%d;%dH", i + y + 1, x + 1);
    for (j = 0; j < 80; j++) {
      char field = map_get(i, j);
      if ((field & 3) == 1)
        if (field & (1 << 3))
          fputs("\e[0mx", out);
        else
          fputs("\e[1;32mX", out);
      else if ((field & 3) == 2)
        if (field & (1 << 3))
          fputs("\e[0mo", out);
        else
          fputs("\e[1;34mO", out);
      else
        fputs(" ", out);
    }
  }
  fputs("\e[0m", out);
}


x86 assembly (clang, -O0):
<print_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
add    $0x16,%edx
add    $0x1,%edx
mov    -0x10(%rbp),%ecx
lea    0xea7(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x50,-0x18(%rbp)
jge    118d <print_map+0x5d>
mov    -0x8(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1165 <print_map+0x35>
movl   $0x0,-0x14(%rbp)
cmpl   $0x16,-0x14(%rbp)
jge    12ab <print_map+0x17b>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    -0xc(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
lea    0xe48(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x50,-0x18(%rbp)
jge    1298 <print_map+0x168>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <map_get@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
and    $0x3,%eax
cmp    $0x1,%eax
jne    1226 <print_map+0xf6>
movsbl -0x19(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1211 <print_map+0xe1>
mov    -0x8(%rbp),%rsi
lea    0xe04(%rip),%rdi
call   1040 <fputs@plt>
jmp    1221 <print_map+0xf1>
mov    -0x8(%rbp),%rsi
lea    0xdf5(%rip),%rdi
call   1040 <fputs@plt>
jmp    1285 <print_map+0x155>
movsbl -0x19(%rbp),%eax
and    $0x3,%eax
cmp    $0x2,%eax
jne    1270 <print_map+0x140>
movsbl -0x19(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     125b <print_map+0x12b>
mov    -0x8(%rbp),%rsi
lea    0xdc9(%rip),%rdi
call   1040 <fputs@plt>
jmp    126b <print_map+0x13b>
mov    -0x8(%rbp),%rsi
lea    0xdba(%rip),%rdi
call   1040 <fputs@plt>
jmp    1280 <print_map+0x150>
mov    -0x8(%rbp),%rsi
lea    0xdae(%rip),%rdi
call   1040 <fputs@plt>
jmp    1285 <print_map+0x155>
jmp    128a <print_map+0x15a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c4 <print_map+0x94>
jmp    129d <print_map+0x16d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1194 <print_map+0x64>
mov    -0x8(%rbp),%rsi
lea    0xd75(%rip),%rdi
call   1040 <fputs@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_map>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ecx
mov    %rdi,%rbx
mov    %rsi,0x10(%rsp)
lea    0x17(%rsi),%edx
lea    0xe9e(%rip),%rsi
mov    %ecx,0xc(%rsp)
call   1050 <fprintf@plt>
mov    $0x50,%ebp
mov    $0x3d,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0xffffffff,%ebp
jne    1170 <print_map+0x30>
addl   $0x1,0xc(%rsp)
xor    %ebp,%ebp
lea    0xe7f(%rip),%r14
lea    0xe72(%rip),%r12
jmp    11ad <print_map+0x6d>
nopl   0x0(%rax)
mov    %r15d,%ebp
cmp    $0x16,%r15d
je     1265 <print_map+0x125>
lea    0x1(%rbp),%r15d
mov    0x10(%rsp),%rax
lea    (%rax,%rbp,1),%edx
add    $0x1,%edx
mov    %rbx,%rdi
lea    0xe3a(%rip),%rsi
mov    0xc(%rsp),%ecx
call   1050 <fprintf@plt>
xor    %r13d,%r13d
jmp    11f3 <print_map+0xb3>
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r12,%rdi
mov    %rbx,%rcx
call   1060 <fwrite@plt>
add    $0x1,%r13d
cmp    $0x50,%r13d
je     11a0 <print_map+0x60>
mov    %ebp,%edi
mov    %r13d,%esi
call   1030 <map_get@plt>
movzbl %al,%ecx
and    $0x3,%ecx
cmp    $0x2,%ecx
je     1220 <print_map+0xe0>
cmp    $0x1,%ecx
jne    1240 <print_map+0x100>
test   $0x8,%al
jne    11d4 <print_map+0x94>
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r14,%rdi
jmp    11e1 <print_map+0xa1>
test   $0x8,%al
jne    124f <print_map+0x10f>
mov    $0x8,%esi
mov    $0x1,%edx
lea    0xde9(%rip),%rdi
jmp    11e1 <print_map+0xa1>
nopw   0x0(%rax,%rax,1)
mov    $0x20,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
jmp    11e9 <print_map+0xa9>
mov    $0x5,%esi
mov    $0x1,%edx
lea    0xdb8(%rip),%rdi
jmp    11e1 <print_map+0xa1>
lea    0xdbb(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fwrite@plt>

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

LLVM IR (-O2):
@.str = [9 x i8] c"\1B[%d;%dH\00"
@.str.2 = [6 x i8] c"\1B[0mx\00"
@.str.3 = [9 x i8] c"\1B[1;32mX\00"
@.str.4 = [6 x i8] c"\1B[0mo\00"
@.str.5 = [9 x i8] c"\1B[1;34mO\00"
@.str.7 = [5 x i8] c"\1B[0m\00"
define void @print_map(i32* nocapture %0, i32 %1, i32 %2) {
%4 = add nsw i32 %1, 23
%5 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %2)
br label %8
6: ; preds = %8
%7 = add nsw i32 %2, 1
br label %13
8: ; preds = %3, %8
%9 = phi i32 [ 0, %3 ], [ %11, %8 ]
%10 = tail call i32 @fputc(i32 61, i32* %0)
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i32 %11, 80
br i1 %12, label %6, label %8
13: ; preds = %6, %42
%14 = phi i32 [ 0, %6 ], [ %15, %42 ]
%15 = add nuw nsw i32 %14, 1
%16 = add i32 %15, %1
%17 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %7)
br label %18
18: ; preds = %13, %39
%19 = phi i32 [ 0, %13 ], [ %40, %39 ]
%20 = tail call signext i8 @map_get(i32 %14, i32 %19)
%21 = zext i8 %20 to i32
%22 = and i32 %21, 3
switch i32 %22, label %37 [
i32 1, label %23
i32 2, label %30
]
23: ; preds = %18
%24 = and i32 %21, 8
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 5, i64 1, i32* %0)
br label %39
28: ; preds = %23
%29 = tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 8, i64 1, i32* %0)
br label %39
30: ; preds = %18
%31 = and i32 %21, 8
%32 = icmp eq i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 5, i64 1, i32* %0)
br label %39
35: ; preds = %30
%36 = tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i64 8, i64 1, i32* %0)
br label %39
37: ; preds = %18
%38 = tail call i32 @fputc(i32 32, i32* %0)
br label %39
39: ; preds = %37, %35, %33, %26, %28
%40 = add nuw nsw i32 %19, 1
%41 = icmp eq i32 %40, 80
br i1 %41, label %42, label %18
42: ; preds = %39
%43 = icmp eq i32 %15, 22
br i1 %43, label %44, label %13
44: ; preds = %42
%45 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i64 4, i64 1, i32* %0)
ret void
}