#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 */
void *calloc(int, int);
int /*<<< orphan*/ printf(char *);
int **aloca(int tam) {
  int **matriz, i;
  matriz = calloc(tam, sizeof(int *));
  for (i = 0; i < tam; i++) {
    matriz[i] = calloc(tam, sizeof(int *));
  }
  printf("alocado\n");
  return (matriz);
}


x86 assembly (clang, -O0):
<aloca>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1179 <aloca+0x59>
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <aloca+0x23>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aloca>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    116a <aloca+0x4a>
mov    %r15d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,(%r14,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1150 <aloca+0x30>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"alocado\0A\00"
define i32** @aloca(i32 %0) {
%2 = alloca i32
%3 = alloca i32**
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i8* @calloc(i32 %5, i32 8)
%7 = bitcast i8* %6 to i32**
store i32** %7, i32*** %3
store i32 0, i32* %4
br label %8
8: ; preds = %20, %1
%9 = load i32, i32* %4
%10 = load i32, i32* %2
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load i32, i32* %2
%14 = call i8* @calloc(i32 %13, i32 8)
%15 = bitcast i8* %14 to i32*
%16 = load i32**, i32*** %3
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32*, i32** %16, i64 %18
store i32* %15, i32** %19
br label %20
20: ; preds = %12
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %8
23: ; preds = %8
%24 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%25 = load i32**, i32*** %3
ret i32** %25
}

LLVM IR (-O2):
@str = [8 x i8] c"alocado\00"
define noalias i32** @aloca(i32 %0) {
%2 = tail call i8* @calloc(i32 %0, i32 8)
%3 = bitcast i8* %2 to i32**
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %14
5: ; preds = %1
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %12, %7 ]
%9 = tail call i8* @calloc(i32 %0, i32 8)
%10 = getelementptr inbounds i32*, i32** %3, i64 %8
%11 = bitcast i32** %10 to i8**
store i8* %9, i8** %11
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, %6
br i1 %13, label %14, label %7
14: ; preds = %7, %1
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
ret i32** %3
}