#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*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
double *new_doubarray(int size) {
  int i;
  double *array, *ptr;
  array = (double *)malloc(sizeof(double) * size);
  if (!array) {
    fprintf(stderr, "Insufficient memory for %d data array.\n", size);
    return NULL;
  }
  ptr = array;
  for (i = 0; i < size; i++, ptr++)
    *ptr = 0.0;
  return array;
}


x86 assembly (clang, -O0):
<new_doubarray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116e <new_doubarray+0x4e>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xea4(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b6 <new_doubarray+0x96>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ae <new_doubarray+0x8e>
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    117d <new_doubarray+0x5d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_doubarray>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x0(,%rbx,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1160 <new_doubarray+0x30>
mov    %rax,%r14
test   %ebx,%ebx
jle    117a <new_doubarray+0x4a>
mov    %ebx,%edx
shl    $0x3,%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
jmp    117a <new_doubarray+0x4a>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Insufficient memory for %d data array.\0A\00"
define double* @new_doubarray(i32 %0) {
%2 = alloca double*
%3 = alloca i32
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = mul i64 8, %8
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to double*
store double* %12, double** %5
%13 = load double*, double** %5
%14 = icmp ne double* %13, null
br i1 %14, label %19, label %15
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = load i32, i32* %3
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %17)
store double* null, double** %2
br label %34
19: ; preds = %1
%20 = load double*, double** %5
store double* %20, double** %6
store i32 0, i32* %4
br label %21
21: ; preds = %27, %19
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load double*, double** %6
store double 0.000000e+00, double* %26
br label %27
27: ; preds = %25
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
%30 = load double*, double** %6
%31 = getelementptr inbounds double, double* %30, i32 1
store double* %31, double** %6
br label %21
32: ; preds = %21
%33 = load double*, double** %5
store double* %33, double** %2
br label %34
34: ; preds = %32, %15
%35 = load double*, double** %2
ret double* %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Insufficient memory for %d data array.\0A\00"
define double* @new_doubarray(i32 %0) {
%2 = shl i32 %0, 3
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to double*
%5 = inttoptr i64 %3 to i8*
%6 = icmp eq i64 %3, 0
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %15
9: ; preds = %7
%10 = zext i32 %0 to i64
%11 = shl nuw nsw i64 %10, 3
br label %15
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %15
15: ; preds = %9, %7, %12
%16 = phi double* [ null, %12 ], [ %4, %7 ], [ %4, %9 ]
ret double* %16
}