#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);
int /*<<< orphan*/ printf(char *, char *);
char *strchr(char *, char);
int salvaArquivo(char caminho[], int **matriz, int linhas, int colunas) {
  FILE *f = NULL;
  f = fopen(caminho, "w");
  if (!f) {
    return 0;
  }
  fprintf(f, "%d\n", linhas);
  fprintf(f, "%d\n", colunas);
  int i, j;
  for (i = 0; i < linhas; i++) {
    for (j = 0; j < colunas; j++) {
      fprintf(f, "%d\n", matriz[i][j]);
    }
  }
  fclose(f);
  char *quebra = strchr(caminho, '\n');
  if (quebra)
    *quebra = '\0';
  printf("\n%s escrito com sucesso.\n", caminho);
  return 1;
}


x86 assembly (clang, -O0):
<salvaArquivo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1199 <salvaArquivo+0x49>
movl   $0x0,-0x4(%rbp)
jmp    126d <salvaArquivo+0x11d>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe5b(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xe48(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1229 <salvaArquivo+0xd9>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1216 <salvaArquivo+0xc6>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdff(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11d9 <salvaArquivo+0x89>
jmp    121b <salvaArquivo+0xcb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c6 <salvaArquivo+0x76>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1256 <salvaArquivo+0x106>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rsi
lea    0xda5(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<salvaArquivo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1246 <salvaArquivo+0xf6>
mov    %rax,%rbp
mov    %r14,0x8(%rsp)
mov    %r15d,0x4(%rsp)
lea    0xe6f(%rip),%r13
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1060 <fprintf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    0x4(%rsp),%r13d
mov    %r13d,%edx
call   1060 <fprintf@plt>
test   %r12d,%r12d
jle    120e <salvaArquivo+0xbe>
mov    %r12d,%eax
mov    %rax,0x10(%rsp)
mov    %r13d,%r14d
xor    %r15d,%r15d
lea    0xe34(%rip),%r12
jmp    11e0 <salvaArquivo+0x90>
add    $0x1,%r15
cmp    0x10(%rsp),%r15
mov    0x4(%rsp),%r13d
je     120e <salvaArquivo+0xbe>
test   %r13d,%r13d
jle    11d0 <salvaArquivo+0x80>
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%r15,8),%rax
mov    (%rax,%r13,4),%edx
mov    %rbp,%rdi
mov    %r12,%rsi
call   1060 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%r14
jne    11f0 <salvaArquivo+0xa0>
jmp    11d0 <salvaArquivo+0x80>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1230 <salvaArquivo+0xe0>
movb   $0x0,(%rax)
lea    0xdcf(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    1248 <salvaArquivo+0xf8>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [26 x i8] c"\0A%s escrito com sucesso.\0A\00"
define i32 @salvaArquivo(i8* %0, i32** %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %6
store i32** %1, i32*** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32* null, i32** %10
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %10
%16 = load i32*, i32** %10
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %4
store i32 0, i32* %5
br label %66
19: ; preds = %4
%20 = load i32*, i32** %10
%21 = load i32, i32* %8
%22 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32*, i32** %10
%24 = load i32, i32* %9
%25 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %24)
store i32 0, i32* %11
br label %26
26: ; preds = %51, %19
%27 = load i32, i32* %11
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %54
30: ; preds = %26
store i32 0, i32* %12
br label %31
31: ; preds = %47, %30
%32 = load i32, i32* %12
%33 = load i32, i32* %9
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load i32*, i32** %10
%37 = load i32**, i32*** %7
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32*, i32** %37, i64 %39
%41 = load i32*, i32** %40
%42 = load i32, i32* %12
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %35
%48 = load i32, i32* %12
%49 = add nsw i32 %48, 1
store i32 %49, i32* %12
br label %31
50: ; preds = %31
br label %51
51: ; preds = %50
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 1
store i32 %53, i32* %11
br label %26
54: ; preds = %26
%55 = load i32*, i32** %10
%56 = call i32 @fclose(i32* %55)
%57 = load i8*, i8** %6
%58 = call i8* @strchr(i8* %57, i8 signext 10)
store i8* %58, i8** %13
%59 = load i8*, i8** %13
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %63
61: ; preds = %54
%62 = load i8*, i8** %13
store i8 0, i8* %62
br label %63
63: ; preds = %61, %54
%64 = load i8*, i8** %6
%65 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %64)
store i32 1, i32* %5
br label %66
66: ; preds = %63, %18
%67 = load i32, i32* %5
ret i32 %67
}

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