#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*/ flushall();
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
main() {
  int *ptr;
  int no_els, no_bytes, i;
  printf("Enter the number of elements\n");
  scanf("%d", &no_els);
  no_bytes = (no_els * sizeof(int));
  ptr = (int *)malloc(no_bytes);
  if (ptr == NULL) {
    printf("Cannot allocate memory\n");
  } else {
    for (i = 0; i < no_els; i++) {
      scanf("%d", (ptr + i));
    }
    for (i = 0; i < no_els; i++) {
      printf("%d\n", *(ptr + i));
    }
    free(ptr);
  }
  flushall();
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9a(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1080 <scanf@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c2 <main+0x62>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1241 <main+0xe1>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11fe <main+0x9e>
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe33(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c9 <main+0x69>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1238 <main+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1205 <main+0xa5>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1050 <flushall@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
lea    0xe75(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1090 <scanf@plt>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1216 <main+0xa6>
mov    %rax,%r14
cmpl   $0x0,0x4(%rsp)
jle    120c <main+0x9c>
xor    %r12d,%r12d
lea    0xe46(%rip),%r15
mov    %r14,%rbx
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
add    $0x1,%r12
movslq 0x4(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%r12
jl     11c0 <main+0x50>
test   %eax,%eax
jle    120c <main+0x9c>
lea    0xe1b(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     11f0 <main+0x80>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1222 <main+0xb2>
lea    0xe07(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <flushall@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Enter the number of elements\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [24 x i8] c"Cannot allocate memory\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 4
%11 = trunc i64 %10 to i32
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %2
%15 = load i32*, i32** %2
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %51
19: ; preds = %0
store i32 0, i32* %5
br label %20
20: ; preds = %30, %19
%21 = load i32, i32* %5
%22 = load i32, i32* %3
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i32*, i32** %2
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %28)
br label %30
30: ; preds = %24
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %20
33: ; preds = %20
store i32 0, i32* %5
br label %34
34: ; preds = %45, %33
%35 = load i32, i32* %5
%36 = load i32, i32* %3
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %48
38: ; preds = %34
%39 = load i32*, i32** %2
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %38
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %34
48: ; preds = %34
%49 = load i32*, i32** %2
%50 = call i32 @free(i32* %49)
br label %51
51: ; preds = %48, %17
%52 = call i32 (...) @flushall()
%53 = call i32 (...) @getchar()
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [29 x i8] c"Enter the number of elements\00"
@str.4 = [23 x i8] c"Cannot allocate memory\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl i32 %5, 2
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = icmp eq i64 %7, 0
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %17, label %34
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
br label %36
15: ; preds = %17
%16 = icmp sgt i32 %22, 0
br i1 %16, label %25, label %34
17: ; preds = %10, %17
%18 = phi i64 [ %21, %17 ], [ 0, %10 ]
%19 = getelementptr inbounds i32, i32* %8, i64 %18
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %19)
%21 = add nuw nsw i64 %18, 1
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %17, label %15
25: ; preds = %15, %25
%26 = phi i64 [ %30, %25 ], [ 0, %15 ]
%27 = getelementptr inbounds i32, i32* %8, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = add nuw nsw i64 %26, 1
%31 = load i32, i32* %1
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %25, label %34
34: ; preds = %25, %10, %15
%35 = call i32 @free(i32* %8)
br label %36
36: ; preds = %34, %13
%37 = call i32 (...) @flushall()
%38 = call i32 (...) @getchar()
ret i32 0
}