#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
void writeBoardToFile(int board[][9], char *filepath) {
  printf("writing to file: \'%s\'\n", filepath);
  FILE *outputfile = fopen(filepath, "w");
  int row, col;
  for (row = 0; row < 9; row++) {
    for (col = 0; col < 9; col++) {
      fprintf(outputfile, "%d ", board[row][col]);
    }
    fprintf(outputfile, "\n");
  }
  fclose(outputfile);
}


x86 assembly (clang, -O0):
<writeBoardToFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x9,-0x1c(%rbp)
jge    11ec <writeBoardToFile+0xac>
movl   $0x0,-0x20(%rbp)
cmpl   $0x9,-0x20(%rbp)
jge    11cc <writeBoardToFile+0x8c>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x24,%rcx,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118c <writeBoardToFile+0x4c>
mov    -0x18(%rbp),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117b <writeBoardToFile+0x3b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeBoardToFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r12
mov    $0x20,%ebx
lea    0xe91(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    -0x20(%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    -0x1c(%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    -0x18(%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    -0x14(%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    -0x10(%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    -0xc(%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    -0x8(%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    -0x4(%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xa,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
add    $0x24,%rbx
cmp    $0x164,%rbx
jne    1190 <writeBoardToFile+0x40>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"writing to file: '%s'\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @writeBoardToFile([9 x i32]* %0, i8* %1) {
%3 = alloca [9 x i32]*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store [9 x i32]* %0, [9 x i32]** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %5
store i32 0, i32* %6
br label %12
12: ; preds = %36, %2
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 9
br i1 %14, label %15, label %39
15: ; preds = %12
store i32 0, i32* %7
br label %16
16: ; preds = %30, %15
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 9
br i1 %18, label %19, label %33
19: ; preds = %16
%20 = load i32*, i32** %5
%21 = load [9 x i32]*, [9 x i32]** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [9 x i32], [9 x i32]* %21, i64 %23
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [9 x i32], [9 x i32]* %24, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %19
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %16
33: ; preds = %16
%34 = load i32*, i32** %5
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %33
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %12
39: ; preds = %12
%40 = load i32*, i32** %5
%41 = call i32 @fclose(i32* %40)
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"writing to file: '%s'\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d \00"
define void @writeBoardToFile([9 x i32]* nocapture %0, i8* %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %1)
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %2, %5
%6 = phi i64 [ 0, %2 ], [ %35, %5 ]
%7 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %6, i64 0
%8 = load i32, i32* %7
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %6, i64 1
%11 = load i32, i32* %10
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %6, i64 2
%14 = load i32, i32* %13
%15 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %6, i64 3
%17 = load i32, i32* %16
%18 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %6, i64 4
%20 = load i32, i32* %19
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %6, i64 5
%23 = load i32, i32* %22
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %6, i64 6
%26 = load i32, i32* %25
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %6, i64 7
%29 = load i32, i32* %28
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %6, i64 8
%32 = load i32, i32* %31
%33 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = tail call i32 @fputc(i32 10, i32* %4)
%35 = add nuw nsw i64 %6, 1
%36 = icmp eq i64 %35, 9
br i1 %36, label %37, label %5
37: ; preds = %5
%38 = tail call i32 @fclose(i32* %4)
ret void
}