#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 *);
int *malloc(int const);
int /*<<< orphan*/ printf(char *, int);
int main() {
  const int N = 1000;
  int *arr = malloc(N * sizeof(int));
  for (int i = 0; i < N; i++) {
    arr[i] = i + 1;
  }
  for (int i = 0; i < N; i++) {
    printf("%d\n", arr[i]);
  }
  free(arr);
  arr = 0;
  arr[4] = 7;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0x8(%rbp)
mov    $0xfa0,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jge    1187 <main+0x57>
mov    -0x14(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115b <main+0x2b>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3e8,-0x18(%rbp)
jge    11c0 <main+0x90>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118e <main+0x5e>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x7,0x10(%rax)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0xfa0,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
movaps 0xeb7(%rip),%xmm0
movaps 0xec0(%rip),%xmm1
mov    $0xc,%eax
pcmpeqd %xmm2,%xmm2
movdqa 0xebf(%rip),%xmm3
movdqa 0xec7(%rip),%xmm4
movdqa 0xecf(%rip),%xmm5
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movaps %xmm1,%xmm6
shufps $0x88,%xmm0,%xmm6
movaps %xmm6,%xmm7
psubd  %xmm2,%xmm7
paddd  %xmm3,%xmm6
movdqu %xmm7,-0x30(%r15,%rax,4)
movdqu %xmm6,-0x20(%r15,%rax,4)
cmp    $0x3ec,%rax
je     11e0 <main+0xb0>
movaps %xmm1,%xmm6
paddq  %xmm4,%xmm6
movaps %xmm0,%xmm7
paddq  %xmm4,%xmm7
shufps $0x88,%xmm7,%xmm6
movaps %xmm6,%xmm7
psubd  %xmm2,%xmm7
paddd  %xmm3,%xmm6
movdqu %xmm7,-0x10(%r15,%rax,4)
movdqu %xmm6,(%r15,%rax,4)
paddq  %xmm5,%xmm1
paddq  %xmm5,%xmm0
add    $0x10,%rax
jmp    1180 <main+0x50>
xor    %ebx,%ebx
lea    0xe67(%rip),%r14
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    11f0 <main+0xc0>
mov    %r15,%rdi
call   1030 <free@plt>
movl   $0x7,0x10
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1000, i32* %2
%6 = call i32* @malloc(i32 4000)
store i32* %6, i32** %3
store i32 0, i32* %4
br label %7
7: ; preds = %17, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 1000
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 1
%13 = load i32*, i32** %3
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
store i32 %12, i32* %16
br label %17
17: ; preds = %10
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %7
20: ; preds = %7
store i32 0, i32* %5
br label %21
21: ; preds = %31, %20
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 1000
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = load i32*, i32** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %24
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %21
34: ; preds = %21
%35 = load i32*, i32** %3
%36 = call i32 @free(i32* %35)
store i32* null, i32** %3
%37 = load i32*, i32** %3
%38 = getelementptr inbounds i32, i32* %37, i64 4
store i32 7, i32* %38
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 4000)
br label %2
2: ; preds = %16, %0
%3 = phi i64 [ 0, %0 ], [ %25, %16 ]
%4 = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %0 ], [ %26, %16 ]
%5 = getelementptr inbounds i32, i32* %1, i64 %3
%6 = trunc <4 x i64> %4 to <4 x i32>
%7 = add <4 x i32> %6, <i32 1, i32 1, i32 1, i32 1>
%8 = trunc <4 x i64> %4 to <4 x i32>
%9 = add <4 x i32> %8, <i32 5, i32 5, i32 5, i32 5>
%10 = bitcast i32* %5 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %5, i64 4
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> %9, <4 x i32>* %12
%13 = or i64 %3, 8
%14 = add <4 x i64> %4, <i64 8, i64 8, i64 8, i64 8>
%15 = icmp eq i64 %13, 1000
br i1 %15, label %29, label %16
16: ; preds = %2
%17 = getelementptr inbounds i32, i32* %1, i64 %13
%18 = trunc <4 x i64> %14 to <4 x i32>
%19 = add <4 x i32> %18, <i32 1, i32 1, i32 1, i32 1>
%20 = trunc <4 x i64> %14 to <4 x i32>
%21 = add <4 x i32> %20, <i32 5, i32 5, i32 5, i32 5>
%22 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> %19, <4 x i32>* %22
%23 = getelementptr inbounds i32, i32* %17, i64 4
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> %21, <4 x i32>* %24
%25 = add nuw nsw i64 %3, 16
%26 = add <4 x i64> %4, <i64 16, i64 16, i64 16, i64 16>
br label %2
27: ; preds = %29
%28 = tail call i32 @free(i32* %1)
store i32 7, i32* inttoptr (i64 16 to i32*)
ret i32 0
29: ; preds = %2, %29
%30 = phi i64 [ %34, %29 ], [ 0, %2 ]
%31 = getelementptr inbounds i32, i32* %1, i64 %30
%32 = load i32, i32* %31
%33 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = add nuw nsw i64 %30, 1
%35 = icmp eq i64 %34, 1000
br i1 %35, label %27, label %29
}