#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 */
char *aligned_alloc(int, int);
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *realloc(char *, int);
char *reallocarray(char *, int, int);
void arrayIndexOutOfBounds() {
  char *pAlloc1 = aligned_alloc(8, 16);
  pAlloc1[15] = '\0';
  pAlloc1[16] = '1';
  free(pAlloc1);
  char *pAlloc2 = malloc(9);
  pAlloc2[8] = 'a';
  pAlloc2[9] = 'a';
  pAlloc2 = realloc(pAlloc2, 8);
  pAlloc2[7] = 'b';
  pAlloc2[8] = 0;
  pAlloc2 = realloc(pAlloc2, 20);
  pAlloc2[19] = 'b';
  pAlloc2[20] = 0;
  free(pAlloc2);
  char *pAlloc3 = calloc(2, 3);
  pAlloc3[5] = 'a';
  pAlloc3[6] = 1;
  pAlloc3 = reallocarray(pAlloc3, 3, 3);
  pAlloc3[8] = 'a';
  pAlloc3[9] = 1;
  free(pAlloc3);
}


x86 assembly (clang, -O0):
<arrayIndexOutOfBounds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x8,%edi
mov    $0x10,%esi
call   1080 <aligned_alloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,0xf(%rax)
mov    -0x8(%rbp),%rax
movb   $0x31,0x10(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x9,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x61,0x8(%rax)
mov    -0x10(%rbp),%rax
movb   $0x61,0x9(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x62,0x7(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x14,%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x62,0x13(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x14(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x2,%edi
mov    $0x3,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x61,0x5(%rax)
mov    -0x18(%rbp),%rax
movb   $0x1,0x6(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x3,%edx
mov    %edx,%esi
call   1040 <reallocarray@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x61,0x8(%rax)
mov    -0x18(%rbp),%rax
movb   $0x1,0x9(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrayIndexOutOfBounds>:
push   %rax
mov    $0x8,%edi
mov    $0x10,%esi
call   1080 <aligned_alloc@plt>
movw   $0x3100,0xf(%rax)
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x9,%edi
call   1060 <malloc@plt>
movw   $0x6161,0x8(%rax)
mov    %rax,%rdi
mov    $0x8,%esi
call   1070 <realloc@plt>
movw   $0x62,0x7(%rax)
mov    %rax,%rdi
mov    $0x14,%esi
call   1070 <realloc@plt>
movw   $0x62,0x13(%rax)
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x2,%edi
mov    $0x3,%esi
call   1050 <calloc@plt>
movw   $0x161,0x5(%rax)
mov    %rax,%rdi
mov    $0x3,%esi
mov    $0x3,%edx
call   1040 <reallocarray@plt>
movw   $0x161,0x8(%rax)
mov    %rax,%rdi
pop    %rax
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @arrayIndexOutOfBounds() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @aligned_alloc(i32 8, i32 16)
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = getelementptr inbounds i8, i8* %5, i64 15
store i8 0, i8* %6
%7 = load i8*, i8** %1
%8 = getelementptr inbounds i8, i8* %7, i64 16
store i8 49, i8* %8
%9 = load i8*, i8** %1
%10 = call i32 @free(i8* %9)
%11 = call i8* @malloc(i32 9)
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i64 8
store i8 97, i8* %13
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 9
store i8 97, i8* %15
%16 = load i8*, i8** %2
%17 = call i8* @realloc(i8* %16, i32 8)
store i8* %17, i8** %2
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i64 7
store i8 98, i8* %19
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 8
store i8 0, i8* %21
%22 = load i8*, i8** %2
%23 = call i8* @realloc(i8* %22, i32 20)
store i8* %23, i8** %2
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 19
store i8 98, i8* %25
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i64 20
store i8 0, i8* %27
%28 = load i8*, i8** %2
%29 = call i32 @free(i8* %28)
%30 = call i8* @calloc(i32 2, i32 3)
store i8* %30, i8** %3
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 5
store i8 97, i8* %32
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 6
store i8 1, i8* %34
%35 = load i8*, i8** %3
%36 = call i8* @reallocarray(i8* %35, i32 3, i32 3)
store i8* %36, i8** %3
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 8
store i8 97, i8* %38
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 9
store i8 1, i8* %40
%41 = load i8*, i8** %3
%42 = call i32 @free(i8* %41)
ret void
}

LLVM IR (-O2):
define void @arrayIndexOutOfBounds() {
%1 = tail call align 8 dereferenceable_or_null(16) i8* @aligned_alloc(i32 8, i32 16)
%2 = getelementptr inbounds i8, i8* %1, i64 15
store i8 0, i8* %2
%3 = getelementptr inbounds i8, i8* %1, i64 16
store i8 49, i8* %3
%4 = tail call i32 @free(i8* %1)
%5 = tail call dereferenceable_or_null(9) i8* @malloc(i32 9)
%6 = getelementptr inbounds i8, i8* %5, i64 8
store i8 97, i8* %6
%7 = getelementptr inbounds i8, i8* %5, i64 9
store i8 97, i8* %7
%8 = tail call i8* @realloc(i8* %5, i32 8)
%9 = getelementptr inbounds i8, i8* %8, i64 7
store i8 98, i8* %9
%10 = getelementptr inbounds i8, i8* %8, i64 8
store i8 0, i8* %10
%11 = tail call i8* @realloc(i8* %8, i32 20)
%12 = getelementptr inbounds i8, i8* %11, i64 19
store i8 98, i8* %12
%13 = getelementptr inbounds i8, i8* %11, i64 20
store i8 0, i8* %13
%14 = tail call i32 @free(i8* %11)
%15 = tail call dereferenceable_or_null(6) i8* @calloc(i32 2, i32 3)
%16 = getelementptr inbounds i8, i8* %15, i64 5
store i8 97, i8* %16
%17 = getelementptr inbounds i8, i8* %15, i64 6
store i8 1, i8* %17
%18 = tail call i8* @reallocarray(i8* %15, i32 3, i32 3)
%19 = getelementptr inbounds i8, i8* %18, i64 8
store i8 97, i8* %19
%20 = getelementptr inbounds i8, i8* %18, i64 9
store i8 1, i8* %20
%21 = tail call i32 @free(i8* %18)
ret void
}