#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(void) {
  int *array[5];
  for (int i = 0; i < 5; i++) {
    *(array + i) = (int *)malloc(sizeof(int));
    **(array + i) = i;
  }
  for (int i = 0; i < 5; i++) {
    printf("%d\n", *array[i]);
  }
  for (int i = 0; i < 5; i++) {
    free(array[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x5,-0x34(%rbp)
jge    1182 <main+0x52>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
mov    %rcx,-0x30(%rbp,%rax,8)
mov    -0x34(%rbp),%ecx
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1146 <main+0x16>
movl   $0x0,-0x38(%rbp)
cmpl   $0x5,-0x38(%rbp)
jge    11b8 <main+0x88>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rax
mov    (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1189 <main+0x59>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x5,-0x3c(%rbp)
jge    11e5 <main+0xb5>
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11bf <main+0x8f>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
movl   $0x0,(%rax)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
movl   $0x1,(%rax)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
movl   $0x2,(%rax)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r13
movl   $0x3,(%rax)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movl   $0x4,(%rax)
mov    (%r14),%esi
lea    0xe5c(%rip),%rbp
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    (%r15),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    (%r12),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    (%rbx),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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