#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 *fail_die_malloc(size_t, char const *, int);
int /*<<< orphan*/ fail_die_malloc_die(size_t, char const *, int);
void *realloc(void *, size_t);
void *fail_die_realloc(void *p, size_t size, const char *file, int line) {
  if (!p)
    return fail_die_malloc(size, file, line);
  p = realloc(p, size);
  if (!p && size)
    fail_die_malloc_die(size, file, line);
  return p;
}


x86 assembly (clang, -O0):
<fail_die_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116b <fail_die_realloc+0x3b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <fail_die_malloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11aa <fail_die_realloc+0x7a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a2 <fail_die_realloc+0x72>
cmpq   $0x0,-0x18(%rbp)
je     11a2 <fail_die_realloc+0x72>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <fail_die_malloc_die@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fail_die_realloc>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%rbp
test   %rdi,%rdi
je     1169 <fail_die_realloc+0x39>
mov    %rbp,%rsi
call   1040 <realloc@plt>
test   %rbp,%rbp
je     1164 <fail_die_realloc+0x34>
test   %rax,%rax
jne    1164 <fail_die_realloc+0x34>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <fail_die_malloc_die@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fail_die_malloc@plt>

LLVM IR (-O0):
define i8* @fail_die_realloc(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %4
%13 = load i64, i64* %7
%14 = load i8*, i8** %8
%15 = load i32, i32* %9
%16 = call i8* @fail_die_malloc(i64 %13, i8* %14, i32 %15)
store i8* %16, i8** %5
br label %33
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = load i64, i64* %7
%20 = call i8* @realloc(i8* %18, i64 %19)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %31, label %23
23: ; preds = %17
%24 = load i64, i64* %7
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i64, i64* %7
%28 = load i8*, i8** %8
%29 = load i32, i32* %9
%30 = call i32 @fail_die_malloc_die(i64 %27, i8* %28, i32 %29)
br label %31
31: ; preds = %26, %23, %17
%32 = load i8*, i8** %6
store i8* %32, i8** %5
br label %33
33: ; preds = %31, %12
%34 = load i8*, i8** %5
ret i8* %34
}

LLVM IR (-O2):
define i8* @fail_die_realloc(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i8* @fail_die_malloc(i64 %1, i8* %2, i32 %3)
br label %15
8: ; preds = %4
%9 = tail call i8* @realloc(i8* %0, i64 %1)
%10 = icmp eq i8* %9, null
%11 = icmp ne i64 %1, 0
%12 = and i1 %11, %10
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @fail_die_malloc_die(i64 %1, i8* %2, i32 %3)
br label %15
15: ; preds = %8, %13, %6
%16 = phi i8* [ %7, %6 ], [ null, %13 ], [ %9, %8 ]
ret i8* %16
}