#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*/ free(void *);
int /*<<< orphan*/ out_of_memory(char *, size_t);
void *ppmM_alloc(size_t);
void *realloc(void *, size_t);
void *ppmM_realloc(void *ptr, size_t size) {
  void *p;
  if (!ptr)
    return ppmM_alloc(size);
  p = realloc(ptr, size);
  if (!p) {
    free(ptr);
    out_of_memory("realloc", size);
  }
  return p;
}


x86 assembly (clang, -O0):
<ppmM_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <ppmM_realloc+0x2d>
mov    -0x18(%rbp),%rdi
call   1040 <ppmM_alloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11aa <ppmM_realloc+0x6a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a2 <ppmM_realloc+0x62>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rsi
lea    0xe63(%rip),%rdi
call   1050 <out_of_memory@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ppmM_realloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     117d <ppmM_realloc+0x3d>
mov    %rdi,%rbx
mov    %r14,%rsi
call   1060 <realloc@plt>
test   %rax,%rax
jne    1175 <ppmM_realloc+0x35>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe95(%rip),%rdi
mov    %r14,%rsi
call   1050 <out_of_memory@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <ppmM_alloc@plt>

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

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