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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    119b <main+0x6b>
mov    -0x14(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115b <main+0x2b>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 @malloc(i32 20)
%5 = inttoptr i64 %4 to i32*
store i32* %5, i32** %2
store i32 0, i32* %3
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 = load i32, i32* %3
%11 = add nsw i32 %10, 1
%12 = load i32*, i32** %2
%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** %2
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
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
%26 = load i32*, i32** %2
%27 = call i32 @free(i32* %26)
ret i32 0
}

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