#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 /*<<< orphan*/ free(double *);
double *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, double);
void test1(void) {
  double *a;
  size_t n = 10;
  a = malloc(n * sizeof(double));
  size_t i;
  if (a == 0) {
    perror("malloc failed");
  }
  for (i = 0; i < n; i++)
    a[i] = (double)i;
  for (i = 0; i < n; i++)
    printf("%-10f \n", a[i]);
  free(a);
}


x86 assembly (clang, -O0):
<test1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0xa,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1178 <test1+0x38>
lea    0xead(%rip),%rdi
call   1060 <perror@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11d3 <test1+0x93>
movaps 0xe6b(%rip),%xmm1
movq   -0x18(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe6a(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1180 <test1+0x40>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1213 <test1+0xd3>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11db <test1+0x9b>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test1>:
push   %r14
push   %rbx
push   %rax
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1248 <test1+0x108>
movsd  0xe9e(%rip),%xmm1
xorps  %xmm0,%xmm0
movlhps %xmm1,%xmm0
movups %xmm0,(%rbx)
movaps 0xede(%rip),%xmm0
movups %xmm0,0x10(%rbx)
movaps 0xee3(%rip),%xmm0
movups %xmm0,0x20(%rbx)
movaps 0xee8(%rip),%xmm0
movups %xmm0,0x30(%rbx)
movaps 0xeed(%rip),%xmm0
movups %xmm0,0x40(%rbx)
lea    0xf00(%rip),%r14
xorps  %xmm0,%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
movsd  0xe4c(%rip),%xmm0
call   1040 <printf@plt>
movsd  0xe47(%rip),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
movsd  0xe3f(%rip),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
movsd  0xe37(%rip),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
movsd  0xe2f(%rip),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
movsd  0xe27(%rip),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
movsd  0xe1f(%rip),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
movsd  0xe17(%rip),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
movsd  0xe0f(%rip),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
lea    0xe41(%rip),%rdi
call   1060 <perror@plt>
jmp    115a <test1+0x1a>

LLVM IR (-O0):
@.str = [14 x i8] c"malloc failed\00"
@.str.1 = [8 x i8] c"%-10f \0A\00"
define void @test1() {
%1 = alloca double*
%2 = alloca i64
%3 = alloca i64
store i64 10, i64* %2
%4 = load i64, i64* %2
%5 = mul i64 %4, 8
%6 = call double* @malloc(i64 %5)
store double* %6, double** %1
%7 = load double*, double** %1
%8 = icmp eq double* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
store i64 0, i64* %3
br label %12
12: ; preds = %22, %11
%13 = load i64, i64* %3
%14 = load i64, i64* %2
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i64, i64* %3
%18 = uitofp i64 %17 to double
%19 = load double*, double** %1
%20 = load i64, i64* %3
%21 = getelementptr inbounds double, double* %19, i64 %20
store double %18, double* %21
br label %22
22: ; preds = %16
%23 = load i64, i64* %3
%24 = add i64 %23, 1
store i64 %24, i64* %3
br label %12
25: ; preds = %12
store i64 0, i64* %3
br label %26
26: ; preds = %36, %25
%27 = load i64, i64* %3
%28 = load i64, i64* %2
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = load double*, double** %1
%32 = load i64, i64* %3
%33 = getelementptr inbounds double, double* %31, i64 %32
%34 = load double, double* %33
%35 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %34)
br label %36
36: ; preds = %30
%37 = load i64, i64* %3
%38 = add i64 %37, 1
store i64 %38, i64* %3
br label %26
39: ; preds = %26
%40 = load double*, double** %1
%41 = call i32 @free(double* %40)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"malloc failed\00"
@.str.1 = [8 x i8] c"%-10f \0A\00"
define void @test1() {
%1 = tail call double* @malloc(i64 80)
%2 = icmp eq double* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = bitcast double* %1 to <2 x double>*
store <2 x double> <double 0.000000e+00, double 1.000000e+00>, <2 x double>* %6
%7 = getelementptr inbounds double, double* %1, i64 2
%8 = bitcast double* %7 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 3.000000e+00>, <2 x double>* %8
%9 = getelementptr inbounds double, double* %1, i64 4
%10 = bitcast double* %9 to <2 x double>*
store <2 x double> <double 4.000000e+00, double 5.000000e+00>, <2 x double>* %10
%11 = getelementptr inbounds double, double* %1, i64 6
%12 = bitcast double* %11 to <2 x double>*
store <2 x double> <double 6.000000e+00, double 7.000000e+00>, <2 x double>* %12
%13 = getelementptr inbounds double, double* %1, i64 8
%14 = bitcast double* %13 to <2 x double>*
store <2 x double> <double 8.000000e+00, double 9.000000e+00>, <2 x double>* %14
%15 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double 0.000000e+00)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double 1.000000e+00)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double 2.000000e+00)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double 3.000000e+00)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double 4.000000e+00)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double 5.000000e+00)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double 6.000000e+00)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double 7.000000e+00)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double 8.000000e+00)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double 9.000000e+00)
%25 = tail call i32 @free(double* %1)
ret void
}