#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 *malloc(int);
int /*<<< orphan*/ printf(char *, int *, int *, int *, int, int, int);
int *realloc(int *, int);
int main(void) {
  int *p = malloc(sizeof(int));
  int *q = realloc(p, sizeof(int));
  int *z = realloc(q, sizeof(int));
  *p = 1;
  *q = 2;
  *z = 3;
  if (p == q)
    printf("%p %p %p %d %d %d\n", p, q, z, *p, *q, *z);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1050 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x4,%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11cc <main+0x9c>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    (%rax),%r8d
mov    -0x18(%rbp),%rax
mov    (%rax),%r9d
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
lea    0xe3c(%rip),%rdi
mov    %eax,(%rsp)
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x4,%esi
call   1050 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x4,%esi
call   1050 <realloc@plt>
movl   $0x1,(%r14)
movl   $0x2,(%rbx)
movl   $0x3,(%rax)
cmp    %rbx,%r14
jne    1198 <main+0x68>
mov    (%r14),%r8d
movl   $0x3,(%rsp)
lea    0xe79(%rip),%rdi
mov    %r14,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
mov    %r8d,%r9d
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"%p %p %p %d %d %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32* @malloc(i32 4)
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = call i32* @realloc(i32* %6, i32 4)
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = call i32* @realloc(i32* %8, i32 4)
store i32* %9, i32** %4
%10 = load i32*, i32** %2
store i32 1, i32* %10
%11 = load i32*, i32** %3
store i32 2, i32* %11
%12 = load i32*, i32** %4
store i32 3, i32* %12
%13 = load i32*, i32** %2
%14 = load i32*, i32** %3
%15 = icmp eq i32* %13, %14
br i1 %15, label %16, label %27
16: ; preds = %0
%17 = load i32*, i32** %2
%18 = load i32*, i32** %3
%19 = load i32*, i32** %4
%20 = load i32*, i32** %2
%21 = load i32, i32* %20
%22 = load i32*, i32** %3
%23 = load i32, i32* %22
%24 = load i32*, i32** %4
%25 = load i32, i32* %24
%26 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %17, i32* %18, i32* %19, i32 %21, i32 %23, i32 %25)
br label %27
27: ; preds = %16, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"%p %p %p %d %d %d\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 4)
%2 = tail call i32* @realloc(i32* %1, i32 4)
%3 = tail call i32* @realloc(i32* %2, i32 4)
store i32 1, i32* %1
store i32 2, i32* %2
store i32 3, i32* %3
%4 = icmp eq i32* %1, %2
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %1, i32* %3, i32 %6, i32 %6, i32 3)
br label %8
8: ; preds = %5, %0
ret i32 0
}