#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 */
scalar_t__ alocaMatriz(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int **carregaArquivo(char caminho[], int *linhas, int *colunas) {
  FILE *f = NULL;
  f = fopen(caminho, "r");
  if (!f) {
    return NULL;
  }
  fscanf(f, "%d", linhas);
  fscanf(f, "%d", colunas);
  int **matriz;
  matriz = (int **)alocaMatriz(*linhas, *colunas);
  if (!matriz) {
    return NULL;
  }
  int i, j;
  for (i = 0; i < *linhas; i++) {
    for (j = 0; j < *colunas; j++) {
      fscanf(f, "%d", &matriz[i][j]);
    }
  }
  fclose(f);
  return matriz;
}


x86 assembly (clang, -O0):
<carregaArquivo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1188 <carregaArquivo+0x48>
movq   $0x0,-0x8(%rbp)
jmp    1262 <carregaArquivo+0x122>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe6b(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe57(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1040 <alocaMatriz@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11dd <carregaArquivo+0x9d>
movq   $0x0,-0x8(%rbp)
jmp    1262 <carregaArquivo+0x122>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1251 <carregaArquivo+0x111>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    123e <carregaArquivo+0xfe>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x38(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xdd7(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11fa <carregaArquivo+0xba>
jmp    1243 <carregaArquivo+0x103>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e4 <carregaArquivo+0xa4>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<carregaArquivo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1232 <carregaArquivo+0xf2>
mov    %rax,%rbp
lea    0xe8f(%rip),%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <fscanf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
mov    (%r14),%edi
mov    (%r15),%esi
call   1040 <alocaMatriz@plt>
test   %rax,%rax
je     1232 <carregaArquivo+0xf2>
mov    %rax,0x8(%rsp)
mov    %rbp,0x10(%rsp)
mov    %r15,0x18(%rsp)
mov    (%r14),%ecx
test   %ecx,%ecx
jle    1236 <carregaArquivo+0xf6>
mov    0x18(%rsp),%rax
mov    (%rax),%eax
xor    %r12d,%r12d
lea    0xe34(%rip),%r15
mov    %r14,0x20(%rsp)
mov    0x10(%rsp),%rbx
mov    0x8(%rsp),%rbp
jmp    11ec <carregaArquivo+0xac>
nop
add    $0x1,%r12
movslq %ecx,%rdx
cmp    %rdx,%r12
jge    1236 <carregaArquivo+0xf6>
test   %eax,%eax
jle    11e0 <carregaArquivo+0xa0>
xor    %r14d,%r14d
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%rbp,%r12,8),%rdx
add    %r14,%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fscanf@plt>
add    $0x1,%r13
mov    0x18(%rsp),%rax
movslq (%rax),%rax
add    $0x4,%r14
cmp    %rax,%r13
jl     1200 <carregaArquivo+0xc0>
mov    0x20(%rsp),%r14
mov    (%r14),%ecx
jmp    11e0 <carregaArquivo+0xa0>
xor    %eax,%eax
jmp    1245 <carregaArquivo+0x105>
mov    0x10(%rsp),%rdi
call   1030 <fclose@plt>
mov    0x8(%rsp),%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define i32** @carregaArquivo(i8* nocapture %0, i32* %1, i32* %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %45, label %6
6: ; preds = %3
%7 = tail call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = tail call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %1
%10 = load i32, i32* %2
%11 = tail call i64 @alocaMatriz(i32 %9, i32 %10)
%12 = inttoptr i64 %11 to i32**
%13 = icmp eq i64 %11, 0
br i1 %13, label %45, label %14
14: ; preds = %6
%15 = load i32, i32* %1
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %43
17: ; preds = %14
%18 = load i32, i32* %2
br label %19
19: ; preds = %17, %37
%20 = phi i32 [ %15, %17 ], [ %38, %37 ]
%21 = phi i32 [ %18, %17 ], [ %39, %37 ]
%22 = phi i64 [ 0, %17 ], [ %40, %37 ]
%23 = icmp sgt i32 %21, 0
br i1 %23, label %24, label %37
24: ; preds = %19
%25 = getelementptr inbounds i32*, i32** %12, i64 %22
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ 0, %24 ], [ %31, %26 ]
%28 = load i32*, i32** %25
%29 = getelementptr inbounds i32, i32* %28, i64 %27
%30 = tail call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %29)
%31 = add nuw nsw i64 %27, 1
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %26, label %35
35: ; preds = %26
%36 = load i32, i32* %1
br label %37
37: ; preds = %35, %19
%38 = phi i32 [ %36, %35 ], [ %20, %19 ]
%39 = phi i32 [ %32, %35 ], [ %21, %19 ]
%40 = add nuw nsw i64 %22, 1
%41 = sext i32 %38 to i64
%42 = icmp slt i64 %40, %41
br i1 %42, label %19, label %43
43: ; preds = %37, %14
%44 = tail call i32 @fclose(i32* %4)
br label %45
45: ; preds = %43, %6, %3
%46 = phi i32** [ null, %3 ], [ %12, %43 ], [ null, %6 ]
ret i32** %46
}