#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 *calloc(int, int);
int /*<<< orphan*/ free(int *);
int getpagesize();
int *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
void memory() {
  int *p, *q;
  printf("pagesize = %d\n", getpagesize());
  if ((p = calloc(sizeof(int), 10)) == NULL) {
    perror("calloc");
  }
  if ((q = malloc(sizeof(int) * 10)) == NULL) {
    perror("malloc");
  }
  int i;
  printf("calloc\n");
  for (i = 0; i < 10; ++i) {
    printf("%d\t", p[i]);
  }
  printf("malloc\n");
  for (i = 0; i < 10; ++i) {
    printf("%d\t", p[i]);
  }
  free(p);
  free(q);
  sleep(1);
}


x86 assembly (clang, -O0):
<memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1080 <getpagesize@plt>
mov    %eax,%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x4,%edi
mov    $0xa,%esi
call   1050 <calloc@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11b8 <memory+0x48>
lea    0xe5c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11dc <memory+0x6c>
lea    0xe3f(%rip),%rdi
call   1070 <perror@plt>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1222 <memory+0xb2>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f1 <memory+0x81>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1268 <memory+0xf8>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1237 <memory+0xc7>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1090 <getpagesize@plt>
lea    0xe64(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x4,%edi
mov    $0xa,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1342 <memory+0x1c2>
mov    $0x28,%edi
call   1070 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1353 <memory+0x1d3>
lea    0xe34(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%esi
lea    0xe22(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%esi
mov    %esi,0xc(%rsp)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rbx),%esi
mov    %esi,0x8(%rsp)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%esi
mov    %esi,0x4(%rsp)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rbx),%esi
mov    %esi,(%rsp)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rbx),%r12d
mov    %r15,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x1c(%rbx),%r13d
mov    %r15,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rbx),%ebp
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x24(%rbx),%r14d
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd8a(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    0xc(%rsp),%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    0x8(%rsp),%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    0x4(%rsp),%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    (%rsp),%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <sleep@plt>
lea    0xcca(%rip),%rdi
call   1080 <perror@plt>
jmp    11c0 <memory+0x40>
lea    0xcc0(%rip),%rdi
call   1080 <perror@plt>
jmp    11d8 <memory+0x58>

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

LLVM IR (-O2):
@.str = [15 x i8] c"pagesize = %d\0A\00"
@.str.4 = [4 x i8] c"%d\09\00"
@str = [7 x i8] c"calloc\00"
@str.6 = [7 x i8] c"malloc\00"
define void @memory() {
%1 = tail call i32 (...) @getpagesize()
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32* @calloc(i32 4, i32 10)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i32* @malloc(i32 40)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.6, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%14 = load i32, i32* %3
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds i32, i32* %3, i64 1
%17 = load i32, i32* %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds i32, i32* %3, i64 2
%20 = load i32, i32* %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds i32, i32* %3, i64 3
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds i32, i32* %3, i64 4
%26 = load i32, i32* %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds i32, i32* %3, i64 5
%29 = load i32, i32* %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds i32, i32* %3, i64 6
%32 = load i32, i32* %31
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds i32, i32* %3, i64 7
%35 = load i32, i32* %34
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds i32, i32* %3, i64 8
%38 = load i32, i32* %37
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds i32, i32* %3, i64 9
%41 = load i32, i32* %40
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.6, i64 0, i64 0))
%44 = load i32, i32* %3
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %16
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%56 = tail call i32 @free(i32* %3)
%57 = tail call i32 @free(i32* %8)
%58 = tail call i32 @sleep(i32 1)
ret void
}