#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ malloc(size_t);
scalar_t__ realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *realloc_error(void *array, size_t size, const char *variable,
                    const char *function) {
  if (array == (void *)NULL)
    array = (void *)malloc(size);
  else
    array = (void *)realloc(array, size);
  if (array == (void *)NULL) {
    fprintf(stderr, "Cannot realloc space for \"%s\" in the ", variable);
    fprintf(stderr, "\"%s\" function.\n", function);
    exit(1);
  } else
    return (array);
}


x86 assembly (clang, -O0):
<realloc_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1175 <realloc_error+0x35>
mov    -0x10(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
jmp    1186 <realloc_error+0x46>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11cd <realloc_error+0x8d>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe5b(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe68(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realloc_error>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
test   %rdi,%rdi
je     1160 <realloc_error+0x20>
call   1050 <realloc@plt>
test   %rax,%rax
je     116d <realloc_error+0x2d>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rsi,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
jne    115a <realloc_error+0x1a>
mov    0x2e6c(%rip),%r15
mov    (%r15),%edi
lea    0xe82(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    (%r15),%edi
lea    0xe96(%rip),%rsi
mov    %r14,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"Cannot realloc space for \22%s\22 in the \00"
@.str.1 = [16 x i8] c"\22%s\22 function.\0A\00"
define i8* @realloc_error(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = load i64, i64* %6
%13 = call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %5
br label %20
15: ; preds = %4
%16 = load i8*, i8** %5
%17 = load i64, i64* %6
%18 = call i64 @realloc(i8* %16, i64 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %5
br label %20
20: ; preds = %15, %11
%21 = load i8*, i8** %5
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %7
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %8
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %20
%32 = load i8*, i8** %5
ret i8* %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"Cannot realloc space for \22%s\22 in the \00"
@.str.1 = [16 x i8] c"\22%s\22 function.\0A\00"
define i8* @realloc_error(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i64 @malloc(i64 %1)
br label %10
8: ; preds = %4
%9 = tail call i64 @realloc(i8* %0, i64 %1)
br label %10
10: ; preds = %8, %6
%11 = phi i64 [ %7, %6 ], [ %9, %8 ]
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %2)
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %10
%20 = inttoptr i64 %11 to i8*
ret i8* %20
}