#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*/ fatal(char *);
int /*<<< orphan*/ free(double *);
double *realloc(double *, uintptr_t);
double *reallocDouble(double *old, uintptr_t numDoubles) {
  {};
  double *new = NULL;
  if (numDoubles == 0) {
    free(old);
  } else {
    new = realloc(old, numDoubles * sizeof(double));
    if (new == NULL) {
      fatal("Memory allocation error.\n");
    }
  }
  {};
  return new;
}


x86 assembly (clang, -O0):
<reallocDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1161 <reallocDouble+0x31>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
jmp    1192 <reallocDouble+0x62>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
shl    $0x3,%rsi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118d <reallocDouble+0x5d>
lea    0xe78(%rip),%rdi
call   1050 <fatal@plt>
jmp    1192 <reallocDouble+0x62>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reallocDouble>:
push   %rax
test   %rsi,%rsi
je     1146 <reallocDouble+0x16>
shl    $0x3,%rsi
call   1040 <realloc@plt>
test   %rax,%rax
je     114d <reallocDouble+0x1d>
pop    %rcx
ret
call   1030 <free@plt>
jmp    1159 <reallocDouble+0x29>
lea    0xeac(%rip),%rdi
call   1050 <fatal@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Memory allocation error.\0A\00"
define double* @reallocDouble(double* %0, i64 %1) {
%3 = alloca double*
%4 = alloca i64
%5 = alloca double*
store double* %0, double** %3
store i64 %1, i64* %4
store double* null, double** %5
%6 = load i64, i64* %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load double*, double** %3
%10 = call i32 @free(double* %9)
br label %21
11: ; preds = %2
%12 = load double*, double** %3
%13 = load i64, i64* %4
%14 = mul i64 %13, 8
%15 = call double* @realloc(double* %12, i64 %14)
store double* %15, double** %5
%16 = load double*, double** %5
%17 = icmp eq double* %16, null
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %11
br label %21
21: ; preds = %20, %8
%22 = load double*, double** %5
ret double* %22
}

LLVM IR (-O2):
@.str = [26 x i8] c"Memory allocation error.\0A\00"
define noalias double* @reallocDouble(double* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @free(double* %0)
br label %12
6: ; preds = %2
%7 = shl i64 %1, 3
%8 = tail call double* @realloc(double* %0, i64 %7)
%9 = icmp eq double* %8, null
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %6, %10, %4
%13 = phi double* [ null, %4 ], [ null, %10 ], [ %8, %6 ]
ret double* %13
}