#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
double *double_vector(int len) {
  double *v;
  v = (double *)malloc((len + 1) * sizeof(double));
  if (!v) {
    fprintf(stderr, "Can not allocate double vector (%i)\n", len);
    exit(1);
  }
  *(int *)v = len;
  return v;
}


x86 assembly (clang, -O0):
<double_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117f <double_vector+0x4f>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe90(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<double_vector>:
push   %rbx
mov    %edi,%ebx
lea    0x8(,%rbx,8),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1148 <double_vector+0x18>
mov    %ebx,(%rax)
pop    %rbx
ret
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
mov    %ebx,%edx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Can not allocate double vector (%i)\0A\00"
define double* @double_vector(i32 %0) {
%2 = alloca i32
%3 = alloca double*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = add nsw i32 %4, 1
%6 = sext i32 %5 to i64
%7 = mul i64 %6, 8
%8 = trunc i64 %7 to i32
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to double*
store double* %10, double** %3
%11 = load double*, double** %3
%12 = icmp ne double* %11, null
br i1 %12, label %18, label %13
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i32, i32* %2
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %1
%19 = load i32, i32* %2
%20 = load double*, double** %3
%21 = bitcast double* %20 to i32*
store i32 %19, i32* %21
%22 = load double*, double** %3
ret double* %22
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"Can not allocate double vector (%i)\0A\00"
define double* @double_vector(i32 %0) {
%2 = shl i32 %0, 3
%3 = add i32 %2, 8
%4 = tail call i64 @malloc(i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = inttoptr i64 %4 to double*
%12 = inttoptr i64 %4 to i32*
store i32 %0, i32* %12
ret double* %11
}