#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char const *);
void writePBM(unsigned char **board, unsigned int dimx, unsigned int dimy,
              const char *fileName, unsigned int actionNumber) {
  int i, j;
  int actionNumberStringLenght = 1;
  if (actionNumber >= 10) {
    actionNumberStringLenght = 2;
  }
  char str[actionNumberStringLenght];
  sprintf(str, "%d", actionNumber);
  char newFileName[50];
  newFileName[0] = '\0';
  strcat(newFileName, "imagenes/");
  strcat(newFileName, fileName);
  strcat(newFileName, "_");
  strcat(newFileName, str);
  strcat(newFileName, ".pbm");
  FILE *fp = fopen(newFileName, "wb");
  if (fp == NULL) {
    fprintf(stderr, "Error while opening output file: %s\n", newFileName);
    exit(1);
  }
  unsigned int amp = 1;
  (void)fprintf(fp, "P4\n%d %d\n", dimy * amp, dimx * amp);
  for (j = 0; j < dimy; ++j) {
    for (i = 0; i < dimx; ++i) {
      unsigned int x, y;
      unsigned char writeValue = 0;
      if ((board[i][j]) == '1') {
        writeValue = 1;
      }
      for (x = i * amp; x < amp * (i + 1); x++) {
        for (y = j * amp; y < amp * (j + 1); y++) {
          fprintf(fp, "%c", writeValue);
        }
      }
    }
  }
  (void)fclose(fp);
  return;
}


x86 assembly (clang, -O0):
<writePBM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movl   $0x1,-0x28(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jb     1195 <writePBM+0x35>
movl   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%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,-0x38(%rbp)
mov    -0x1c(%rbp),%edx
lea    0xe38(%rip),%rsi
call   1070 <sprintf@plt>
movb   $0x0,-0x70(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
lea    -0x70(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x90(%rbp),%rsi
lea    -0x70(%rbp),%rdi
call   1060 <strcat@plt>
lea    -0x70(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x70(%rbp),%rdi
lea    0xdeb(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    1263 <writePBM+0x103>
mov    0x2d9c(%rip),%rax
movslq (%rax),%rdi
lea    -0x70(%rbp),%rdx
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x1,-0x7c(%rbp)
mov    -0x78(%rbp),%rdi
mov    -0x10(%rbp),%edx
imul   -0x7c(%rbp),%edx
mov    -0xc(%rbp),%ecx
imul   -0x7c(%rbp),%ecx
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    1389 <writePBM+0x229>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1376 <writePBM+0x216>
movb   $0x0,-0x85(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
jne    12db <writePBM+0x17b>
movb   $0x1,-0x85(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x7c(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%eax
mov    -0x7c(%rbp),%ecx
mov    -0x20(%rbp),%edx
add    $0x1,%edx
imul   %edx,%ecx
cmp    %ecx,%eax
jae    1363 <writePBM+0x203>
mov    -0x24(%rbp),%eax
imul   -0x7c(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    -0x7c(%rbp),%ecx
mov    -0x24(%rbp),%edx
add    $0x1,%edx
imul   %edx,%ecx
cmp    %ecx,%eax
jae    1350 <writePBM+0x1f0>
mov    -0x78(%rbp),%rdi
movzbl -0x85(%rbp),%edx
lea    0xd11(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1309 <writePBM+0x1a9>
jmp    1355 <writePBM+0x1f5>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    12e5 <writePBM+0x185>
jmp    1368 <writePBM+0x208>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12a4 <writePBM+0x144>
jmp    137b <writePBM+0x21b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1291 <writePBM+0x131>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writePBM>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,%r15
mov    %edx,-0x30(%rbp)
mov    %esi,%r14d
mov    %rdi,%r12
lea    -0x10(%rsp),%rbx
mov    %rbx,%rsp
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
mov    %r8d,%edx
call   1080 <sprintf@plt>
movb   $0x0,-0x70(%rbp)
lea    0xe51(%rip),%rsi
lea    -0x70(%rbp),%r13
mov    %r13,%rdi
call   1070 <strcat@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
lea    0xe3d(%rip),%rsi
mov    %r13,%rdi
call   1070 <strcat@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <strcat@plt>
lea    0xe25(%rip),%rsi
mov    %r13,%rdi
call   1070 <strcat@plt>
lea    0xe1b(%rip),%rsi
mov    %r13,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1299 <writePBM+0x129>
mov    %rax,%r13
lea    0xe28(%rip),%rsi
mov    %rax,%rdi
mov    -0x30(%rbp),%ebx
mov    %ebx,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %ebx,%ebx
je     1282 <writePBM+0x112>
mov    %r14d,%eax
mov    %ebx,%ecx
mov    %rcx,-0x30(%rbp)
mov    %r14d,%ebx
xor    %r14d,%r14d
mov    %eax,-0x34(%rbp)
jmp    124d <writePBM+0xdd>
xchg   %ax,%ax
add    $0x1,%r14
cmp    -0x30(%rbp),%r14
mov    -0x34(%rbp),%eax
je     1282 <writePBM+0x112>
test   %eax,%eax
je     1240 <writePBM+0xd0>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%r15,8),%rax
xor    %edi,%edi
cmpb   $0x31,(%rax,%r14,1)
sete   %dil
mov    %r13,%rsi
call   1040 <fputc@plt>
add    $0x1,%r15
cmp    %r15,%rbx
jne    1260 <writePBM+0xf0>
jmp    1240 <writePBM+0xd0>
mov    %r13,%rdi
call   1030 <fclose@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d40(%rip),%rax
movslq (%rax),%rdi
lea    0xd6d(%rip),%rsi
lea    -0x70(%rbp),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"imagenes/\00"
@.str.2 = [2 x i8] c"_\00"
@.str.3 = [5 x i8] c".pbm\00"
@.str.4 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.5 = [37 x i8] c"Error while opening output file: %s\0A\00"
@.str.6 = [10 x i8] c"P4\0A%d %d\0A\00"
@.str.7 = [3 x i8] c"%c\00"
define void @writePBM(i8** %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
%16 = alloca [50 x i8]
%17 = alloca i32*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i8
store i8** %0, i8*** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
store i32 1, i32* %13
%22 = load i32, i32* %10
%23 = icmp uge i32 %22, 10
br i1 %23, label %24, label %25
24: ; preds = %5
store i32 2, i32* %13
br label %25
25: ; preds = %24, %5
%26 = load i32, i32* %13
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %14
%29 = alloca i8, i64 %27
store i64 %27, i64* %15
%30 = load i32, i32* %10
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %16, i64 0, i64 0
store i8 0, i8* %32
%33 = getelementptr inbounds [50 x i8], [50 x i8]* %16, i64 0, i64 0
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%35 = getelementptr inbounds [50 x i8], [50 x i8]* %16, i64 0, i64 0
%36 = load i8*, i8** %9
%37 = call i32 @strcat(i8* %35, i8* %36)
%38 = getelementptr inbounds [50 x i8], [50 x i8]* %16, i64 0, i64 0
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = getelementptr inbounds [50 x i8], [50 x i8]* %16, i64 0, i64 0
%41 = call i32 @strcat(i8* %40, i8* %29)
%42 = getelementptr inbounds [50 x i8], [50 x i8]* %16, i64 0, i64 0
%43 = call i32 @strcat(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%44 = getelementptr inbounds [50 x i8], [50 x i8]* %16, i64 0, i64 0
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %45, i32** %17
%46 = load i32*, i32** %17
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %55
48: ; preds = %25
%49 = load i32, i32* @stderr
%50 = sext i32 %49 to i64
%51 = inttoptr i64 %50 to i32*
%52 = getelementptr inbounds [50 x i8], [50 x i8]* %16, i64 0, i64 0
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %25
store i32 1, i32* %18
%56 = load i32*, i32** %17
%57 = load i32, i32* %8
%58 = load i32, i32* %18
%59 = mul i32 %57, %58
%60 = load i32, i32* %7
%61 = load i32, i32* %18
%62 = mul i32 %60, %61
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %59, i32 %62)
store i32 0, i32* %12
br label %64
64: ; preds = %125, %55
%65 = load i32, i32* %12
%66 = load i32, i32* %8
%67 = icmp ult i32 %65, %66
br i1 %67, label %68, label %128
68: ; preds = %64
store i32 0, i32* %11
br label %69
69: ; preds = %121, %68
%70 = load i32, i32* %11
%71 = load i32, i32* %7
%72 = icmp ult i32 %70, %71
br i1 %72, label %73, label %124
73: ; preds = %69
store i8 0, i8* %21
%74 = load i8**, i8*** %6
%75 = load i32, i32* %11
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %74, i64 %76
%78 = load i8*, i8** %77
%79 = load i32, i32* %12
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = load i8, i8* %81
%83 = zext i8 %82 to i32
%84 = icmp eq i32 %83, 49
br i1 %84, label %85, label %86
85: ; preds = %73
store i8 1, i8* %21
br label %86
86: ; preds = %85, %73
%87 = load i32, i32* %11
%88 = load i32, i32* %18
%89 = mul i32 %87, %88
store i32 %89, i32* %19
br label %90
90: ; preds = %117, %86
%91 = load i32, i32* %19
%92 = load i32, i32* %18
%93 = load i32, i32* %11
%94 = add nsw i32 %93, 1
%95 = mul i32 %92, %94
%96 = icmp ult i32 %91, %95
br i1 %96, label %97, label %120
97: ; preds = %90
%98 = load i32, i32* %12
%99 = load i32, i32* %18
%100 = mul i32 %98, %99
store i32 %100, i32* %20
br label %101
101: ; preds = %113, %97
%102 = load i32, i32* %20
%103 = load i32, i32* %18
%104 = load i32, i32* %12
%105 = add nsw i32 %104, 1
%106 = mul i32 %103, %105
%107 = icmp ult i32 %102, %106
br i1 %107, label %108, label %116
108: ; preds = %101
%109 = load i32*, i32** %17
%110 = load i8, i8* %21
%111 = zext i8 %110 to i32
%112 = call i32 (i32*, i8*, ...) @fprintf(i32* %109, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %111)
br label %113
113: ; preds = %108
%114 = load i32, i32* %20
%115 = add i32 %114, 1
store i32 %115, i32* %20
br label %101
116: ; preds = %101
br label %117
117: ; preds = %116
%118 = load i32, i32* %19
%119 = add i32 %118, 1
store i32 %119, i32* %19
br label %90
120: ; preds = %90
br label %121
121: ; preds = %120
%122 = load i32, i32* %11
%123 = add nsw i32 %122, 1
store i32 %123, i32* %11
br label %69
124: ; preds = %69
br label %125
125: ; preds = %124
%126 = load i32, i32* %12
%127 = add nsw i32 %126, 1
store i32 %127, i32* %12
br label %64
128: ; preds = %64
%129 = load i32*, i32** %17
%130 = call i32 @fclose(i32* %129)
%131 = load i8*, i8** %14
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"imagenes/\00"
@.str.2 = [2 x i8] c"_\00"
@.str.3 = [5 x i8] c".pbm\00"
@.str.4 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.5 = [37 x i8] c"Error while opening output file: %s\0A\00"
@.str.6 = [10 x i8] c"P4\0A%d %d\0A\00"
define void @writePBM(i8** nocapture %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca [50 x i8]
%7 = icmp ugt i32 %4, 9
%8 = select i1 %7, i64 2, i64 1
%9 = alloca i8, i64 %8
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %4)
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
store i8 0, i8* %11
%12 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @strcat(i8* %11, i8* %3)
%14 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @strcat(i8* %11, i8* %9)
%16 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %25
19: ; preds = %5
%20 = load i32, i32* @stderr
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i32*
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %11)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %5
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %2, i32 %1)
%27 = icmp eq i32 %2, 0
br i1 %27, label %48, label %28
28: ; preds = %25
%29 = icmp eq i32 %1, 0
%30 = zext i32 %2 to i64
%31 = zext i32 %1 to i64
br label %32
32: ; preds = %28, %45
%33 = phi i64 [ 0, %28 ], [ %46, %45 ]
br i1 %29, label %45, label %34
34: ; preds = %32, %34
%35 = phi i64 [ %43, %34 ], [ 0, %32 ]
%36 = getelementptr inbounds i8*, i8** %0, i64 %35
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i64 %33
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 49
%41 = zext i1 %40 to i32
%42 = call i32 @fputc(i32 %41, i32* %17)
%43 = add nuw nsw i64 %35, 1
%44 = icmp eq i64 %43, %31
br i1 %44, label %45, label %34
45: ; preds = %34, %32
%46 = add nuw nsw i64 %33, 1
%47 = icmp eq i64 %46, %30
br i1 %47, label %48, label %32
48: ; preds = %45, %25
%49 = call i32 @fclose(i32* %17)
ret void
}