#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*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
void read_array(int **array, int *n) {
  printf("Insert array length:");
  scanf("%d", n);
  (*array) = (int *)malloc(*n * sizeof(int));
  for (int i = 0; i < *n; i++)
    scanf("%d", &(*array)[i]);
}


x86 assembly (clang, -O0):
<read_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xebe(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    11ba <read_array+0x8a>
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe6e(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117f <read_array+0x4f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_array>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    (%r12),%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,(%r14)
cmpl   $0x0,(%r12)
jle    11bf <read_array+0x8f>
lea    0xe9e(%rip),%rdi
mov    %rax,%rsi
call   1050 <scanf@plt>
cmpl   $0x2,(%r12)
jl     11bf <read_array+0x8f>
mov    $0x1,%r13d
mov    $0x4,%ebx
lea    0xe7d(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    (%r14),%rsi
add    %rbx,%rsi
mov    %r15,%rdi
call   1050 <scanf@plt>
add    $0x1,%r13
movslq (%r12),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     11a0 <read_array+0x70>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [21 x i8] c"Insert array length:\00"
@.str.1 = [3 x i8] c"%d\00"
define void @read_array(i32** nocapture %0, i32* %1) {
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = tail 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 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %0
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, 1
br i1 %14, label %16, label %15
15: ; preds = %16, %11, %2
ret void
16: ; preds = %11, %16
%17 = phi i64 [ %21, %16 ], [ 1, %11 ]
%18 = load i32*, i32** %0
%19 = getelementptr inbounds i32, i32* %18, i64 %17
%20 = tail 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 %17, 1
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %16, label %15
}