#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*/ free(void *);
void *malloc(int);
void *realloc(void *, int);
int main(void) {
  void *a;
  void *b;
  void *c;
  a = malloc(0);
  free(a);
  c = malloc(0);
  a = malloc(0);
  b = realloc(a, 0);
  free(b);
  a = malloc(0);
  b = realloc(a, 1);
  free(b);
  a = malloc(1);
  b = realloc(a, 0);
  free(b);
  free(c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %edi,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
xor    %edi,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %edi,%edi
call   1040 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1040 <malloc@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <realloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1040 <malloc@plt>
mov    %rax,%rdi
mov    $0x1,%esi
call   1050 <realloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <realloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @malloc(i32 0)
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = call i32 @free(i8* %5)
%7 = call i8* @malloc(i32 0)
store i8* %7, i8** %3
%8 = call i8* @malloc(i32 0)
store i8* %8, i8** %1
%9 = load i8*, i8** %1
%10 = call i8* @realloc(i8* %9, i32 0)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = call i32 @free(i8* %11)
%13 = call i8* @malloc(i32 0)
store i8* %13, i8** %1
%14 = load i8*, i8** %1
%15 = call i8* @realloc(i8* %14, i32 1)
store i8* %15, i8** %2
%16 = load i8*, i8** %2
%17 = call i32 @free(i8* %16)
%18 = call i8* @malloc(i32 1)
store i8* %18, i8** %1
%19 = load i8*, i8** %1
%20 = call i8* @realloc(i8* %19, i32 0)
store i8* %20, i8** %2
%21 = load i8*, i8** %2
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i8* @malloc(i32 0)
%2 = tail call i32 @free(i8* %1)
%3 = tail call i8* @malloc(i32 0)
%4 = tail call i8* @malloc(i32 0)
%5 = tail call i8* @realloc(i8* %4, i32 0)
%6 = tail call i32 @free(i8* %5)
%7 = tail call i8* @malloc(i32 0)
%8 = tail call i8* @realloc(i8* %7, i32 1)
%9 = tail call i32 @free(i8* %8)
%10 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%11 = tail call i8* @realloc(i8* %10, i32 0)
%12 = tail call i32 @free(i8* %11)
%13 = tail call i32 @free(i8* %3)
ret i32 0
}