#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ readboard(int **, int *, int *, char *);
scalar_t__ strtol(char *, char **, int);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int loadboard(int b[8][8], int *view, int *color, int *maxtime, char *path) {
  int i, n;
  int t = 0;
  char buf[31];
  FILE *cakegame;
  cakegame = fopen(path, "r");
  if (!cakegame) {
    perror(path);
    return 0;
  }
  while ((n = fgetc(cakegame)) != EOF) {
    ungetc(n, cakegame);
    for (i = 0; i < 30; i++) {
      if ((n = fgetc(cakegame)) == '\n') {
        buf[i] = '\0';
        break;
      }
      buf[i] = n;
    }
    t += readboard(b, view, color, buf);
  }
  if (t != 45)
    printf("\ngame file %s corrupt ?\n", path);
  *maxtime = (int)strtol(buf, (char **)NULL, 10);
  fclose(cakegame);
  printf("\nread from file %s.\n", path);
  printf("cake maxtime set to %d.\n", *maxtime);
  return 1;
}


x86 assembly (clang, -O0):
<loadboard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    11d7 <loadboard+0x57>
mov    -0x30(%rbp),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e5 <loadboard+0x165>
jmp    11dc <loadboard+0x5c>
mov    -0x68(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x38(%rbp)
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%eax
je     1279 <loadboard+0xf9>
mov    -0x38(%rbp),%edi
mov    -0x68(%rbp),%rsi
call   1080 <ungetc@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x1e,-0x34(%rbp)
jge    1252 <loadboard+0xd2>
mov    -0x68(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x38(%rbp)
cmp    $0xa,%eax
jne    1237 <loadboard+0xb7>
movslq -0x34(%rbp),%rax
movb   $0x0,-0x60(%rbp,%rax,1)
jmp    1252 <loadboard+0xd2>
mov    -0x38(%rbp),%eax
mov    %al,%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x60(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    120a <loadboard+0x8a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x60(%rbp),%rcx
call   1050 <readboard@plt>
mov    %rax,%rcx
movslq -0x3c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x3c(%rbp)
jmp    11dc <loadboard+0x5c>
cmpl   $0x2d,-0x3c(%rbp)
je     1295 <loadboard+0x115>
mov    -0x30(%rbp),%rsi
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rsi
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadboard>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,%r15
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
lea    0xe5c(%rip),%rsi
mov    %r8,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12b0 <loadboard+0x130>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%eax
je     124d <loadboard+0xcd>
mov    %r15,(%rsp)
mov    %r14,0x8(%rsp)
xor    %r15d,%r15d
jmp    120f <loadboard+0x8f>
nopl   (%rax)
movb   $0x0,0x10(%rsp,%r14,1)
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
lea    0x10(%rsp),%rcx
call   1050 <readboard@plt>
add    %eax,%r15d
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2ddd(%rip),%rcx
cmp    (%rcx),%eax
je     123e <loadboard+0xbe>
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <ungetc@plt>
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    $0xa,%eax
je     11e0 <loadboard+0x60>
mov    %al,0x10(%rsp,%r14,1)
add    $0x1,%r14
cmp    $0x1e,%r14
jne    1220 <loadboard+0xa0>
jmp    11e6 <loadboard+0x66>
cmp    $0x2d,%r15d
mov    0x8(%rsp),%r14
mov    (%rsp),%r15
je     125e <loadboard+0xde>
lea    0xdae(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,(%r14)
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xd9a(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%esi
lea    0xd9b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   10a0 <perror@plt>
xor    %eax,%eax
jmp    12a1 <loadboard+0x121>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.1 = [25 x i8] c"\0Agame file %s corrupt ?\0A\00"
@.str.2 = [21 x i8] c"\0Aread from file %s.\0A\00"
@.str.3 = [25 x i8] c"cake maxtime set to %d.\0A\00"
define i32 @loadboard([8 x i32]* %0, i32* %1, i32* %2, i32* %3, i8* %4) {
%6 = alloca i32
%7 = alloca [8 x i32]*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [31 x i8]
%16 = alloca i32*
store [8 x i32]* %0, [8 x i32]** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i8* %4, i8** %11
store i32 0, i32* %14
%17 = load i8*, i8** %11
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %16
%19 = load i32*, i32** %16
%20 = icmp ne i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %5
%22 = load i8*, i8** %11
%23 = call i32 @perror(i8* %22)
store i32 0, i32* %6
br label %83
24: ; preds = %5
br label %25
25: ; preds = %54, %24
%26 = load i32*, i32** %16
%27 = call i32 @fgetc(i32* %26)
store i32 %27, i32* %13
%28 = load i32, i32* @EOF
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %65
30: ; preds = %25
%31 = load i32, i32* %13
%32 = load i32*, i32** %16
%33 = call i32 @ungetc(i32 %31, i32* %32)
store i32 0, i32* %12
br label %34
34: ; preds = %51, %30
%35 = load i32, i32* %12
%36 = icmp slt i32 %35, 30
br i1 %36, label %37, label %54
37: ; preds = %34
%38 = load i32*, i32** %16
%39 = call i32 @fgetc(i32* %38)
store i32 %39, i32* %13
%40 = icmp eq i32 %39, 10
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* %12
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [31 x i8], [31 x i8]* %15, i64 0, i64 %43
store i8 0, i8* %44
br label %54
45: ; preds = %37
%46 = load i32, i32* %13
%47 = trunc i32 %46 to i8
%48 = load i32, i32* %12
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [31 x i8], [31 x i8]* %15, i64 0, i64 %49
store i8 %47, i8* %50
br label %51
51: ; preds = %45
%52 = load i32, i32* %12
%53 = add nsw i32 %52, 1
store i32 %53, i32* %12
br label %34
54: ; preds = %41, %34
%55 = load [8 x i32]*, [8 x i32]** %7
%56 = bitcast [8 x i32]* %55 to i32**
%57 = load i32*, i32** %8
%58 = load i32*, i32** %9
%59 = getelementptr inbounds [31 x i8], [31 x i8]* %15, i64 0, i64 0
%60 = call i64 @readboard(i32** %56, i32* %57, i32* %58, i8* %59)
%61 = load i32, i32* %14
%62 = sext i32 %61 to i64
%63 = add nsw i64 %62, %60
%64 = trunc i64 %63 to i32
store i32 %64, i32* %14
br label %25
65: ; preds = %25
%66 = load i32, i32* %14
%67 = icmp ne i32 %66, 45
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i8*, i8** %11
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %69)
br label %71
71: ; preds = %68, %65
%72 = getelementptr inbounds [31 x i8], [31 x i8]* %15, i64 0, i64 0
%73 = call i64 @strtol(i8* %72, i8** null, i32 10)
%74 = trunc i64 %73 to i32
%75 = load i32*, i32** %10
store i32 %74, i32* %75
%76 = load i32*, i32** %16
%77 = call i32 @fclose(i32* %76)
%78 = load i8*, i8** %11
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %78)
%80 = load i32*, i32** %10
%81 = load i32, i32* %80
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %81)
store i32 1, i32* %6
br label %83
83: ; preds = %71, %21
%84 = load i32, i32* %6
ret i32 %84
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.1 = [25 x i8] c"\0Agame file %s corrupt ?\0A\00"
@.str.2 = [21 x i8] c"\0Aread from file %s.\0A\00"
@.str.3 = [25 x i8] c"cake maxtime set to %d.\0A\00"
define i32 @loadboard([8 x i32]* %0, i32* %1, i32* %2, i32* nocapture %3, i8* %4) {
%6 = alloca [31 x i8]
%7 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 0
%8 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %16, label %10
10: ; preds = %5
%11 = call i32 @fgetc(i32* %8)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %43, label %14
14: ; preds = %10
%15 = bitcast [8 x i32]* %0 to i32**
br label %18
16: ; preds = %5
%17 = tail call i32 @perror(i8* %4)
br label %52
18: ; preds = %14, %34
%19 = phi i32 [ %11, %14 ], [ %38, %34 ]
%20 = phi i32 [ 0, %14 ], [ %37, %34 ]
%21 = call i32 @ungetc(i32 %19, i32* %8)
br label %22
22: ; preds = %18, %29
%23 = phi i64 [ 0, %18 ], [ %32, %29 ]
%24 = call i32 @fgetc(i32* %8)
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = and i64 %23, 4294967295
%28 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 %27
store i8 0, i8* %28
br label %34
29: ; preds = %22
%30 = trunc i32 %24 to i8
%31 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 %23
store i8 %30, i8* %31
%32 = add nuw nsw i64 %23, 1
%33 = icmp eq i64 %32, 30
br i1 %33, label %34, label %22
34: ; preds = %29, %26
%35 = call i64 @readboard(i32** %15, i32* %1, i32* %2, i8* %7)
%36 = trunc i64 %35 to i32
%37 = add i32 %20, %36
%38 = call i32 @fgetc(i32* %8)
%39 = load i32, i32* @EOF
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %18
41: ; preds = %34
%42 = icmp eq i32 %37, 45
br i1 %42, label %45, label %43
43: ; preds = %10, %41
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %45
45: ; preds = %43, %41
%46 = call i64 @strtol(i8* nocapture %7, i8** null, i32 10)
%47 = trunc i64 %46 to i32
store i32 %47, i32* %3
%48 = call i32 @fclose(i32* %8)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%50 = load i32, i32* %3
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %45, %16
%53 = phi i32 [ 1, %45 ], [ 0, %16 ]
ret i32 %53
}