#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 */
size_t INT_MAX;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
scalar_t__ realloc(int *, size_t);
int /*<<< orphan*/ stderr;
void Realloc(void **item, size_t newsize) {
  int *p = (int *)*item - 2;
  assert(*item != NULL);
  assert(newsize > 0 && newsize <= INT_MAX);
  assert(p[0] == 0x42);
  ;
  p = (int *)realloc(p, newsize + 2 * sizeof(int));
  ;
  if (!p) {
    fprintf(stderr, "Realloc(%ld) failed\n", (long)newsize);
    exit(1);
  }
  assert(p[0] == 0x42);
  p[1] = newsize;
  *item = &p[2];
}


x86 assembly (clang, -O0):
<Realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x19(%rbp)
jbe    1198 <Realloc+0x58>
mov    -0x10(%rbp),%rax
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%rax
setbe  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x42,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1050 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fc <Realloc+0xbc>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe13(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x42,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rcx
add    $0x8,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Realloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
mov    (%rdi),%rbx
lea    -0x8(%rbx),%r15
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
test   %r12,%r12
setne  %al
mov    0x2e78(%rip),%rcx
cmp    %r12,(%rcx)
setae  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x42,-0x8(%rbx)
sete   %dil
call   1030 <assert@plt>
lea    0x8(%r12),%rsi
mov    %r15,%rdi
call   1050 <realloc@plt>
test   %rax,%rax
je     11c9 <Realloc+0x89>
mov    %rax,%rbx
xor    %edi,%edi
cmpl   $0x42,(%rax)
sete   %dil
call   1030 <assert@plt>
mov    %r12d,0x4(%rbx)
add    $0x8,%rbx
mov    %rbx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
mov    %r12,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@INT_MAX = global i64 0
@stderr = global i32 0
@.str = [21 x i8] c"Realloc(%ld) failed\0A\00"
define void @Realloc(i8** %0, i64 %1) {
%3 = alloca i8**
%4 = alloca i64
%5 = alloca i32*
store i8** %0, i8*** %3
store i64 %1, i64* %4
%6 = load i8**, i8*** %3
%7 = load i8*, i8** %6
%8 = bitcast i8* %7 to i32*
%9 = getelementptr inbounds i32, i32* %8, i64 -2
store i32* %9, i32** %5
%10 = load i8**, i8*** %3
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i64, i64* %4
%16 = icmp ugt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i64, i64* %4
%19 = load i64, i64* @INT_MAX
%20 = icmp ule i64 %18, %19
br label %21
21: ; preds = %17, %2
%22 = phi i1 [ false, %2 ], [ %20, %17 ]
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i32*, i32** %5
%26 = getelementptr inbounds i32, i32* %25, i64 0
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, 66
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32*, i32** %5
%32 = load i64, i64* %4
%33 = add i64 %32, 8
%34 = call i64 @realloc(i32* %31, i64 %33)
%35 = inttoptr i64 %34 to i32*
store i32* %35, i32** %5
%36 = load i32*, i32** %5
%37 = icmp ne i32* %36, null
br i1 %37, label %43, label %38
38: ; preds = %21
%39 = load i32, i32* @stderr
%40 = load i64, i64* %4
%41 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %21
%44 = load i32*, i32** %5
%45 = getelementptr inbounds i32, i32* %44, i64 0
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, 66
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i64, i64* %4
%51 = trunc i64 %50 to i32
%52 = load i32*, i32** %5
%53 = getelementptr inbounds i32, i32* %52, i64 1
store i32 %51, i32* %53
%54 = load i32*, i32** %5
%55 = getelementptr inbounds i32, i32* %54, i64 2
%56 = bitcast i32* %55 to i8*
%57 = load i8**, i8*** %3
store i8* %56, i8** %57
ret void
}

LLVM IR (-O2):
@INT_MAX = global i64 0
@stderr = global i32 0
@.str = [21 x i8] c"Realloc(%ld) failed\0A\00"
define void @Realloc(i8** nocapture %0, i64 %1) {
%3 = load i8*, i8** %0
%4 = getelementptr inbounds i8, i8* %3, i64 -8
%5 = bitcast i8* %4 to i32*
%6 = icmp ne i8* %3, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp ne i64 %1, 0
%10 = load i64, i64* @INT_MAX
%11 = icmp uge i64 %10, %1
%12 = select i1 %9, i1 %11, i1 false
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 66
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = add i64 %1, 8
%20 = tail call i64 @realloc(i32* %5, i64 %19)
%21 = inttoptr i64 %20 to i32*
%22 = icmp eq i64 %20, 0
br i1 %22, label %23, label %27
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %1)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %2
%28 = load i32, i32* %21
%29 = icmp eq i32 %28, 66
%30 = zext i1 %29 to i32
%31 = tail call i32 @assert(i32 %30)
%32 = trunc i64 %1 to i32
%33 = getelementptr inbounds i32, i32* %21, i64 1
store i32 %32, i32* %33
%34 = getelementptr inbounds i32, i32* %21, i64 2
%35 = bitcast i8** %0 to i32**
store i32* %34, i32** %35
ret void
}