#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 main() {
  int *p1 = (int *)malloc(sizeof(int));
  int *p2 = (int *)malloc(sizeof(int));
  *p1 = 1;
  *(p1 + 1) = 2;
  *(p1 + 2) = 3;
  *(p1 + 3) = 4;
  *(p1 + 4) = 5;
  *(p1 + 5) = 6;
  *(p1 + 6) = 7;
  *(p1 + 7) = 8;
  *(p1 + 8) = 9;
  free(p1);
  printf("p2 = %d\n", *p2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x2,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x4,0xc(%rax)
mov    -0x10(%rbp),%rax
movl   $0x5,0x10(%rax)
mov    -0x10(%rbp),%rax
movl   $0x6,0x14(%rax)
mov    -0x10(%rbp),%rax
movl   $0x7,0x18(%rax)
mov    -0x10(%rbp),%rax
movl   $0x8,0x1c(%rax)
mov    -0x10(%rbp),%rax
movl   $0x9,0x20(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
movaps 0xeab(%rip),%xmm0
movups %xmm0,(%rbx)
movaps 0xeb1(%rip),%xmm0
movups %xmm0,0x10(%rbx)
movl   $0x9,0x20(%rbx)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%r14),%esi
lea    0xea4(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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