#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 atoi(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ strncmp(char *, char *, int);
int getBoardSize(FILE *gameFile) {
  char line[1000];
  while (fgets(line, 1000, gameFile) != NULL) {
    char *sz = "SZ[";
    if (!strncmp(line, sz, 3)) {
      char sizeString[3];
      int i;
      for (i = 0; i < 3; i++) {
        if (isdigit(line[3 + i])) {
          sizeString[i] = line[3 + i];
        } else {
          sizeString[i] = '\0';
          return atoi(sizeString);
        }
      }
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<getBoardSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1241 <getBoardSize+0x101>
lea    0xe8b(%rip),%rax
mov    %rax,-0x408(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x408(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    123c <getBoardSize+0xfc>
movl   $0x0,-0x410(%rbp)
cmpl   $0x3,-0x410(%rbp)
jge    1237 <getBoardSize+0xf7>
mov    -0x410(%rbp),%eax
add    $0x3,%eax
cltq
movsbl -0x400(%rbp,%rax,1),%edi
ff
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     11fb <getBoardSize+0xbb>
mov    -0x410(%rbp),%eax
add    $0x3,%eax
cltq
mov    -0x400(%rbp,%rax,1),%cl
movslq -0x410(%rbp),%rax
mov    %cl,-0x40b(%rbp,%rax,1)
jmp    121e <getBoardSize+0xde>
movslq -0x410(%rbp),%rax
movb   $0x0,-0x40b(%rbp,%rax,1)
lea    -0x40b(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    1248 <getBoardSize+0x108>
jmp    1223 <getBoardSize+0xe3>
mov    -0x410(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x410(%rbp)
jmp    11a7 <getBoardSize+0x67>
jmp    123c <getBoardSize+0xfc>
jmp    114f <getBoardSize+0xf>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getBoardSize>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
mov    $0x3e8,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     1219 <getBoardSize+0xd9>
lea    0xe86(%rip),%r15
lea    0x10(%rsp),%rbp
xor    %r12d,%r12d
jmp    11a5 <getBoardSize+0x65>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1219 <getBoardSize+0xd9>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1190 <getBoardSize+0x50>
movsbl 0x13(%rsp),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     1206 <getBoardSize+0xc6>
movzbl 0x13(%rsp),%eax
mov    %al,0xd(%rsp)
movsbl 0x14(%rsp),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     1200 <getBoardSize+0xc0>
movzbl 0x14(%rsp),%eax
mov    %al,0xe(%rsp)
movsbl 0x15(%rsp),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
jne    1190 <getBoardSize+0x50>
mov    $0x2,%r12d
jmp    1206 <getBoardSize+0xc6>
mov    $0x1,%r12d
movb   $0x0,0xd(%rsp,%r12,1)
lea    0xd(%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"SZ[\00"
define i32 @getBoardSize(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [1000 x i8]
%5 = alloca i8*
%6 = alloca [3 x i8]
%7 = alloca i32
store i32* %0, i32** %3
br label %8
8: ; preds = %50, %1
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%10 = load i32*, i32** %3
%11 = call i32* @fgets(i8* %9, i32 1000, i32* %10)
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %51
13: ; preds = %8
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %5
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = call i32 @strncmp(i8* %14, i8* %15, i32 3)
%17 = icmp ne i32 %16, 0
br i1 %17, label %50, label %18
18: ; preds = %13
store i32 0, i32* %7
br label %19
19: ; preds = %46, %18
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %49
22: ; preds = %19
%23 = load i32, i32* %7
%24 = add nsw i32 3, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = call i64 @isdigit(i8 signext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %22
%31 = load i32, i32* %7
%32 = add nsw i32 3, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 %37
store i8 %35, i8* %38
br label %45
39: ; preds = %22
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 %41
store i8 0, i8* %42
%43 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%44 = call i32 @atoi(i8* %43)
store i32 %44, i32* %2
br label %52
45: ; preds = %30
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %19
49: ; preds = %19
br label %50
50: ; preds = %49, %13
br label %8
51: ; preds = %8
store i32 -1, i32* %2
br label %52
52: ; preds = %51, %39
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@.str = [4 x i8] c"SZ[\00"
define i32 @getBoardSize(i32* nocapture %0) {
%2 = alloca [1000 x i8]
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%5 = call i32* @fgets(i8* %4, i32 1000, i32* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %38, label %7
7: ; preds = %1
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 3
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 4
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 5
br label %13
13: ; preds = %7, %35
%14 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %35
16: ; preds = %13
%17 = load i8, i8* %9
%18 = call i64 @isdigit(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %31, label %20
20: ; preds = %16
%21 = load i8, i8* %9
store i8 %21, i8* %8
%22 = load i8, i8* %10
%23 = call i64 @isdigit(i8 signext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %20
%26 = load i8, i8* %10
store i8 %26, i8* %11
%27 = load i8, i8* %12
%28 = call i64 @isdigit(i8 signext %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %25
br label %35
31: ; preds = %25, %20, %16
%32 = phi i64 [ 0, %16 ], [ 1, %20 ], [ 2, %25 ]
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 %32
store i8 0, i8* %33
%34 = call i32 @atoi(i8* %8)
br label %38
35: ; preds = %13, %30
%36 = call i32* @fgets(i8* %4, i32 1000, i32* %0)
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %13
38: ; preds = %35, %1, %31
%39 = phi i32 [ %34, %31 ], [ -1, %1 ], [ -1, %35 ]
ret i32 %39
}