#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int *realloc(int *, int);
void realloc1() {
  int *p = (int *)malloc(sizeof(int *));
  printf("%d\n", *p);
  p = realloc(p, sizeof(int) * 3);
  p[1] = 20;
  printf("%d\n", *(p + 1));
  p[2] = 30;
  printf("%d\n", *(p + 2));
  printf("%d\n", *(p + 3));
}


x86 assembly (clang, -O0):
<realloc1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0xc,%esi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x14,0x4(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movl   $0x1e,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%esi
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realloc1>:
push   %r14
push   %rbx
push   %rax
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    (%rax),%esi
lea    0xeb6(%rip),%r14
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1050 <realloc@plt>
mov    %rax,%rbx
movl   $0x14,0x4(%rax)
mov    %r14,%rdi
mov    $0x14,%esi
call   1030 <printf@plt>
movl   $0x1e,0x8(%rbx)
mov    %r14,%rdi
mov    $0x1e,%esi
call   1030 <printf@plt>
mov    0xc(%rbx),%esi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define void @realloc1() {
%1 = alloca i32*
%2 = call i64 @malloc(i32 8)
%3 = inttoptr i64 %2 to i32*
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = load i32, i32* %4
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32*, i32** %1
%8 = call i32* @realloc(i32* %7, i32 12)
store i32* %8, i32** %1
%9 = load i32*, i32** %1
%10 = getelementptr inbounds i32, i32* %9, i64 1
store i32 20, i32* %10
%11 = load i32*, i32** %1
%12 = getelementptr inbounds i32, i32* %11, i64 1
%13 = load i32, i32* %12
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32*, i32** %1
%16 = getelementptr inbounds i32, i32* %15, i64 2
store i32 30, i32* %16
%17 = load i32*, i32** %1
%18 = getelementptr inbounds i32, i32* %17, i64 2
%19 = load i32, i32* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %1
%22 = getelementptr inbounds i32, i32* %21, i64 3
%23 = load i32, i32* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
ret void
}

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