#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_FAILURE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
void *realloc(void *, size_t);
extern void *mem_resize(void *ptr, size_t nbytes, const char *file, int line) {
  assert(ptr);
  assert(nbytes > 0);
  ptr = realloc(ptr, nbytes);
  if (!ptr) {
    printf("Memory was not allocated. Exiting...\n");
    exit(EXIT_FAILURE);
  }
  return ptr;
}


x86 assembly (clang, -O0):
<mem_resize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11aa <mem_resize+0x6a>
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_resize>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <realloc@plt>
test   %rax,%rax
je     1175 <mem_resize+0x35>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"Memory was not allocated. Exiting...\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @mem_resize(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%9 = load i8*, i8** %5
%10 = ptrtoint i8* %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i64, i64* %6
%13 = icmp ugt i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %5
%17 = load i64, i64* %6
%18 = call i8* @realloc(i8* %16, i64 %17)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %25, label %21
21: ; preds = %4
%22 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %4
%26 = load i8*, i8** %5
ret i8* %26
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [37 x i8] c"Memory was not allocated. Exiting...\00"
define noalias i8* @mem_resize(i8* %0, i64 %1, i8* nocapture readnone %2, i32 %3) {
%5 = ptrtoint i8* %0 to i64
%6 = trunc i64 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp ne i64 %1, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i8* @realloc(i8* %0, i64 %1)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %4
ret i8* %11
}