#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 *, ...);
void read_array(double **array, int *n) {
  printf("Insert array length:");
  scanf("%d", n);
  (*array) = (double *)malloc(*n * sizeof(double));
  for (int i = 0; i < *n; i++)
    scanf("%lf", &(*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
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%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    11be <read_array+0x8e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1181 <read_array+0x51>
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
xor    %eax,%eax
call   1050 <scanf@plt>
mov    (%r12),%edi
shl    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,(%r14)
cmpl   $0x0,(%r12)
jle    11c1 <read_array+0x91>
lea    0xe9f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x2,(%r12)
jl     11c1 <read_array+0x91>
mov    $0x1,%r13d
mov    $0x8,%ebx
lea    0xe7c(%rip),%r15
nopl   0x0(%rax)
mov    (%r14),%rsi
add    %rbx,%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
add    $0x1,%r13
movslq (%r12),%rax
add    $0x8,%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"
@.str.2 = [4 x i8] c"%lf\00"
define void @read_array(double** %0, i32* %1) {
%3 = alloca double**
%4 = alloca i32*
%5 = alloca i32
store double** %0, double*** %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 (i8*, ...) @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, 8
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to double*
%16 = load double**, double*** %3
store double* %15, double** %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 double**, double*** %3
%24 = load double*, double** %23
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %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"
@.str.2 = [4 x i8] c"%lf\00"
define void @read_array(double** 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 (i8*, ...) @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, 3
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to double*
store double* %8, double** %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 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %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 double*, double** %0
%19 = getelementptr inbounds double, double* %18, i64 %17
%20 = tail call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %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
}