#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fill_from_top_left(int *, int, int, int, int *);
int /*<<< orphan*/ fill_from_top_right(int *, int, int, int, int *);
int /*<<< orphan*/ print_array(int *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ remove_new_line(char *);
int /*<<< orphan*/ set_bit(int *, int, int);
int /*<<< orphan*/ stdin;
scalar_t__ strcasecmp(char *, char *);
int strtol(char *, char **, int);
int /*<<< orphan*/ zero_arr(int *, int);
void begin_game(uint32_t size) {
  char input[10];
  fgets(input, 10, stdin);
  remove_new_line(input);
  int crossroadsCount = 0;
  uint32_t digits[size];
  int currentRow, currentCol;
  zero_arr(digits, size);
  while (strcasecmp(input, "end") != 0) {
    char *remainder;
    currentRow = strtol(input, &remainder, 10);
    currentCol = strtol(remainder, &remainder, 10);
    set_bit(&digits[currentRow], currentCol, 1);
    fill_from_top_left(digits, currentRow, currentCol, size, &crossroadsCount);
    fill_from_top_right(digits, currentRow, currentCol, size, &crossroadsCount);
    crossroadsCount++;
    fgets(input, 10, stdin);
    remove_new_line(input);
  }
  print_array(digits, size);
  printf("%u", crossroadsCount);
}


x86 assembly (clang, -O0):
<begin_game>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
lea    -0xe(%rbp),%rdi
mov    %rdi,-0x48(%rbp)
mov    $0xa,%esi
call   1070 <fgets@plt>
mov    -0x48(%rbp),%rdi
call   10c0 <remove_new_line@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%esi
call   1040 <zero_arr@plt>
lea    -0xe(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
je     12bf <begin_game+0x11f>
lea    -0xe(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   10a0 <strtol@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   10a0 <strtol@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,-0x30(%rbp)
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%esi
mov    $0x1,%edx
call   1080 <set_bit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x4(%rbp),%ecx
lea    -0x14(%rbp),%r8
call   1090 <fill_from_top_left@plt>
mov    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x4(%rbp),%ecx
lea    -0x14(%rbp),%r8
call   10b0 <fill_from_top_right@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    -0xe(%rbp),%rdi
mov    0x2d43(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1070 <fgets@plt>
lea    -0xe(%rbp),%rdi
call   10c0 <remove_new_line@plt>
jmp    1205 <begin_game+0x65>
mov    -0x40(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1050 <print_array@plt>
mov    -0x14(%rbp),%esi
lea    0xd2f(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<begin_game>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edi,%r12d
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
lea    -0x42(%rbp),%r15
mov    %r15,%rdi
mov    $0xa,%esi
call   1070 <fgets@plt>
mov    %r15,%rdi
call   10c0 <remove_new_line@plt>
mov    %rsp,-0x50(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    %r12d,%eax
mov    %rsp,%rdi
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdi
mov    %rdi,%rsp
mov    %rdi,-0x38(%rbp)
mov    %r12d,%esi
call   1040 <zero_arr@plt>
lea    0xdf4(%rip),%rsi
mov    %r15,%rdi
nop
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     12c8 <begin_game+0x128>
lea    -0x42(%rbp),%rdi
lea    -0x58(%rbp),%rbx
mov    %rbx,%rsi
mov    $0xa,%edx
call   10a0 <strtol@plt>
mov    %r12d,%r15d
mov    %eax,%r12d
mov    -0x58(%rbp),%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
call   10a0 <strtol@plt>
mov    %eax,%r13d
movslq %r12d,%r14
mov    %r15d,%r12d
mov    -0x38(%rbp),%rbx
lea    (%rbx,%r14,4),%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1080 <set_bit@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r13d,%edx
mov    %r15d,%ecx
lea    -0x2c(%rbp),%r15
mov    %r15,%r8
call   1090 <fill_from_top_left@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    0x2d5c(%rip),%rbx
mov    %r13d,%edx
mov    %r12d,%ecx
mov    %r15,%r8
call   10b0 <fill_from_top_right@plt>
addl   $0x1,-0x2c(%rbp)
mov    (%rbx),%edx
lea    -0x42(%rbp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   10c0 <remove_new_line@plt>
mov    %rbx,%rdi
lea    0xd3d(%rip),%rsi
jmp    1210 <begin_game+0x70>
mov    -0x38(%rbp),%rdi
mov    %r12d,%esi
call   1050 <print_array@plt>
mov    -0x2c(%rbp),%esi
lea    0xd26(%rip),%rdi
call   1060 <printf@plt>
mov    -0x50(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"end\00"
@.str.1 = [3 x i8] c"%u\00"
define void @begin_game(i32 %0) {
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %2
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %10, i32 10, i32 %11)
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%14 = call i32 @remove_new_line(i8* %13)
store i32 0, i32* %4
%15 = load i32, i32* %2
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %5
%18 = alloca i32, i64 %16
store i64 %16, i64* %6
%19 = load i32, i32* %2
%20 = call i32 @zero_arr(i32* %18, i32 %19)
br label %21
21: ; preds = %25, %1
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%23 = call i64 @strcasecmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %50
25: ; preds = %21
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%27 = call i32 @strtol(i8* %26, i8** %9, i32 10)
store i32 %27, i32* %7
%28 = load i8*, i8** %9
%29 = call i32 @strtol(i8* %28, i8** %9, i32 10)
store i32 %29, i32* %8
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %18, i64 %31
%33 = load i32, i32* %8
%34 = call i32 @set_bit(i32* %32, i32 %33, i32 1)
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = load i32, i32* %2
%38 = call i32 @fill_from_top_left(i32* %18, i32 %35, i32 %36, i32 %37, i32* %4)
%39 = load i32, i32* %7
%40 = load i32, i32* %8
%41 = load i32, i32* %2
%42 = call i32 @fill_from_top_right(i32* %18, i32 %39, i32 %40, i32 %41, i32* %4)
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%46 = load i32, i32* @stdin
%47 = call i32 @fgets(i8* %45, i32 10, i32 %46)
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%49 = call i32 @remove_new_line(i8* %48)
br label %21
50: ; preds = %21
%51 = load i32, i32* %2
%52 = call i32 @print_array(i32* %18, i32 %51)
%53 = load i32, i32* %4
%54 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%55 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"end\00"
@.str.1 = [3 x i8] c"%u\00"
define void @begin_game(i32 %0) {
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i8*
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 10, i32 %6)
%8 = call i32 @remove_new_line(i8* %5)
%9 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%10 = zext i32 %0 to i64
%11 = call i8* @llvm.stacksave()
%12 = alloca i32, i64 %10
%13 = call i32 @zero_arr(i32* %12, i32 %0)
%14 = call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %34, label %16
16: ; preds = %1
%17 = bitcast i8** %4 to i8*
br label %18
18: ; preds = %16, %18
%19 = call i32 @strtol(i8* %5, i8** %4, i32 10)
%20 = load i8*, i8** %4
%21 = call i32 @strtol(i8* %20, i8** %4, i32 10)
%22 = sext i32 %19 to i64
%23 = getelementptr inbounds i32, i32* %12, i64 %22
%24 = call i32 @set_bit(i32* %23, i32 %21, i32 1)
%25 = call i32 @fill_from_top_left(i32* %12, i32 %19, i32 %21, i32 %0, i32* %3)
%26 = call i32 @fill_from_top_right(i32* %12, i32 %19, i32 %21, i32 %0, i32* %3)
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %5, i32 10, i32 %29)
%31 = call i32 @remove_new_line(i8* %5)
%32 = call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %18
34: ; preds = %18, %1
%35 = call i32 @print_array(i32* %12, i32 %0)
%36 = load i32, i32* %3
%37 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %36)
ret void
}