#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int /*<<< orphan*/ stdin;
main() {
  int *m = NULL;
  int nBytes = 0, correcto = 0, nElementos = 0, i = 0;
  do {
    printf("Número de elementos de la matriz: ");
    correcto = scanf("%d", &nElementos);
    fflush(stdin);
  } while (!correcto || nElementos < 1);
  nBytes = nElementos * sizeof(int);
  if ((m = (int *)malloc(nBytes)) == NULL) {
    printf("Insuficiente espacio de memoria\n");
    return -1;
  }
  printf("Se han asignado %u bytes de memoria\n", nBytes);
  for (i = 0; i < nElementos; i++)
    m[i] = 0;
  free(m);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <scanf@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x1,%al
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x21(%rbp)
je     11cb <main+0x7b>
cmpl   $0x1,-0x1c(%rbp)
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1183 <main+0x33>
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1211 <main+0xc1>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1262 <main+0x112>
mov    -0x14(%rbp),%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1252 <main+0x102>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1229 <main+0xd9>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe85(%rip),%r14
lea    0xea2(%rip),%r15
lea    0xc(%rsp),%r12
mov    0x2e5a(%rip),%rbx
xchg   %ax,%ax
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
mov    %eax,%ebp
mov    (%rbx),%edi
call   1070 <fflush@plt>
test   %ebp,%ebp
je     1190 <main+0x30>
mov    0xc(%rsp),%ebp
test   %ebp,%ebp
jle    1190 <main+0x30>
shl    $0x2,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     120f <main+0xaf>
mov    %rax,%rbx
lea    0xe54(%rip),%rdi
xor    %r14d,%r14d
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1205 <main+0xa5>
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movl   $0x0,(%rbx,%rax,4)
add    $0x1,%rax
movslq 0xc(%rsp),%rcx
cmp    %rcx,%rax
jl     11f0 <main+0x90>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1221 <main+0xc1>
lea    0xe36(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"N\C3\BAmero de elementos de la matriz: \00"
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.2 = [33 x i8] c"Insuficiente espacio de memoria\0A\00"
@.str.3 = [37 x i8] c"Se han asignado %u bytes de memoria\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32* null, i32** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %18, %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
store i32 %9, i32* %4
%10 = load i32, i32* @stdin
%11 = call i32 @fflush(i32 %10)
br label %12
12: ; preds = %7
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 1
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ true, %12 ], [ %17, %15 ]
br i1 %19, label %7, label %20
20: ; preds = %18
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = trunc i64 %23 to i32
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i32*
store i32* %27, i32** %2
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %49
31: ; preds = %20
%32 = load i32, i32* %3
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %32)
store i32 0, i32* %6
br label %34
34: ; preds = %43, %31
%35 = load i32, i32* %6
%36 = load i32, i32* %5
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %46
38: ; preds = %34
%39 = load i32*, i32** %2
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
store i32 0, i32* %42
br label %43
43: ; preds = %38
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %34
46: ; preds = %34
%47 = load i32*, i32** %2
%48 = call i32 @free(i32* %47)
store i32 0, i32* %1
br label %49
49: ; preds = %46, %29
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@.str = [36 x i8] c"N\C3\BAmero de elementos de la matriz: \00"
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.3 = [37 x i8] c"Se han asignado %u bytes de memoria\0A\00"
@str = [32 x i8] c"Insuficiente espacio de memoria\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
br label %3
3: ; preds = %3, %0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = load i32, i32* @stdin
%7 = call i32 @fflush(i32 %6)
%8 = icmp eq i32 %5, 0
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 1
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %3, label %12
12: ; preds = %3
%13 = shl i32 %9, 2
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
%16 = icmp eq i64 %14, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %32
19: ; preds = %12
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%21 = load i32, i32* %1
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %19, %23
%24 = phi i64 [ %26, %23 ], [ 0, %19 ]
%25 = getelementptr inbounds i32, i32* %15, i64 %24
store i32 0, i32* %25
%26 = add nuw nsw i64 %24, 1
%27 = load i32, i32* %1
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %23, label %30
30: ; preds = %23, %19
%31 = call i32 @free(i32* %15)
br label %32
32: ; preds = %30, %17
%33 = phi i32 [ -1, %17 ], [ 0, %30 ]
ret i32 %33
}