#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ parse(char *, int **, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fd;
  char str[1000];
  int fabric[1000][1000];
  int i, j, claims = 0;
  char *filename = "input.txt";
  for (i = 0; i < 1000; i++) {
    for (j = 0; j < 1000; j++) {
      fabric[i][j] = 0;
    }
  }
  fd = fopen(filename, "r");
  if (fd == NULL) {
    printf("error opening: %s\n", filename);
  }
  while (fgets(str, 1000, fd) != NULL) {
    parse(str, fabric, 0);
  }
  fclose(fd);
  for (i = 0; i < 1000; i++) {
    for (j = 0; j < 1000; j++) {
      if (fabric[i][j] >= 2) {
        claims++;
      }
    }
  }
  fd = fopen(filename, "r");
  if (fd == NULL) {
    printf("error opening: %s\n", filename);
  }
  while (fgets(str, 1000, fd) != NULL) {
    parse(str, fabric, 1);
  }
  printf("Claimed squares: %d\n", claims);
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d0d20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x3d0d0c(%rbp)
lea    0xe8d(%rip),%rax
mov    %rax,-0x3d0d18(%rbp)
movl   $0x0,-0x3d0d04(%rbp)
cmpl   $0x3e8,-0x3d0d04(%rbp)
jge    1201 <main+0xb1>
movl   $0x0,-0x3d0d08(%rbp)
cmpl   $0x3e8,-0x3d0d08(%rbp)
jge    11e8 <main+0x98>
movslq -0x3d0d04(%rbp),%rcx
lea    -0x3d0d00(%rbp),%rax
imul   $0xfa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x3d0d08(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x3d0d08(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0d08(%rbp)
jmp    119e <main+0x4e>
jmp    11ed <main+0x9d>
mov    -0x3d0d04(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0d04(%rbp)
jmp    1184 <main+0x34>
mov    -0x3d0d18(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1238 <main+0xe8>
mov    -0x3d0d18(%rbp),%rsi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    123d <main+0xed>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1276 <main+0x126>
lea    -0x400(%rbp),%rdi
lea    -0x3d0d00(%rbp),%rsi
xor    %edx,%edx
call   1070 <parse@plt>
jmp    123d <main+0xed>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x3d0d04(%rbp)
cmpl   $0x3e8,-0x3d0d04(%rbp)
jge    131d <main+0x1cd>
movl   $0x0,-0x3d0d08(%rbp)
cmpl   $0x3e8,-0x3d0d08(%rbp)
jge    1304 <main+0x1b4>
movslq -0x3d0d04(%rbp),%rcx
lea    -0x3d0d00(%rbp),%rax
imul   $0xfa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x3d0d08(%rbp),%rcx
cmpl   $0x2,(%rax,%rcx,4)
jl     12eb <main+0x19b>
mov    -0x3d0d0c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0d0c(%rbp)
jmp    12f0 <main+0x1a0>
mov    -0x3d0d08(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0d08(%rbp)
jmp    12a3 <main+0x153>
jmp    1309 <main+0x1b9>
mov    -0x3d0d04(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0d04(%rbp)
jmp    1289 <main+0x139>
mov    -0x3d0d18(%rbp),%rdi
lea    0xcdf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1354 <main+0x204>
mov    -0x3d0d18(%rbp),%rsi
lea    0xcbf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1359 <main+0x209>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1395 <main+0x245>
lea    -0x400(%rbp),%rdi
lea    -0x3d0d00(%rbp),%rsi
mov    $0x1,%edx
call   1070 <parse@plt>
jmp    1359 <main+0x209>
mov    -0x3d0d0c(%rbp),%esi
lea    0xc7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x3d0d20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3d0cf8,%rsp
lea    0x3f0(%rsp),%rbx
mov    $0x3d0900,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe85(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11b4 <main+0x54>
lea    0xe76(%rip),%rdi
lea    0xe63(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1202 <main+0xa2>
mov    %rsp,%rbp
lea    0x3f0(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1080 <parse@plt>
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11e0 <main+0x80>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
movdqa 0xdec(%rip),%xmm0
xor    %ebp,%ebp
jmp    124d <main+0xed>
nopl   0x0(%rax,%rax,1)
paddd  %xmm2,%xmm1
pshufd $0xee,%xmm1,%xmm2
paddd  %xmm1,%xmm2
pshufd $0x55,%xmm2,%xmm1
paddd  %xmm2,%xmm1
movd   %xmm1,%ebp
add    $0x1,%rax
add    $0xfa0,%rbx
cmp    $0x3e8,%rax
je     12a6 <main+0x146>
movd   %ebp,%xmm2
pxor   %xmm1,%xmm1
mov    $0xc,%ecx
nopw   0x0(%rax,%rax,1)
movdqa -0x30(%rbx,%rcx,4),%xmm3
movdqa -0x20(%rbx,%rcx,4),%xmm4
pcmpgtd %xmm0,%xmm3
psubd  %xmm3,%xmm2
pcmpgtd %xmm0,%xmm4
psubd  %xmm4,%xmm1
cmp    $0x3ec,%rcx
je     1220 <main+0xc0>
movdqa -0x10(%rbx,%rcx,4),%xmm3
movdqa (%rbx,%rcx,4),%xmm4
pcmpgtd %xmm0,%xmm3
pcmpgtd %xmm0,%xmm4
psubd  %xmm3,%xmm2
psubd  %xmm4,%xmm1
add    $0x10,%rcx
jmp    1260 <main+0x100>
lea    0xd63(%rip),%rdi
lea    0xd66(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    12d6 <main+0x176>
lea    0xd54(%rip),%rdi
lea    0xd41(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1325 <main+0x1c5>
mov    %rsp,%rbx
lea    0x3f0(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1080 <parse@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1300 <main+0x1a0>
lea    0xd03(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x3d0cf8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"error opening: %s\0A\00"
@.str.3 = [21 x i8] c"Claimed squares: %d\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [1000 x [1000 x i32]]
%3 = bitcast [1000 x [1000 x i32]]* %2 to i8*
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i32* @fgets(i8* %4, i32 1000, i32* %5)
%11 = icmp eq i32* %10, null
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = bitcast [1000 x [1000 x i32]]* %2 to i32**
br label %14
14: ; preds = %12, %14
%15 = call i32 @parse(i8* %4, i32** %13, i32 0)
%16 = call i32* @fgets(i8* %4, i32 1000, i32* %5)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %14
18: ; preds = %14, %9
%19 = call i32 @fclose(i32* %5)
br label %20
20: ; preds = %56, %18
%21 = phi i64 [ 0, %18 ], [ %59, %56 ]
%22 = phi i32 [ 0, %18 ], [ %58, %56 ]
%23 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %22, i64 0
br label %24
24: ; preds = %42, %20
%25 = phi i64 [ 0, %20 ], [ %55, %42 ]
%26 = phi <4 x i32> [ %23, %20 ], [ %53, %42 ]
%27 = phi <4 x i32> [ zeroinitializer, %20 ], [ %54, %42 ]
%28 = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* %2, i64 0, i64 %21, i64 %25
%29 = bitcast i32* %28 to <4 x i32>*
%30 = load <4 x i32>, <4 x i32>* %29
%31 = getelementptr inbounds i32, i32* %28, i64 4
%32 = bitcast i32* %31 to <4 x i32>*
%33 = load <4 x i32>, <4 x i32>* %32
%34 = icmp sgt <4 x i32> %30, <i32 1, i32 1, i32 1, i32 1>
%35 = icmp sgt <4 x i32> %33, <i32 1, i32 1, i32 1, i32 1>
%36 = zext <4 x i1> %34 to <4 x i32>
%37 = zext <4 x i1> %35 to <4 x i32>
%38 = add <4 x i32> %26, %36
%39 = add <4 x i32> %27, %37
%40 = or i64 %25, 8
%41 = icmp eq i64 %40, 1000
br i1 %41, label %56, label %42
42: ; preds = %24
%43 = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* %2, i64 0, i64 %21, i64 %40
%44 = bitcast i32* %43 to <4 x i32>*
%45 = load <4 x i32>, <4 x i32>* %44
%46 = getelementptr inbounds i32, i32* %43, i64 4
%47 = bitcast i32* %46 to <4 x i32>*
%48 = load <4 x i32>, <4 x i32>* %47
%49 = icmp sgt <4 x i32> %45, <i32 1, i32 1, i32 1, i32 1>
%50 = icmp sgt <4 x i32> %48, <i32 1, i32 1, i32 1, i32 1>
%51 = zext <4 x i1> %49 to <4 x i32>
%52 = zext <4 x i1> %50 to <4 x i32>
%53 = add <4 x i32> %38, %51
%54 = add <4 x i32> %39, %52
%55 = add nuw nsw i64 %25, 16
br label %24
56: ; preds = %24
%57 = add <4 x i32> %39, %38
%58 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %57)
%59 = add nuw nsw i64 %21, 1
%60 = icmp eq i64 %59, 1000
br i1 %60, label %61, label %20
61: ; preds = %56
%62 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%63 = icmp eq i32* %62, null
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %66
66: ; preds = %64, %61
%67 = call i32* @fgets(i8* %4, i32 1000, i32* %62)
%68 = icmp eq i32* %67, null
br i1 %68, label %75, label %69
69: ; preds = %66
%70 = bitcast [1000 x [1000 x i32]]* %2 to i32**
br label %71
71: ; preds = %69, %71
%72 = call i32 @parse(i8* %4, i32** %70, i32 1)
%73 = call i32* @fgets(i8* %4, i32 1000, i32* %62)
%74 = icmp eq i32* %73, null
br i1 %74, label %75, label %71
75: ; preds = %71, %66
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %58)
%77 = call i32 @fclose(i32* %62)
ret i32 0
}