#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*/ ansiprintboard(int **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
void saveboard(int b[8][8], int view, int color, int maxtime, char *path) {
  FILE *cakegame;
  cakegame = fopen(path, "w");
  if (!cakegame) {
    perror(path);
    return;
  }
  ansiprintboard(b, view, color, cakegame);
  fprintf(cakegame, "%d\n", maxtime);
  fclose(cakegame);
  printf("\nwrote to file %s.\n", path);
}


x86 assembly (clang, -O0):
<saveboard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a6 <saveboard+0x46>
mov    -0x20(%rbp),%rdi
call   1080 <perror@plt>
jmp    11e5 <saveboard+0x85>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x28(%rbp),%rcx
call   1030 <ansiprintboard@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe3b(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rsi
lea    0xe26(%rip),%rdi
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saveboard>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r13
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbx
lea    0xe7f(%rip),%rsi
mov    %r8,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d9 <saveboard+0x79>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %rax,%rcx
call   1030 <ansiprintboard@plt>
lea    0xe59(%rip),%rsi
mov    %rbp,%rdi
mov    %r14d,%edx
call   1060 <fprintf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xe43(%rip),%rdi
mov    %r13,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <perror@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [20 x i8] c"\0Awrote to file %s.\0A\00"
define void @saveboard([8 x i32]* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca [8 x i32]*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
store [8 x i32]* %0, [8 x i32]** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%12 = load i8*, i8** %10
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %11
%14 = load i32*, i32** %11
%15 = icmp ne i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %5
%17 = load i8*, i8** %10
%18 = call i32 @perror(i8* %17)
br label %33
19: ; preds = %5
%20 = load [8 x i32]*, [8 x i32]** %6
%21 = bitcast [8 x i32]* %20 to i32**
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = load i32*, i32** %11
%25 = call i32 @ansiprintboard(i32** %21, i32 %22, i32 %23, i32* %24)
%26 = load i32*, i32** %11
%27 = load i32, i32* %9
%28 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32*, i32** %11
%30 = call i32 @fclose(i32* %29)
%31 = load i8*, i8** %10
%32 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %19, %16
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [20 x i8] c"\0Awrote to file %s.\0A\00"
define void @saveboard([8 x i32]* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @perror(i8* %4)
br label %16
10: ; preds = %5
%11 = bitcast [8 x i32]* %0 to i32**
%12 = tail call i32 @ansiprintboard(i32** %11, i32 %1, i32 %2, i32* %6)
%13 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%14 = tail call i32 @fclose(i32* %6)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %16
16: ; preds = %10, %8
ret void
}