#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(int *);
int *malloc(int);
int *realloc(int *, int);
int main() {
  int *a = malloc(32);
  free(a);
  int *b = malloc(4);
  assert(a == b);
  *b = 373;
  int *c = realloc(b, 20);
  assert(b == c);
  assert(*c == 373);
  int *d = realloc(c, 40);
  assert(b != d);
  assert(*d == 373);
  free(d);
  int *e = realloc(NULL, sizeof *e);
  *e = 18962;
  assert(*e == 18962);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
movl   $0x175,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x14,%esi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rax
cmpl   $0x175,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    $0x28,%esi
call   1060 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x28(%rbp),%rax
cmpl   $0x175,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %eax,%edi
mov    $0x4,%esi
call   1060 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movl   $0x4a12,(%rax)
mov    -0x30(%rbp),%rax
cmpl   $0x4a12,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
xor    %edi,%edi
cmp    %rax,%r14
sete   %dil
call   1040 <assert@plt>
movl   $0x175,(%r15)
mov    %r15,%rdi
mov    $0x14,%esi
call   1060 <realloc@plt>
mov    %rax,%r14
xor    %edi,%edi
cmp    %rax,%r15
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpl   $0x175,(%r14)
sete   %dil
call   1040 <assert@plt>
mov    %r14,%rdi
mov    $0x28,%esi
call   1060 <realloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmp    %rax,%r15
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpl   $0x175,(%rbx)
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    $0x4,%esi
call   1060 <realloc@plt>
movl   $0x4a12,(%rax)
mov    $0x1,%edi
call   1040 <assert@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
store i32 0, i32* %1
%7 = call i32* @malloc(i32 32)
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = call i32 @free(i32* %8)
%10 = call i32* @malloc(i32 4)
store i32* %10, i32** %3
%11 = load i32*, i32** %2
%12 = load i32*, i32** %3
%13 = icmp eq i32* %11, %12
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32*, i32** %3
store i32 373, i32* %16
%17 = load i32*, i32** %3
%18 = call i32* @realloc(i32* %17, i32 20)
store i32* %18, i32** %4
%19 = load i32*, i32** %3
%20 = load i32*, i32** %4
%21 = icmp eq i32* %19, %20
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i32*, i32** %4
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, 373
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i32*, i32** %4
%30 = call i32* @realloc(i32* %29, i32 40)
store i32* %30, i32** %5
%31 = load i32*, i32** %3
%32 = load i32*, i32** %5
%33 = icmp ne i32* %31, %32
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32*, i32** %5
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, 373
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i32*, i32** %5
%42 = call i32 @free(i32* %41)
%43 = call i32* @realloc(i32* null, i32 4)
store i32* %43, i32** %6
%44 = load i32*, i32** %6
store i32 18962, i32* %44
%45 = load i32*, i32** %6
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, 18962
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32* @malloc(i32 32)
%2 = tail call i32 @free(i32* %1)
%3 = tail call i32* @malloc(i32 4)
%4 = icmp eq i32* %1, %3
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
store i32 373, i32* %3
%7 = tail call i32* @realloc(i32* %3, i32 20)
%8 = icmp eq i32* %3, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, 373
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32* @realloc(i32* %7, i32 40)
%16 = icmp ne i32* %3, %15
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = load i32, i32* %15
%20 = icmp eq i32 %19, 373
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = tail call i32 @free(i32* %15)
%24 = tail call i32* @realloc(i32* null, i32 4)
store i32 18962, i32* %24
%25 = tail call i32 @assert(i32 1)
ret i32 0
}