#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 */
void *calloc(int, size_t);
int /*<<< orphan*/ eprint(char *, size_t);
void *realloc(void *, size_t);
void *ereallocz(void *p, size_t size) {
  void *res;
  if (p)
    res = realloc(p, size);
  else
    res = calloc(1, size);
  if (!res)
    eprint("fatal: could not malloc() %u bytes\n", size);
  return res;
}


x86 assembly (clang, -O0):
<ereallocz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1161 <ereallocz+0x31>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
jmp    1173 <ereallocz+0x43>
mov    -0x10(%rbp),%rsi
mov    $0x1,%edi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118e <ereallocz+0x5e>
mov    -0x10(%rbp),%rsi
lea    0xe77(%rip),%rdi
call   1050 <eprint@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ereallocz>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     1146 <ereallocz+0x16>
mov    %r14,%rsi
call   1040 <realloc@plt>
jmp    1153 <ereallocz+0x23>
mov    $0x1,%edi
mov    %r14,%rsi
call   1030 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116a <ereallocz+0x3a>
lea    0xe9e(%rip),%rdi
mov    %r14,%rsi
call   1050 <eprint@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [36 x i8] c"fatal: could not malloc() %u bytes\0A\00"
define i8* @ereallocz(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = load i64, i64* %4
%11 = call i8* @realloc(i8* %9, i64 %10)
store i8* %11, i8** %5
br label %15
12: ; preds = %2
%13 = load i64, i64* %4
%14 = call i8* @calloc(i32 1, i64 %13)
store i8* %14, i8** %5
br label %15
15: ; preds = %12, %8
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i64, i64* %4
%20 = call i32 @eprint(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i64 %19)
br label %21
21: ; preds = %18, %15
%22 = load i8*, i8** %5
ret i8* %22
}

LLVM IR (-O2):
@.str = [36 x i8] c"fatal: could not malloc() %u bytes\0A\00"
define i8* @ereallocz(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i8* @realloc(i8* %0, i64 %1)
br label %8
6: ; preds = %2
%7 = tail call i8* @calloc(i32 1, i64 %1)
br label %8
8: ; preds = %6, %4
%9 = phi i8* [ %5, %4 ], [ %7, %6 ]
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @eprint(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i64 %1)
br label %13
13: ; preds = %11, %8
ret i8* %9
}