#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__ calloc(unsigned int, int);
scalar_t__ realloc(char *, unsigned int);
void AllocDouble(int newsize, double **storage) {
  union {
    double *D;
    char *C;
  } DC;
  if (!*storage)
    DC.C = (char *)calloc((unsigned)newsize, sizeof(double));
  else {
    DC.D = *storage;
    DC.C = (char *)realloc(DC.C, (unsigned)newsize * sizeof(double));
  }
  *storage = DC.D;
}


x86 assembly (clang, -O0):
<AllocDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1153 <AllocDouble+0x33>
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
jmp    1174 <AllocDouble+0x54>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AllocDouble>:
push   %rbx
mov    %rsi,%rbx
mov    %edi,%esi
mov    (%rbx),%rdi
test   %rdi,%rdi
je     1138 <AllocDouble+0x18>
shl    $0x3,%esi
call   1040 <realloc@plt>
jmp    1144 <AllocDouble+0x24>
mov    %esi,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
%union.anon = type { double* }
define void @AllocDouble(i32 %0, double** %1) {
%3 = alloca i32
%4 = alloca double**
%5 = alloca %union.anon
store i32 %0, i32* %3
store double** %1, double*** %4
%6 = load double**, double*** %4
%7 = load double*, double** %6
%8 = icmp ne double* %7, null
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i32, i32* %3
%11 = call i64 @calloc(i32 %10, i32 8)
%12 = inttoptr i64 %11 to i8*
%13 = bitcast %union.anon* %5 to i8**
store i8* %12, i8** %13
br label %27
14: ; preds = %2
%15 = load double**, double*** %4
%16 = load double*, double** %15
%17 = bitcast %union.anon* %5 to double**
store double* %16, double** %17
%18 = bitcast %union.anon* %5 to i8**
%19 = load i8*, i8** %18
%20 = load i32, i32* %3
%21 = zext i32 %20 to i64
%22 = mul i64 %21, 8
%23 = trunc i64 %22 to i32
%24 = call i64 @realloc(i8* %19, i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = bitcast %union.anon* %5 to i8**
store i8* %25, i8** %26
br label %27
27: ; preds = %14, %9
%28 = bitcast %union.anon* %5 to double**
%29 = load double*, double** %28
%30 = load double**, double*** %4
store double* %29, double** %30
ret void
}

LLVM IR (-O2):
define void @AllocDouble(i32 %0, double** nocapture %1) {
%3 = load double*, double** %1
%4 = icmp eq double* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i64 @calloc(i32 %0, i32 8)
br label %11
7: ; preds = %2
%8 = bitcast double* %3 to i8*
%9 = shl i32 %0, 3
%10 = tail call i64 @realloc(i8* %8, i32 %9)
br label %11
11: ; preds = %7, %5
%12 = phi i64 [ %10, %7 ], [ %6, %5 ]
%13 = inttoptr i64 %12 to double*
store double* %13, double** %1
ret void
}