#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(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int *, int);
scalar_t__ realloc(int *, int);
int main() {
  int *x = (int *)malloc(sizeof(int));
  *x = 2;
  printf("The address is %p and the value is %d\n", x, *x);
  x = (int *)realloc(x, sizeof(int) * 3);
  *(x + 1) = 3;
  *(x + 2) = 4;
  x[1] = 3;
  x[2] = 2;
  free(x);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0xc,%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x3,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0x4,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0x2,0x8(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movl   $0x2,(%rax)
lea    0xea5(%rip),%rdi
mov    %rax,%rsi
mov    $0x2,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1060 <realloc@plt>
movabs $0x200000003,%rcx
mov    %rcx,0x4(%rax)
mov    %rax,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [39 x i8] c"The address is %p and the value is %d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 4)
%2 = inttoptr i64 %1 to i32*
store i32 2, i32* %2
%3 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32* %2, i32 2)
%4 = tail call i64 @realloc(i32* %2, i32 12)
%5 = inttoptr i64 %4 to i32*
%6 = getelementptr inbounds i32, i32* %5, i64 1
%7 = getelementptr inbounds i32, i32* %5, i64 2
store i32 3, i32* %6
store i32 2, i32* %7
%8 = tail call i32 @free(i32* %5)
ret i32 0
}