#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 *malloc(size_t);
int /*<<< orphan*/ scanf(char *, ...);
int *array_read(size_t *out_count) {
  int *array;
  size_t i;
  size_t cnt;
  scanf("%zu", &cnt);
  array = malloc(cnt * sizeof(int));
  for (i = 0; i < cnt; i++)
    scanf("%d", &array[i]);
  *out_count = cnt;
  return array;
}


x86 assembly (clang, -O0):
<array_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x20(%rbp),%rdi
shl    $0x2,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1193 <array_read+0x73>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1157 <array_read+0x37>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xecb(%rip),%rdi
xor    %r13d,%r13d
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    (%rsp),%rbx
lea    0x0(,%rbx,4),%rdi
call   1030 <malloc@plt>
mov    %rax,%r15
test   %rbx,%rbx
je     118e <array_read+0x6e>
lea    0xea2(%rip),%r12
mov    %r15,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
add    $0x1,%rbp
mov    (%rsp),%r13
add    $0x4,%rbx
cmp    %r13,%rbp
jb     1170 <array_read+0x50>
mov    %r13,(%r14)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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