#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*/ MA_assure_alloc(long, char const *, long);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ print_message(char *, char *, char const *, char const *,
                                 long);
void *realloc(void *, long);
void *MA_Realloc(void *p, long nr_bytes, const char *r, const char *fn,
                 long ln) {
  if (!nr_bytes)
    print_message("W003",
                  "[%s]: Reallocating to 0 bytes in file `%s' at line %ld.", r,
                  fn, ln);
  MA_assure_alloc(nr_bytes, fn, ln);
  if (!(p = realloc(p, nr_bytes))) {
    print_message("F003",
                  "[%s]: Memory allocation failed in file `%s' at line %ld.", r,
                  fn, ln);
    exit(1);
  }
  return p;
}


x86 assembly (clang, -O0):
<MA_Realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1186 <MA_Realloc+0x46>
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe86(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1030 <print_message@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <MA_assure_alloc@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11db <MA_Realloc+0x9b>
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe78(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1030 <print_message@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MA_Realloc>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r14
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r13
test   %rsi,%rsi
jne    1179 <MA_Realloc+0x39>
lea    0xe9c(%rip),%rdi
lea    0xe9a(%rip),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
call   1030 <print_message@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1060 <MA_assure_alloc@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1040 <realloc@plt>
test   %rax,%rax
je     11a1 <MA_Realloc+0x61>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe95(%rip),%rdi
lea    0xe93(%rip),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
call   1030 <print_message@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"W003\00"
@.str.1 = [56 x i8] c"[%s]: Reallocating to 0 bytes in file `%s' at line %ld.\00"
@.str.2 = [5 x i8] c"F003\00"
@.str.3 = [57 x i8] c"[%s]: Memory allocation failed in file `%s' at line %ld.\00"
define i8* @MA_Realloc(i8* %0, i64 %1, i8* %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%11 = load i64, i64* %7
%12 = icmp ne i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %5
%14 = load i8*, i8** %8
%15 = load i8*, i8** %9
%16 = load i64, i64* %10
%17 = call i32 @print_message(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %15, i64 %16)
br label %18
18: ; preds = %13, %5
%19 = load i64, i64* %7
%20 = load i8*, i8** %9
%21 = load i64, i64* %10
%22 = call i32 @MA_assure_alloc(i64 %19, i8* %20, i64 %21)
%23 = load i8*, i8** %6
%24 = load i64, i64* %7
%25 = call i8* @realloc(i8* %23, i64 %24)
store i8* %25, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %33, label %27
27: ; preds = %18
%28 = load i8*, i8** %8
%29 = load i8*, i8** %9
%30 = load i64, i64* %10
%31 = call i32 @print_message(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i8* %28, i8* %29, i64 %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %18
%34 = load i8*, i8** %6
ret i8* %34
}

LLVM IR (-O2):
@.str = [5 x i8] c"W003\00"
@.str.1 = [56 x i8] c"[%s]: Reallocating to 0 bytes in file `%s' at line %ld.\00"
@.str.2 = [5 x i8] c"F003\00"
@.str.3 = [57 x i8] c"[%s]: Memory allocation failed in file `%s' at line %ld.\00"
define noalias i8* @MA_Realloc(i8* nocapture %0, i64 %1, i8* %2, i8* %3, i64 %4) {
%6 = icmp eq i64 %1, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 @print_message(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %3, i64 %4)
br label %9
9: ; preds = %7, %5
%10 = tail call i32 @MA_assure_alloc(i64 %1, i8* %3, i64 %4)
%11 = tail call i8* @realloc(i8* %0, i64 %1)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = tail call i32 @print_message(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i8* %2, i8* %3, i64 %4)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9
ret i8* %11
}