#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*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char const *);
void print_board_file(unsigned char **board, unsigned int rows,
                      unsigned int cols, int n, const char *filename) {
  char newFilename[50];
  int numLength = 1;
  if (n >= 10 && n <= 99) {
    numLength = 2;
  } else if (n >= 100 && n <= 999) {
    numLength = 3;
  }
  char str[numLength];
  sprintf(str, "%d", n);
  newFilename[0] = '\0';
  strcat(newFilename, "output/");
  strcat(newFilename, filename);
  strcat(newFilename, "_");
  strcat(newFilename, str);
  FILE *file = fopen(newFilename, "w+");
  fprintf(file, "Simulacion N°: %i\n", n);
  unsigned int i, j;
  for (i = 0; i < cols; i++) {
    for (j = 0; j < rows; j++) {
      if (board[i][j] == '0') {
        fprintf(file, "·");
      } else {
        fprintf(file, "O");
      }
    }
    fprintf(file, "\n");
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<print_board_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x1,-0x64(%rbp)
cmpl   $0xa,-0x14(%rbp)
jl     1193 <print_board_file+0x43>
cmpl   $0x63,-0x14(%rbp)
jg     1193 <print_board_file+0x43>
movl   $0x2,-0x64(%rbp)
jmp    11b6 <print_board_file+0x66>
cmpl   $0x64,-0x14(%rbp)
jl     11b1 <print_board_file+0x61>
cmpl   $0x3e7,-0x14(%rbp)
jg     11b1 <print_board_file+0x61>
movl   $0x3,-0x64(%rbp)
jmp    11b6 <print_board_file+0x66>
mov    -0x64(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x90(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x78(%rbp)
mov    -0x14(%rbp),%edx
lea    0xe17(%rip),%rsi
call   1070 <sprintf@plt>
movb   $0x0,-0x60(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcat@plt>
lea    -0x60(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x90(%rbp),%rsi
lea    -0x60(%rbp),%rdi
call   1060 <strcat@plt>
lea    -0x60(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    1313 <print_board_file+0x1c3>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    12ed <print_board_file+0x19d>
mov    -0x8(%rbp),%rax
mov    -0x84(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    -0x88(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jne    12c2 <print_board_file+0x172>
mov    -0x80(%rbp),%rdi
lea    0xd6e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12d4 <print_board_file+0x184>
mov    -0x80(%rbp),%rdi
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12d9 <print_board_file+0x189>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    127b <print_board_file+0x12b>
mov    -0x80(%rbp),%rdi
lea    0xd2a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1262 <print_board_file+0x112>
mov    -0x80(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x70(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_board_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8,-0x38(%rbp)
mov    %ecx,%r12d
mov    %edx,%r14d
mov    %esi,-0x2c(%rbp)
mov    %rdi,%r13
mov    %rsp,-0x40(%rbp)
lea    -0x64(%r12),%eax
xor    %ecx,%ecx
cmp    $0x384,%eax
lea    -0xa(%r12),%eax
setb   %cl
cmp    $0x5a,%eax
lea    0x1(%rcx,%rcx,1),%eax
mov    $0x2,%ecx
cmovae %eax,%ecx
add    $0xf,%ecx
and    $0x10,%ecx
mov    %rsp,%r15
sub    %rcx,%r15
mov    %r15,%rsp
lea    0xe32(%rip),%rsi
mov    %r15,%rdi
mov    %r12d,%edx
call   1080 <sprintf@plt>
movb   $0x0,-0x80(%rbp)
lea    0xe1f(%rip),%rsi
lea    -0x80(%rbp),%rbx
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    -0x38(%rbp),%rsi
call   1070 <strcat@plt>
lea    0xe08(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
lea    0xdf0(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xde1(%rip),%rsi
mov    %rax,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r14d,%r14d
je     12cd <print_board_file+0x15d>
mov    %r14d,%eax
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%r14d
xor    %r12d,%r12d
jmp    1277 <print_board_file+0x107>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x1,%r12
cmp    -0x38(%rbp),%r12
je     12cd <print_board_file+0x15d>
cmpl   $0x0,-0x2c(%rbp)
je     1260 <print_board_file+0xf0>
xor    %r15d,%r15d
jmp    12a6 <print_board_file+0x136>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x4f,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x1,%r15
cmp    %r15,%r14
je     1260 <print_board_file+0xf0>
mov    0x0(%r13,%r12,8),%rax
cmpb   $0x30,(%rax,%r15,1)
jne    1290 <print_board_file+0x120>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xd61(%rip),%rdi
mov    %rbx,%rcx
call   1090 <fwrite@plt>
jmp    129d <print_board_file+0x12d>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    -0x40(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [8 x i8] c"output/\00"
@.str.2 = [2 x i8] c"_\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [20 x i8] c"Simulacion N\C2\B0: %i\0A\00"
@.str.5 = [3 x i8] c"\C2\B7\00"
@.str.6 = [2 x i8] c"O\00"
@.str.7 = [2 x i8] c"\0A\00"
define void @print_board_file(i8** %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [50 x i8]
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
store i8** %0, i8*** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
store i32 1, i32* %12
%18 = load i32, i32* %9
%19 = icmp sge i32 %18, 10
br i1 %19, label %20, label %24
20: ; preds = %5
%21 = load i32, i32* %9
%22 = icmp sle i32 %21, 99
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 2, i32* %12
br label %32
24: ; preds = %20, %5
%25 = load i32, i32* %9
%26 = icmp sge i32 %25, 100
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* %9
%29 = icmp sle i32 %28, 999
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 3, i32* %12
br label %31
31: ; preds = %30, %27, %24
br label %32
32: ; preds = %31, %23
%33 = load i32, i32* %12
%34 = zext i32 %33 to i64
%35 = call i8* @llvm.stacksave()
store i8* %35, i8** %13
%36 = alloca i8, i64 %34
store i64 %34, i64* %14
%37 = load i32, i32* %9
%38 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
store i8 0, i8* %39
%40 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%41 = call i32 @strcat(i8* %40, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%42 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%43 = load i8*, i8** %10
%44 = call i32 @strcat(i8* %42, i8* %43)
%45 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%46 = call i32 @strcat(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%47 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%48 = call i32 @strcat(i8* %47, i8* %36)
%49 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %50, i32** %15
%51 = load i32*, i32** %15
%52 = load i32, i32* %9
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %52)
store i32 0, i32* %16
br label %54
54: ; preds = %88, %32
%55 = load i32, i32* %16
%56 = load i32, i32* %8
%57 = icmp ult i32 %55, %56
br i1 %57, label %58, label %91
58: ; preds = %54
store i32 0, i32* %17
br label %59
59: ; preds = %82, %58
%60 = load i32, i32* %17
%61 = load i32, i32* %7
%62 = icmp ult i32 %60, %61
br i1 %62, label %63, label %85
63: ; preds = %59
%64 = load i8**, i8*** %6
%65 = load i32, i32* %16
%66 = zext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
%68 = load i8*, i8** %67
%69 = load i32, i32* %17
%70 = zext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = icmp eq i32 %73, 48
br i1 %74, label %75, label %78
75: ; preds = %63
%76 = load i32*, i32** %15
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %81
78: ; preds = %63
%79 = load i32*, i32** %15
%80 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %81
81: ; preds = %78, %75
br label %82
82: ; preds = %81
%83 = load i32, i32* %17
%84 = add i32 %83, 1
store i32 %84, i32* %17
br label %59
85: ; preds = %59
%86 = load i32*, i32** %15
%87 = call i32 (i32*, i8*, ...) @fprintf(i32* %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %88
88: ; preds = %85
%89 = load i32, i32* %16
%90 = add i32 %89, 1
store i32 %90, i32* %16
br label %54
91: ; preds = %54
%92 = load i32*, i32** %15
%93 = call i32 @fclose(i32* %92)
%94 = load i8*, i8** %13
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [8 x i8] c"output/\00"
@.str.2 = [2 x i8] c"_\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [20 x i8] c"Simulacion N\C2\B0: %i\0A\00"
@.str.5 = [3 x i8] c"\C2\B7\00"
define void @print_board_file(i8** nocapture %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca [50 x i8]
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%8 = add i32 %3, -10
%9 = icmp ult i32 %8, 90
%10 = add i32 %3, -100
%11 = icmp ult i32 %10, 900
%12 = select i1 %11, i64 3, i64 1
%13 = select i1 %9, i64 2, i64 %12
%14 = tail call i8* @llvm.stacksave()
%15 = alloca i8, i64 %13
%16 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %3)
store i8 0, i8* %7
%17 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @strcat(i8* %7, i8* %4)
%19 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @strcat(i8* %7, i8* %15)
%21 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %3)
%23 = icmp eq i32 %2, 0
br i1 %23, label %49, label %24
24: ; preds = %5
%25 = icmp eq i32 %1, 0
%26 = zext i32 %2 to i64
%27 = zext i32 %1 to i64
br label %28
28: ; preds = %24, %45
%29 = phi i64 [ 0, %24 ], [ %47, %45 ]
br i1 %25, label %45, label %30
30: ; preds = %28
%31 = getelementptr inbounds i8*, i8** %0, i64 %29
br label %32
32: ; preds = %30, %42
%33 = phi i64 [ 0, %30 ], [ %43, %42 ]
%34 = load i8*, i8** %31
%35 = getelementptr inbounds i8, i8* %34, i64 %33
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 48
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 2, i64 1, i32* %21)
br label %42
40: ; preds = %32
%41 = call i32 @fputc(i32 79, i32* %21)
br label %42
42: ; preds = %38, %40
%43 = add nuw nsw i64 %33, 1
%44 = icmp eq i64 %43, %27
br i1 %44, label %45, label %32
45: ; preds = %42, %28
%46 = call i32 @fputc(i32 10, i32* %21)
%47 = add nuw nsw i64 %29, 1
%48 = icmp eq i64 %47, %26
br i1 %48, label %49, label %28
49: ; preds = %45, %5
%50 = call i32 @fclose(i32* %21)
ret void
}