#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 *, ...);
int main() {
  int i;
  int size = 4 * 4096;
  int *p = malloc(size * sizeof(int));
  printf("Allocate %d ints at %p\n", size, p);
  for (i = 4096; i < size; i++) {
    p[i] = i;
    if (i % 1024 == 0)
      printf("p[%d] at %p is %d\n", i, &p[i], p[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4000,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1000,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d1 <main+0xb1>
mov    -0x8(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11be <main+0x9e>
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c3 <main+0xa3>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1165 <main+0x45>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x10000,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xec7(%rip),%rdi
mov    $0x4000,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x4000,%r14
mov    $0x1000,%ebx
lea    0xebd(%rip),%r15
jmp    1171 <main+0x51>
nopl   (%rax)
add    $0x1,%rbx
add    $0x4,%r14
cmp    $0x4000,%rbx
je     118f <main+0x6f>
mov    %ebx,(%r14)
test   $0x3ff,%ebx
jne    1160 <main+0x40>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1160 <main+0x40>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [24 x i8] c"Allocate %d ints at %p\0A\00"
@.str.1 = [19 x i8] c"p[%d] at %p is %d\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 65536)
%2 = tail call i32 (i8*, i32, i32*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 16384, i32* %1)
br label %3
3: ; preds = %0, %11
%4 = phi i64 [ 4096, %0 ], [ %12, %11 ]
%5 = getelementptr inbounds i32, i32* %1, i64 %4
%6 = trunc i64 %4 to i32
store i32 %6, i32* %5
%7 = and i32 %6, 1023
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 (i8*, i32, i32*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32* %5, i32 %6)
br label %11
11: ; preds = %3, %9
%12 = add nuw nsw i64 %4, 1
%13 = icmp eq i64 %12, 16384
br i1 %13, label %14, label %3
14: ; preds = %11
ret i32 0
}