#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int **AlocarMatriz(int tam) {
  int i, j, **matriz;
  matriz = (int **)malloc(tam * sizeof(int *));
  if (!matriz) {
    printf("Erro: Memória insuficiente!\n");
    exit(1);
  }
  for (i = 0; i < tam; i++) {
    matriz[i] = (int *)malloc(tam * sizeof(int));
    if (!matriz[i]) {
      printf("Erro: Memória insuficiente!\n");
      exit(1);
    }
    for (j = 0; j < tam; j++)
      matriz[i][j] = 0;
  }
  return matriz;
}


x86 assembly (clang, -O0):
<AlocarMatriz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116f <AlocarMatriz+0x3f>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1214 <AlocarMatriz+0xe4>
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11c9 <AlocarMatriz+0x99>
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1201 <AlocarMatriz+0xd1>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0xc(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d0 <AlocarMatriz+0xa0>
jmp    1206 <AlocarMatriz+0xd6>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1176 <AlocarMatriz+0x46>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AlocarMatriz>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b4 <AlocarMatriz+0x74>
mov    %rax,%r15
test   %r14d,%r14d
jle    11a7 <AlocarMatriz+0x67>
mov    %r14d,%r12d
shl    $0x2,%r14d
lea    0x0(,%r12,4),%r13
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
test   %rax,%rax
je     11b4 <AlocarMatriz+0x74>
mov    %rax,%rdi
xor    %esi,%esi
mov    %r13,%rdx
call   1040 <memset@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <AlocarMatriz+0x40>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@str.1 = [29 x i8] c"Erro: Mem\C3\B3ria insuficiente!\00"
define i32** @AlocarMatriz(i32 %0) {
%2 = shl i32 %0, 3
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i32**
%5 = icmp eq i64 %3, 0
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %28
8: ; preds = %6
%9 = shl i32 %0, 2
%10 = zext i32 %0 to i64
%11 = shl nuw nsw i64 %10, 2
br label %15
12: ; preds = %1
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8, %24
%16 = phi i64 [ 0, %8 ], [ %26, %24 ]
%17 = tail call i64 @malloc(i32 %9)
%18 = inttoptr i64 %17 to i32*
%19 = getelementptr inbounds i32*, i32** %4, i64 %16
store i32* %18, i32** %19
%20 = icmp eq i64 %17, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = inttoptr i64 %17 to i8*
%26 = add nuw nsw i64 %16, 1
%27 = icmp eq i64 %26, %10
br i1 %27, label %28, label %15
28: ; preds = %24, %6
ret i32** %4
}