#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);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void alloc_dyna(void) {
  int n = 0, *pn, i;
  pn = (int *)malloc(n * sizeof(int));
  if (pn == NULL) {
    printf("Not enough memory!\n");
    exit(1);
  }
  for (i = 0; i < 3; i++) {
    printf("%d numero: ", i + 1);
    scanf("%d", pn + i);
  }
  free(pn);
}


x86 assembly (clang, -O0):
<alloc_dyna>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1195 <alloc_dyna+0x45>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11e3 <alloc_dyna+0x93>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe50(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119c <alloc_dyna+0x4c>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_dyna>:
push   %r15
push   %r14
push   %rbx
xor    %edi,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11e2 <alloc_dyna+0x82>
mov    %rax,%rbx
lea    0xe85(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe7b(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x4(%rbx),%rsi
mov    %r15,%rdi
call   1070 <scanf@plt>
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rsi
add    $0x8,%rsi
mov    %r15,%rdi
call   1070 <scanf@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Not enough memory!\0A\00"
@.str.1 = [12 x i8] c"%d numero: \00"
@.str.2 = [3 x i8] c"%d\00"
define void @alloc_dyna() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* %1
%5 = sext i32 %4 to i64
%6 = mul i64 %5, 4
%7 = trunc i64 %6 to i32
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
store i32 0, i32* %3
br label %16
16: ; preds = %28, %15
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32*, i32** %2
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %26)
br label %28
28: ; preds = %19
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %16
31: ; preds = %16
%32 = load i32*, i32** %2
%33 = call i32 @free(i32* %32)
ret void
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"%d numero: \00"
@.str.2 = [3 x i8] c"%d\00"
@str = [19 x i8] c"Not enough memory!\00"
define void @alloc_dyna() {
%1 = tail call i64 @malloc(i32 0)
%2 = inttoptr i64 %1 to i32*
%3 = icmp eq i64 %1, 0
br i1 %3, label %14, label %4
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 1)
%6 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 2)
%8 = getelementptr inbounds i32, i32* %2, i64 1
%9 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 3)
%11 = getelementptr inbounds i32, i32* %2, i64 2
%12 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %11)
%13 = tail call i32 @free(i32* %2)
ret void
14: ; preds = %0
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
}