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


x86 assembly (clang, -O0):
<arrRead>:
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)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
je     118b <arrRead+0x6b>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe88(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <arrRead+0x36>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrRead>:
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
cmpl   $0x0,0x4(%rsp)
je     1180 <arrRead+0x60>
xor    %r12d,%r12d
lea    0xea3(%rip),%r15
mov    %r14,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
add    $0x1,%r12
mov    0x4(%rsp),%eax
add    $0x4,%rbx
cmp    %rax,%r12
jne    1160 <arrRead+0x40>
cltq
jmp    1182 <arrRead+0x62>
xor    %eax,%eax
movl   $0x0,(%r14,%rax,4)
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* @arrRead() {
%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
store i32 0, i32* %3
br label %12
12: ; preds = %16, %0
%13 = load i32, i32* %3
%14 = load i32, i32* %1
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32*, i32** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %20)
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %12
24: ; preds = %12
%25 = load i32*, i32** %2
%26 = load i32, i32* %1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 0, i32* %28
%29 = load i32*, i32** %2
ret i32* %29
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32* @arrRead() {
%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
%10 = icmp eq i32 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %0, %11
%12 = phi i64 [ %15, %11 ], [ 0, %0 ]
%13 = getelementptr inbounds i32, i32* %8, i64 %12
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %13)
%15 = add nuw i64 %12, 1
%16 = load i32, i32* %1
%17 = zext i32 %16 to i64
%18 = icmp eq i64 %15, %17
br i1 %18, label %19, label %11
19: ; preds = %11
%20 = sext i32 %16 to i64
br label %21
21: ; preds = %19, %0
%22 = phi i64 [ 0, %0 ], [ %20, %19 ]
%23 = getelementptr inbounds i32, i32* %8, i64 %22
store i32 0, i32* %23
ret i32* %8
}