#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ scanf(char *, int *);
int *newArray() {
  int n;
  scanf("%d", &n);
  int *a = (int *)malloc((n + 1) * sizeof(int));
  a[0] = n;
  int i = 1;
  while (i <= n) {
    scanf("%d", a + i);
    i = i + 1;
  }
  return a;
}


x86 assembly (clang, -O0):
<newArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1194 <newArray+0x74>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7f(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115f <newArray+0x3f>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newArray>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xed1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
lea    0x4(,%rax,4),%edi
call   1030 <malloc@plt>
mov    %rax,%r14
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
cmpl   $0x0,0x4(%rsp)
jle    118d <newArray+0x6d>
mov    %r14,%r12
add    $0x4,%r12
xor    %ebx,%ebx
lea    0xe96(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
movslq 0x4(%rsp),%rax
add    $0x1,%rbx
add    $0x4,%r12
cmp    %rax,%rbx
jl     1170 <newArray+0x50>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32* @newArray() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 4
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %2
%12 = load i32, i32* %1
%13 = load i32*, i32** %2
%14 = getelementptr inbounds i32, i32* %13, i64 0
store i32 %12, i32* %14
store i32 1, i32* %3
br label %15
15: ; preds = %19, %0
%16 = load i32, i32* %3
%17 = load i32, i32* %1
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i32*, i32** %2
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %23)
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %15
27: ; preds = %15
%28 = load i32*, i32** %2
ret i32* %28
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32* @newArray() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = shl i32 %4, 2
%6 = add i32 %5, 4
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = load i32, i32* %1
store i32 %9, i32* %8
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 1
br i1 %11, label %20, label %12
12: ; preds = %0, %12
%13 = phi i64 [ %16, %12 ], [ 1, %0 ]
%14 = getelementptr inbounds i32, i32* %8, i64 %13
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %14)
%16 = add nuw nsw i64 %13, 1
%17 = load i32, i32* %1
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %13, %18
br i1 %19, label %12, label %20
20: ; preds = %12, %0
ret i32* %8
}