#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 main() {
  int *p;
  p = (int *)malloc(sizeof(int) * 10);
  printf("Now writing before our allocated array\n");
  p[-1] ^= 0x0F;
  printf("... and now after our allocated array\n");
  p[10] ^= 0x0F;
  printf("Did you notice?\n");
  free(p);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x4(%rax),%ecx
xor    $0xf,%ecx
mov    %ecx,-0x4(%rax)
lea    0xec2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x28(%rax),%ecx
xor    $0xf,%ecx
mov    %ecx,0x28(%rax)
lea    0xed0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xebb(%rip),%rdi
call   1040 <puts@plt>
xorb   $0xf,-0x4(%rbx)
lea    0xed2(%rip),%rdi
call   1040 <puts@plt>
xorb   $0xf,0x28(%rbx)
lea    0xee8(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Now writing before our allocated array\0A\00"
@.str.1 = [39 x i8] c"... and now after our allocated array\0A\00"
@.str.2 = [17 x i8] c"Did you notice?\0A\00"
define i32 @main() {
%1 = alloca i32*
%2 = call i64 @malloc(i32 40)
%3 = inttoptr i64 %2 to i32*
store i32* %3, i32** %1
%4 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%5 = load i32*, i32** %1
%6 = getelementptr inbounds i32, i32* %5, i64 -1
%7 = load i32, i32* %6
%8 = xor i32 %7, 15
store i32 %8, i32* %6
%9 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32*, i32** %1
%11 = getelementptr inbounds i32, i32* %10, i64 10
%12 = load i32, i32* %11
%13 = xor i32 %12, 15
store i32 %13, i32* %11
%14 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32*, i32** %1
%16 = call i32 @free(i32* %15)
ret i32 0
}

LLVM IR (-O2):
@str = [39 x i8] c"Now writing before our allocated array\00"
@str.3 = [38 x i8] c"... and now after our allocated array\00"
@str.4 = [16 x i8] c"Did you notice?\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 40)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%4 = getelementptr inbounds i32, i32* %2, i64 -1
%5 = load i32, i32* %4
%6 = xor i32 %5, 15
store i32 %6, i32* %4
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.3, i64 0, i64 0))
%8 = getelementptr inbounds i32, i32* %2, i64 10
%9 = load i32, i32* %8
%10 = xor i32 %9, 15
store i32 %10, i32* %8
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
%12 = tail call i32 @free(i32* %2)
ret i32 0
}