#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 *, unsigned int);
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 %u bytes\n",
          (unsigned)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    11bf <android_realloc+0x7f>
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    11bf <android_realloc+0x7f>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
lea    0xe50(%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    %ebx,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"PANIC: not enough memory to reallocate %u 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 %26
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 %26
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = load i64, i64* %5
%23 = trunc i64 %22 to i32
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18, %9
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"PANIC: not enough memory to reallocate %u 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 %14
6: ; preds = %2
%7 = tail call i8* @realloc(i8* %0, i64 %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = trunc i64 %1 to i32
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %6, %4
%15 = phi i8* [ null, %4 ], [ %7, %6 ]
ret i8* %15
}