#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 *ignore1();
int /*<<< orphan*/ ignore2(int *, int *);
int *malloc(int);
int *realloc(int *, int);
int main(void) {
  int *x;
  int *ignored_x;
  x = malloc(400);
  ignored_x = ignore1();
  x = realloc(x, 800);
  x = realloc(x, 400);
  ignored_x = realloc(ignored_x, 800);
  ignored_x = realloc(ignored_x, 400);
  ignore2(x, ignored_x);
  x = realloc(ignored_x, 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x190,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <ignore1@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x320,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x190,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x320,%esi
call   1050 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x190,%esi
call   1050 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <ignore2@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x190,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <ignore1@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x320,%esi
call   1050 <realloc@plt>
mov    %rax,%rdi
mov    $0x190,%esi
call   1050 <realloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x320,%esi
call   1050 <realloc@plt>
mov    %rax,%rdi
mov    $0x190,%esi
call   1050 <realloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <ignore2@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <realloc@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*
store i32 0, i32* %1
%4 = call i32* @malloc(i32 400)
store i32* %4, i32** %2
%5 = call i32* (...) @ignore1()
store i32* %5, i32** %3
%6 = load i32*, i32** %2
%7 = call i32* @realloc(i32* %6, i32 800)
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = call i32* @realloc(i32* %8, i32 400)
store i32* %9, i32** %2
%10 = load i32*, i32** %3
%11 = call i32* @realloc(i32* %10, i32 800)
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = call i32* @realloc(i32* %12, i32 400)
store i32* %13, i32** %3
%14 = load i32*, i32** %2
%15 = load i32*, i32** %3
%16 = call i32 @ignore2(i32* %14, i32* %15)
%17 = load i32*, i32** %3
%18 = call i32* @realloc(i32* %17, i32 0)
store i32* %18, i32** %2
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32* @malloc(i32 400)
%2 = tail call i32* (...) @ignore1()
%3 = tail call i32* @realloc(i32* %1, i32 800)
%4 = tail call i32* @realloc(i32* %3, i32 400)
%5 = tail call i32* @realloc(i32* %2, i32 800)
%6 = tail call i32* @realloc(i32* %5, i32 400)
%7 = tail call i32 @ignore2(i32* %4, i32* %6)
%8 = tail call i32* @realloc(i32* %6, i32 0)
ret i32 0
}