#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 *realloc(int *, int);
int main(void) {
  int *a = malloc(10 * sizeof(int));
  int *b = a;
  b[0] = 1;
  a = realloc(a, 1000 * sizeof(int));
  int *c = malloc(10 * sizeof(int));
  c[0] = 2;
  printf("%d, %d, %d\n", a[0], b[0], c[0]);
  b[0] = 3;
  printf("%d, %d, %d\n", a[0], b[0], c[0]);
  printf("a = %p\n", a);
  printf("b = %p\n", b);
  printf("c = %p\n", c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x28,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0xfa0,%esi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x28,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x28,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movl   $0x1,(%rax)
mov    %rax,%rdi
mov    $0xfa0,%esi
call   1050 <realloc@plt>
mov    %rax,%r15
mov    $0x28,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
movl   $0x2,(%rax)
mov    (%r15),%esi
mov    (%rbx),%edx
lea    0xe86(%rip),%r12
mov    %r12,%rdi
mov    $0x2,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0x3,(%rbx)
mov    (%r15),%esi
mov    %r12,%rdi
mov    $0x3,%edx
mov    $0x2,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe5f(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe56(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d, %d, %d\0A\00"
@.str.1 = [8 x i8] c"a = %p\0A\00"
@.str.2 = [8 x i8] c"b = %p\0A\00"
@.str.3 = [8 x i8] c"c = %p\0A\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i32*
%4 = call i32* @malloc(i32 40)
store i32* %4, i32** %1
%5 = load i32*, i32** %1
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = getelementptr inbounds i32, i32* %6, i64 0
store i32 1, i32* %7
%8 = load i32*, i32** %1
%9 = call i32* @realloc(i32* %8, i32 4000)
store i32* %9, i32** %1
%10 = call i32* @malloc(i32 40)
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = getelementptr inbounds i32, i32* %11, i64 0
store i32 2, i32* %12
%13 = load i32*, i32** %1
%14 = getelementptr inbounds i32, i32* %13, i64 0
%15 = load i32, i32* %14
%16 = load i32*, i32** %2
%17 = getelementptr inbounds i32, i32* %16, i64 0
%18 = load i32, i32* %17
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i64 0
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %18, i32 %21)
%23 = load i32*, i32** %2
%24 = getelementptr inbounds i32, i32* %23, i64 0
store i32 3, i32* %24
%25 = load i32*, i32** %1
%26 = getelementptr inbounds i32, i32* %25, i64 0
%27 = load i32, i32* %26
%28 = load i32*, i32** %2
%29 = getelementptr inbounds i32, i32* %28, i64 0
%30 = load i32, i32* %29
%31 = load i32*, i32** %3
%32 = getelementptr inbounds i32, i32* %31, i64 0
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %30, i32 %33)
%35 = load i32*, i32** %1
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %35)
%37 = load i32*, i32** %2
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* %37)
%39 = load i32*, i32** %3
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d, %d, %d\0A\00"
@.str.1 = [8 x i8] c"a = %p\0A\00"
@.str.2 = [8 x i8] c"b = %p\0A\00"
@.str.3 = [8 x i8] c"c = %p\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 40)
store i32 1, i32* %1
%2 = tail call i32* @realloc(i32* %1, i32 4000)
%3 = tail call i32* @malloc(i32 40)
store i32 2, i32* %3
%4 = load i32, i32* %2
%5 = load i32, i32* %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5, i32 2)
store i32 3, i32* %1
%7 = load i32, i32* %2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7, i32 3, i32 2)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* %3)
ret i32 0
}