#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*/ assert(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strcmp(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
char *x_realloc(char *, int);
void realloc_test(void) {
  char *p = x_realloc(NULL, 100);
  assert(p != NULL);
  const char *test_string = "Hello, world!";
  strcpy(p, test_string);
  p = x_realloc(p, 2 * 100);
  assert(!strcmp(p, test_string));
  free(p);
}


x86 assembly (clang, -O0):
<realloc_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
mov    %eax,%edi
mov    $0x64,%esi
call   1070 <x_realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xe7d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    $0xc8,%esi
call   1070 <x_realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realloc_test>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
mov    $0x64,%esi
call   1070 <x_realloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
lea    0xe88(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    $0xc8,%esi
call   1070 <x_realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Hello, world!\00"
define void @realloc_test() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @x_realloc(i8* null, i32 100)
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = icmp ne i8* %4, null
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %2
%8 = load i8*, i8** %1
%9 = load i8*, i8** %2
%10 = call i32 @strcpy(i8* %8, i8* %9)
%11 = load i8*, i8** %1
%12 = call i8* @x_realloc(i8* %11, i32 200)
store i8* %12, i8** %1
%13 = load i8*, i8** %1
%14 = load i8*, i8** %2
%15 = call i32 @strcmp(i8* %13, i8* %14)
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i8*, i8** %1
%21 = call i32 @free(i8* %20)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"Hello, world!\00"
define void @realloc_test() {
%1 = tail call i8* @x_realloc(i8* null, i32 100)
%2 = icmp ne i8* %1, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = tail call i8* @x_realloc(i8* %1, i32 200)
%7 = tail call i32 @strcmp(i8* dereferenceable(1) %6, i8* dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @free(i8* %6)
ret void
}