#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 */
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *realloc(int /*<<< orphan*/ *, uintptr_t);
int32_t *reallocInt(int32_t *old, uintptr_t numInts) {
  int32_t *new = NULL;
  if (numInts == 0) {
    free(old);
  } else {
    new = realloc(old, numInts * sizeof(int32_t));
    if (new == NULL) {
      fatal("Memory allocation error.\n");
    }
  }
  return new;
}


x86 assembly (clang, -O0):
<reallocInt>:
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 <reallocInt+0x31>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
jmp    1192 <reallocInt+0x62>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
shl    $0x2,%rsi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118d <reallocInt+0x5d>
lea    0xe78(%rip),%rdi
call   1050 <fatal@plt>
jmp    1192 <reallocInt+0x62>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reallocInt>:
push   %rax
test   %rsi,%rsi
je     1146 <reallocInt+0x16>
shl    $0x2,%rsi
call   1040 <realloc@plt>
test   %rax,%rax
je     114d <reallocInt+0x1d>
pop    %rcx
ret
call   1030 <free@plt>
jmp    1159 <reallocInt+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 i32* @reallocInt(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32*
store i32* %0, i32** %3
store i64 %1, i64* %4
store i32* null, i32** %5
%6 = load i64, i64* %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32*, i32** %3
%10 = call i32 @free(i32* %9)
br label %21
11: ; preds = %2
%12 = load i32*, i32** %3
%13 = load i64, i64* %4
%14 = mul i64 %13, 4
%15 = call i32* @realloc(i32* %12, i64 %14)
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = icmp eq i32* %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 i32*, i32** %5
ret i32* %22
}

LLVM IR (-O2):
@.str = [26 x i8] c"Memory allocation error.\0A\00"
define noalias i32* @reallocInt(i32* 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(i32* %0)
br label %12
6: ; preds = %2
%7 = shl i64 %1, 2
%8 = tail call i32* @realloc(i32* %0, i64 %7)
%9 = icmp eq i32* %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 i32* [ null, %4 ], [ null, %10 ], [ %8, %6 ]
ret i32* %13
}