#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*/ DumpArray(int *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int idx = 0;
  int *pIntArray = NULL;
  printf("NULL pointer to array -->\n");
  DumpArray(pIntArray, 10);
  pIntArray = (int *)malloc(10 * sizeof(int));
  if (pIntArray == NULL) {
    fprintf(stderr, "Out of memory error, could not allocate %d integers", 10);
    return 1;
  }
  printf("Allocated array -->\n");
  DumpArray(pIntArray, 10);
  memset(pIntArray, 0, sizeof(int) * 10);
  printf("Intiialised array -->\n");
  DumpArray(pIntArray, 10);
  for (idx = 0; idx < 10; ++idx) {
    pIntArray[idx] = idx * 10;
  }
  printf("Populated array -->\n");
  DumpArray(pIntArray, 10);
  for (idx = 0; idx < 10; ++idx) {
    int *pItem = pIntArray + idx;
    int item = (*pItem);
    item /= 2;
    (*pItem) = item;
  }
  printf("Modified array -->\n");
  DumpArray(pIntArray, 10);
  free(pIntArray);
  printf("Freed array (DANGEROUS) -->\n");
  DumpArray(pIntArray, 10);
  pIntArray = NULL;
  printf("NULL pointer to array -->\n");
  DumpArray(pIntArray, 10);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
mov    $0x28,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11de <main+0x7e>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
mov    $0xa,%edx
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1322 <main+0x1c2>
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1250 <main+0xf0>
imul   $0xa,-0x14(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1229 <main+0xc9>
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    12bc <main+0x15c>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1271 <main+0x111>
lea    0xdcd(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xdbe(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
movq   $0x0,-0x20(%rbp)
lea    0xcf8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xf56(%rip),%rdi
call   1040 <puts@plt>
xor    %r14d,%r14d
xor    %edi,%edi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
mov    $0x28,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     12ba <main+0x15a>
mov    %rax,%rbx
lea    0xeb8(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    0xea4(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
movaps 0xe23(%rip),%xmm0
movups %xmm0,(%rbx)
movaps 0xe29(%rip),%xmm0
movups %xmm0,0x10(%rbx)
movabs $0x5a00000050,%rax
mov    %rax,0x20(%rbx)
lea    0xe7e(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
movdqu (%rbx),%xmm0
movdqu 0x10(%rbx),%xmm1
movdqa %xmm0,%xmm2
psrld  $0x1f,%xmm2
paddd  %xmm0,%xmm2
psrad  $0x1,%xmm2
movdqu %xmm2,(%rbx)
movdqa %xmm1,%xmm0
psrld  $0x1f,%xmm0
paddd  %xmm1,%xmm0
psrad  $0x1,%xmm0
movdqu %xmm0,0x10(%rbx)
mov    0x20(%rbx),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    %ecx,0x20(%rbx)
mov    0x24(%rbx),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    %ecx,0x24(%rbx)
lea    0xe25(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe17(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
lea    0xe1a(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
mov    $0xa,%esi
call   1060 <DumpArray@plt>
jmp    12da <main+0x17a>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
lea    0xd56(%rip),%rsi
mov    $0xa,%edx
call   1070 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"NULL pointer to array -->\0A\00"
@stderr = global i32 0
@.str.1 = [52 x i8] c"Out of memory error, could not allocate %d integers\00"
@.str.2 = [21 x i8] c"Allocated array -->\0A\00"
@.str.3 = [23 x i8] c"Intiialised array -->\0A\00"
@.str.4 = [21 x i8] c"Populated array -->\0A\00"
@.str.5 = [20 x i8] c"Modified array -->\0A\00"
@.str.6 = [29 x i8] c"Freed array (DANGEROUS) -->\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32* null, i32** %7
%10 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = load i32*, i32** %7
%12 = call i32 @DumpArray(i32* %11, i32 10)
%13 = call i64 @malloc(i32 40)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %7
%15 = load i32*, i32** %7
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 10)
store i32 1, i32* %3
br label %75
20: ; preds = %2
%21 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32*, i32** %7
%23 = call i32 @DumpArray(i32* %22, i32 10)
%24 = load i32*, i32** %7
%25 = call i32 @memset(i32* %24, i32 0, i32 40)
%26 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32*, i32** %7
%28 = call i32 @DumpArray(i32* %27, i32 10)
store i32 0, i32* %6
br label %29
29: ; preds = %39, %20
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 10
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = load i32, i32* %6
%34 = mul nsw i32 %33, 10
%35 = load i32*, i32** %7
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
store i32 %34, i32* %38
br label %39
39: ; preds = %32
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %29
42: ; preds = %29
%43 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%44 = load i32*, i32** %7
%45 = call i32 @DumpArray(i32* %44, i32 10)
store i32 0, i32* %6
br label %46
46: ; preds = %60, %42
%47 = load i32, i32* %6
%48 = icmp slt i32 %47, 10
br i1 %48, label %49, label %63
49: ; preds = %46
%50 = load i32*, i32** %7
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
store i32* %53, i32** %8
%54 = load i32*, i32** %8
%55 = load i32, i32* %54
store i32 %55, i32* %9
%56 = load i32, i32* %9
%57 = sdiv i32 %56, 2
store i32 %57, i32* %9
%58 = load i32, i32* %9
%59 = load i32*, i32** %8
store i32 %58, i32* %59
br label %60
60: ; preds = %49
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %46
63: ; preds = %46
%64 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%65 = load i32*, i32** %7
%66 = call i32 @DumpArray(i32* %65, i32 10)
%67 = load i32*, i32** %7
%68 = call i32 @free(i32* %67)
%69 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%70 = load i32*, i32** %7
%71 = call i32 @DumpArray(i32* %70, i32 10)
store i32* null, i32** %7
%72 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%73 = load i32*, i32** %7
%74 = call i32 @DumpArray(i32* %73, i32 10)
store i32 0, i32* %3
br label %75
75: ; preds = %63, %17
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.1 = [52 x i8] c"Out of memory error, could not allocate %d integers\00"
@str.7 = [20 x i8] c"Allocated array -->\00"
@str.8 = [22 x i8] c"Intiialised array -->\00"
@str.9 = [20 x i8] c"Populated array -->\00"
@str.10 = [19 x i8] c"Modified array -->\00"
@str.11 = [28 x i8] c"Freed array (DANGEROUS) -->\00"
@str.12 = [26 x i8] c"NULL pointer to array -->\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.12, i64 0, i64 0))
%4 = tail call i32 @DumpArray(i32* null, i32 10)
%5 = tail call i64 @malloc(i32 40)
%6 = inttoptr i64 %5 to i32*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 10)
br label %43
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.7, i64 0, i64 0))
%13 = tail call i32 @DumpArray(i32* %6, i32 10)
%14 = tail call i32 @memset(i32* %6, i32 0, i32 40)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
%16 = tail call i32 @DumpArray(i32* %6, i32 10)
%17 = inttoptr i64 %5 to <4 x i32>*
store <4 x i32> <i32 0, i32 10, i32 20, i32 30>, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %6, i64 4
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> <i32 40, i32 50, i32 60, i32 70>, <4 x i32>* %19
%20 = getelementptr inbounds i32, i32* %6, i64 8
store i32 80, i32* %20
%21 = getelementptr inbounds i32, i32* %6, i64 9
store i32 90, i32* %21
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.9, i64 0, i64 0))
%23 = tail call i32 @DumpArray(i32* %6, i32 10)
%24 = inttoptr i64 %5 to <4 x i32>*
%25 = load <4 x i32>, <4 x i32>* %24
%26 = sdiv <4 x i32> %25, <i32 2, i32 2, i32 2, i32 2>
%27 = inttoptr i64 %5 to <4 x i32>*
store <4 x i32> %26, <4 x i32>* %27
%28 = bitcast i32* %18 to <4 x i32>*
%29 = load <4 x i32>, <4 x i32>* %28
%30 = sdiv <4 x i32> %29, <i32 2, i32 2, i32 2, i32 2>
%31 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %30, <4 x i32>* %31
%32 = load i32, i32* %20
%33 = sdiv i32 %32, 2
store i32 %33, i32* %20
%34 = load i32, i32* %21
%35 = sdiv i32 %34, 2
store i32 %35, i32* %21
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.10, i64 0, i64 0))
%37 = tail call i32 @DumpArray(i32* %6, i32 10)
%38 = tail call i32 @free(i32* %6)
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.11, i64 0, i64 0))
%40 = tail call i32 @DumpArray(i32* %6, i32 10)
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.12, i64 0, i64 0))
%42 = tail call i32 @DumpArray(i32* null, i32 10)
br label %43
43: ; preds = %11, %8
%44 = phi i32 [ 1, %8 ], [ 0, %11 ]
ret i32 %44
}