#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 *);
void guardar(int matriz[1024][1024], int *ancho, int *alto) {
  FILE *archivo;
  int x, y, i;
  if (*ancho <= 1024 || *ancho <= 1024) {
    archivo = fopen("imagen.bpm", "w");
    fprintf(archivo, "%s\n", "P2");
    fprintf(archivo, "%d ", *ancho);
    fprintf(archivo, "%d\n", *alto);
    fprintf(archivo, "%d\n", 255);
    for (y = 0; y < *alto; y++) {
      for (x = 0; x < *ancho; x++) {
        if (x % 17 == 0) {
          fprintf(archivo, "\n");
        }
        if (matriz[x][y] < 10) {
          fprintf(archivo, "  %d ", matriz[x][y]);
        } else {
          if (matriz[x][y] < 100) {
            fprintf(archivo, " %d ", matriz[x][y]);
          } else {
            fprintf(archivo, "%d ", matriz[x][y]);
          }
        }
      }
    }
    fclose(archivo);
    printf("\n!Se han guardado los datos con éxito¡ \n");
  } else {
    printf("\nNO SE PUDO GUARDAR\n");
  }
}


x86 assembly (clang, -O0):
<guardar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x400,(%rax)
jle    1174 <guardar+0x34>
mov    -0x10(%rbp),%rax
cmpl   $0x400,(%rax)
jg     133e <guardar+0x1fe>
lea    0xe85(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe77(%rip),%rsi
lea    0xe74(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe35(%rip),%rsi
mov    $0xff,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1324 <guardar+0x1e4>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    1311 <guardar+0x1d1>
mov    -0x24(%rbp),%eax
mov    $0x11,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    123d <guardar+0xfd>
mov    -0x20(%rbp),%rdi
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0xc,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
cmpl   $0xa,(%rax,%rcx,4)
jge    1287 <guardar+0x147>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0xc,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd9d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12fe <guardar+0x1be>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0xc,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
cmpl   $0x64,(%rax,%rcx,4)
jge    12d1 <guardar+0x191>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0xc,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12f9 <guardar+0x1b9>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0xc,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd28(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12fe <guardar+0x1be>
jmp    1303 <guardar+0x1c3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1208 <guardar+0xc8>
jmp    1316 <guardar+0x1d6>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11f2 <guardar+0xb2>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xcea(%rip),%rdi
call   1040 <printf@plt>
jmp    134a <guardar+0x20a>
lea    0xd04(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guardar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmpl   $0x400,(%rsi)
jg     12ad <guardar+0x15d>
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbp
lea    0xe86(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe7d(%rip),%rsi
lea    0xe7a(%rip),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r12),%edx
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%edx
lea    0xe54(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%ecx
test   %ecx,%ecx
jle    12b6 <guardar+0x166>
mov    (%r12),%eax
lea    0xe24(%rip),%r14
xor    %esi,%esi
mov    %r15,(%rsp)
jmp    1225 <guardar+0xd5>
nopl   (%rax)
mov    (%rsp),%r15
mov    (%r15),%ecx
mov    0x10(%rsp),%rbp
mov    0x8(%rsp),%rsi
add    $0x1,%rsi
movslq %ecx,%rdx
add    $0x4,%rbp
cmp    %rdx,%rsi
jge    12b6 <guardar+0x166>
test   %eax,%eax
jle    1211 <guardar+0xc1>
mov    %rsi,0x8(%rsp)
xor    %r15d,%r15d
mov    %rbp,0x10(%rsp)
xor    %r13d,%r13d
jmp    1270 <guardar+0x120>
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%edx
lea    0xdce(%rip),%rax
cmovl  %rax,%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%r13
movslq (%r12),%rax
add    $0xffffffff,%r15d
add    $0x1000,%rbp
cmp    %rax,%r13
jge    1200 <guardar+0xb0>
mov    %r13d,%eax
mov    $0xf0f0f0f1,%ecx
imul   %rcx,%rax
shr    $0x24,%rax
mov    %eax,%ecx
shl    $0x4,%ecx
add    %eax,%ecx
add    %r15d,%ecx
jne    1299 <guardar+0x149>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    0x0(%rbp),%edx
mov    %r14,%rsi
cmp    $0x64,%edx
jb     1240 <guardar+0xf0>
lea    0xd6f(%rip),%rsi
jmp    1240 <guardar+0xf0>
lea    0xd6a(%rip),%rdi
jmp    12c5 <guardar+0x175>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xd6d(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"imagen.bpm\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c"P2\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [4 x i8] c"%d\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [6 x i8] c" %d \00"
@.str.8 = [5 x i8] c" %d \00"
@.str.9 = [43 x i8] c"\0A!Se han guardado los datos con \C3\A9xito\C2\A1 \0A\00"
@.str.10 = [21 x i8] c"\0ANO SE PUDO GUARDAR\0A\00"
define void @guardar([1024 x i32]* %0, i32* %1, i32* %2) {
%4 = alloca [1024 x i32]*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store [1024 x i32]* %0, [1024 x i32]** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%11 = load i32*, i32** %5
%12 = load i32, i32* %11
%13 = icmp sle i32 %12, 1024
br i1 %13, label %18, label %14
14: ; preds = %3
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = icmp sle i32 %16, 1024
br i1 %17, label %18, label %116
18: ; preds = %14, %3
%19 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %7
%20 = load i32*, i32** %7
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32*, i32** %7
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = load i32*, i32** %7
%27 = load i32*, i32** %6
%28 = load i32, i32* %27
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = load i32*, i32** %7
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 255)
store i32 0, i32* %9
br label %32
32: ; preds = %109, %18
%33 = load i32, i32* %9
%34 = load i32*, i32** %6
%35 = load i32, i32* %34
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %112
37: ; preds = %32
store i32 0, i32* %8
br label %38
38: ; preds = %105, %37
%39 = load i32, i32* %8
%40 = load i32*, i32** %5
%41 = load i32, i32* %40
%42 = icmp slt i32 %39, %41
br i1 %42, label %43, label %108
43: ; preds = %38
%44 = load i32, i32* %8
%45 = srem i32 %44, 17
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32*, i32** %7
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %50
50: ; preds = %47, %43
%51 = load [1024 x i32]*, [1024 x i32]** %4
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [1024 x i32], [1024 x i32]* %51, i64 %53
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [1024 x i32], [1024 x i32]* %54, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = icmp slt i32 %58, 10
br i1 %59, label %60, label %71
60: ; preds = %50
%61 = load i32*, i32** %7
%62 = load [1024 x i32]*, [1024 x i32]** %4
%63 = load i32, i32* %8
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [1024 x i32], [1024 x i32]* %62, i64 %64
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [1024 x i32], [1024 x i32]* %65, i64 0, i64 %67
%69 = load i32, i32* %68
%70 = call i32 (i32*, i8*, ...) @fprintf(i32* %61, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %69)
br label %104
71: ; preds = %50
%72 = load [1024 x i32]*, [1024 x i32]** %4
%73 = load i32, i32* %8
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [1024 x i32], [1024 x i32]* %72, i64 %74
%76 = load i32, i32* %9
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [1024 x i32], [1024 x i32]* %75, i64 0, i64 %77
%79 = load i32, i32* %78
%80 = icmp slt i32 %79, 100
br i1 %80, label %81, label %92
81: ; preds = %71
%82 = load i32*, i32** %7
%83 = load [1024 x i32]*, [1024 x i32]** %4
%84 = load i32, i32* %8
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [1024 x i32], [1024 x i32]* %83, i64 %85
%87 = load i32, i32* %9
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [1024 x i32], [1024 x i32]* %86, i64 0, i64 %88
%90 = load i32, i32* %89
%91 = call i32 (i32*, i8*, ...) @fprintf(i32* %82, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 %90)
br label %103
92: ; preds = %71
%93 = load i32*, i32** %7
%94 = load [1024 x i32]*, [1024 x i32]** %4
%95 = load i32, i32* %8
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [1024 x i32], [1024 x i32]* %94, i64 %96
%98 = load i32, i32* %9
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [1024 x i32], [1024 x i32]* %97, i64 0, i64 %99
%101 = load i32, i32* %100
%102 = call i32 (i32*, i8*, ...) @fprintf(i32* %93, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %101)
br label %103
103: ; preds = %92, %81
br label %104
104: ; preds = %103, %60
br label %105
105: ; preds = %104
%106 = load i32, i32* %8
%107 = add nsw i32 %106, 1
store i32 %107, i32* %8
br label %38
108: ; preds = %38
br label %109
109: ; preds = %108
%110 = load i32, i32* %9
%111 = add nsw i32 %110, 1
store i32 %111, i32* %9
br label %32
112: ; preds = %32
%113 = load i32*, i32** %7
%114 = call i32 @fclose(i32* %113)
%115 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0))
br label %118
116: ; preds = %14
%117 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
br label %118
118: ; preds = %116, %112
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"imagen.bpm\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c"P2\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [4 x i8] c"%d\0A\00"
@.str.7 = [6 x i8] c" %d \00"
@.str.8 = [5 x i8] c" %d \00"
@str = [20 x i8] c"\0ANO SE PUDO GUARDAR\00"
@str.11 = [42 x i8] c"\0A!Se han guardado los datos con \C3\A9xito\C2\A1 \00"
define void @guardar([1024 x i32]* nocapture %0, i32* nocapture %1, i32* nocapture %2) {
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 1025
br i1 %5, label %6, label %52
6: ; preds = %3
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%9 = load i32, i32* %1
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %2
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %11)
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 255)
%14 = load i32, i32* %2
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %50
16: ; preds = %6
%17 = load i32, i32* %1
br label %18
18: ; preds = %16, %44
%19 = phi i32 [ %14, %16 ], [ %45, %44 ]
%20 = phi i32 [ %17, %16 ], [ %46, %44 ]
%21 = phi i64 [ 0, %16 ], [ %47, %44 ]
%22 = icmp sgt i32 %20, 0
br i1 %22, label %23, label %44
23: ; preds = %18, %30
%24 = phi i64 [ %38, %30 ], [ 0, %18 ]
%25 = trunc i64 %24 to i32
%26 = urem i32 %25, 17
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = tail call i32 @fputc(i32 10, i32* %7)
br label %30
30: ; preds = %28, %23
%31 = getelementptr inbounds [1024 x i32], [1024 x i32]* %0, i64 %24, i64 %21
%32 = load i32, i32* %31
%33 = icmp slt i32 %32, 10
%34 = icmp ult i32 %32, 100
%35 = select i1 %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
%36 = select i1 %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %35
%37 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* %36, i32 %32)
%38 = add nuw nsw i64 %24, 1
%39 = load i32, i32* %1
%40 = sext i32 %39 to i64
%41 = icmp slt i64 %38, %40
br i1 %41, label %23, label %42
42: ; preds = %30
%43 = load i32, i32* %2
br label %44
44: ; preds = %42, %18
%45 = phi i32 [ %43, %42 ], [ %19, %18 ]
%46 = phi i32 [ %39, %42 ], [ %20, %18 ]
%47 = add nuw nsw i64 %21, 1
%48 = sext i32 %45 to i64
%49 = icmp slt i64 %47, %48
br i1 %49, label %18, label %50
50: ; preds = %44, %6
%51 = tail call i32 @fclose(i32* %7)
br label %52
52: ; preds = %3, %50
%53 = phi i8* [ getelementptr inbounds ([42 x i8], [42 x i8]* @str.11, i64 0, i64 0), %50 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0), %3 ]
%54 = tail call i32 @puts(i8* dereferenceable(1) %53)
ret void
}