#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);
double *md_alloc_double(int length) {
  double *field = NULL;
  int i;
  if (length < 1) {
    return (NULL);
  }
  if ((field = (double *)malloc(length * sizeof(double))) == NULL) {
    return (NULL);
  } else {
    for (i = 0; i < length; i++) {
      field[i] = 0;
    }
    return (field);
  }
}


x86 assembly (clang, -O0):
<md_alloc_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    113a <md_alloc_double+0x2a>
movq   $0x0,-0x8(%rbp)
jmp    119d <md_alloc_double+0x8d>
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1164 <md_alloc_double+0x54>
movq   $0x0,-0x8(%rbp)
jmp    119d <md_alloc_double+0x8d>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1195 <md_alloc_double+0x85>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116b <md_alloc_double+0x5b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<md_alloc_double>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    1150 <md_alloc_double+0x30>
mov    %edi,%ebx
lea    0x0(,%rbx,8),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1150 <md_alloc_double+0x30>
mov    %rax,%r14
mov    %ebx,%edx
shl    $0x3,%rdx
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
jmp    1153 <md_alloc_double+0x33>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double* @md_alloc_double(i32 %0) {
%2 = alloca double*
%3 = alloca i32
%4 = alloca double*
%5 = alloca i32
store i32 %0, i32* %3
store double* null, double** %4
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %1
store double* null, double** %2
br label %33
9: ; preds = %1
%10 = load i32, i32* %3
%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*
store double* %15, double** %4
%16 = icmp eq double* %15, null
br i1 %16, label %17, label %18
17: ; preds = %9
store double* null, double** %2
br label %33
18: ; preds = %9
store i32 0, i32* %5
br label %19
19: ; preds = %28, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load double*, double** %4
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
store double 0.000000e+00, double* %27
br label %28
28: ; preds = %23
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %19
31: ; preds = %19
%32 = load double*, double** %4
store double* %32, double** %2
br label %33
33: ; preds = %31, %17, %8
%34 = load double*, double** %2
ret double* %34
}

LLVM IR (-O2):
define double* @md_alloc_double(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = shl i32 %0, 3
%5 = tail call i64 @malloc(i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = inttoptr i64 %5 to i8*
%9 = inttoptr i64 %5 to double*
%10 = zext i32 %0 to i64
%11 = shl nuw nsw i64 %10, 3
br label %12
12: ; preds = %7, %3, %1
%13 = phi double* [ null, %1 ], [ null, %3 ], [ %9, %7 ]
ret double* %13
}