#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 *malloc(int);
int /*<<< orphan*/ printf(char *, int, int /*<<< orphan*/);
int main() {
  int *array = malloc(200 * sizeof(int));
  int *array_start = array;
  const int MAX = 10;
  for (int i = 0; i < MAX; i++) {
    printf("array[%d] => %d\n", i, *array_start++);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x320,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0xa,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jge    118b <main+0x6b>
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%edx
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1153 <main+0x33>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x320,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    (%rax),%edx
lea    0xec6(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    0x4(%rbx),%edx
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    0x8(%rbx),%edx
mov    %r14,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    0xc(%rbx),%edx
mov    %r14,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    0x10(%rbx),%edx
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    0x14(%rbx),%edx
mov    %r14,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
mov    0x18(%rbx),%edx
mov    %r14,%rdi
mov    $0x6,%esi
call   1030 <printf@plt>
mov    0x1c(%rbx),%edx
mov    %r14,%rdi
mov    $0x7,%esi
call   1030 <printf@plt>
mov    0x20(%rbx),%edx
mov    %r14,%rdi
mov    $0x8,%esi
call   1030 <printf@plt>
mov    0x24(%rbx),%edx
mov    %r14,%rdi
mov    $0x9,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [17 x i8] c"array[%d] => %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
%6 = call i32* @malloc(i32 800)
store i32* %6, i32** %2
%7 = load i32*, i32** %2
store i32* %7, i32** %3
store i32 10, i32* %4
store i32 0, i32* %5
br label %8
8: ; preds = %17, %0
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 10
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i32, i32* %5
%13 = load i32*, i32** %3
%14 = getelementptr inbounds i32, i32* %13, i32 1
store i32* %14, i32** %3
%15 = load i32, i32* %13
%16 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %15)
br label %17
17: ; preds = %11
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %8
20: ; preds = %8
%21 = load i32, i32* %1
ret i32 %21
}

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