#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t);
int /*<<< orphan*/ free(void *);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *android_realloc(void *block, size_t size) {
  void *block2;
  if (size == 0) {
    free(block);
    return NULL;
  }
  block2 = realloc(block, size);
  if (block2 != NULL)
    return block2;
  fprintf(stderr, "PANIC: not enough memory to reallocate %zu bytes\n", size);
  exit(1);
  return NULL;
}


x86 assembly (clang, -O0):
<android_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1171 <android_realloc+0x31>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11bd <android_realloc+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119a <android_realloc+0x5a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bd <android_realloc+0x7d>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe52(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<android_realloc>:
push   %rbx
test   %rsi,%rsi
je     1155 <android_realloc+0x15>
mov    %rsi,%rbx
call   1050 <realloc@plt>
test   %rax,%rax
je     115e <android_realloc+0x1e>
pop    %rbx
ret
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [50 x i8] c"PANIC: not enough memory to reallocate %zu bytes\0A\00"
define i8* @android_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 i64, i64* %5
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i32 @free(i8* %10)
store i8* null, 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 %18, label %20
18: ; preds = %12
%19 = load i8*, i8** %6
store i8* %19, i8** %3
br label %25
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = load i64, i64* %5
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i64 %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18, %9
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [50 x i8] c"PANIC: not enough memory to reallocate %zu bytes\0A\00"
define noalias i8* @android_realloc(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @free(i8* %0)
br label %13
6: ; preds = %2
%7 = tail call i8* @realloc(i8* %0, i64 %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i64 %1)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6, %4
%14 = phi i8* [ null, %4 ], [ %7, %6 ]
ret i8* %14
}