#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int np, ps, i;
  printf("enter how many pages\n");
  scanf("%d", &np);
  printf("enter the page size \n");
  scanf("%d", &ps);
  int sa[np];
  for (i = 0; i < np; i++) {
    sa[i] = (int)malloc(ps);
    printf("page%d\t address %u\n", i + 1, sa[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x31(%rbp)
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
mov    %rdi,-0x30(%rbp)
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x31(%rbp),%al
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11fb <main+0xcb>
mov    -0xc(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %ecx,%edx
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%esi
add    $0x1,%esi
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ae <main+0x7e>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xea5(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
mov    %rsp,%r14
cmpl   $0x0,0x8(%rsp)
jle    11c0 <main+0x80>
lea    0xe71(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0xc(%rsp),%edi
call   1050 <malloc@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    0x8(%rsp),%ebp
jl     11a0 <main+0x60>
mov    %r14,%rsp
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"enter how many pages\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"enter the page size \0A\00"
@.str.3 = [20 x i8] c"page%d\09 address %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %2
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %5
%14 = alloca i32, i64 %12
store i64 %12, i64* %6
store i32 0, i32* %4
br label %15
15: ; preds = %33, %0
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = load i32, i32* %3
%21 = call i64 @malloc(i32 %20)
%22 = trunc i64 %21 to i32
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %14, i64 %24
store i32 %22, i32* %25
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %14, i64 %29
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %31)
br label %33
33: ; preds = %19
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %15
36: ; preds = %15
store i32 0, i32* %1
%37 = load i8*, i8** %5
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [20 x i8] c"page%d\09 address %u\0A\00"
@str = [21 x i8] c"enter how many pages\00"
@str.4 = [21 x i8] c"enter the page size \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.4, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = call i8* @llvm.stacksave()
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %0, %12
%13 = phi i32 [ %17, %12 ], [ 0, %0 ]
%14 = load i32, i32* %2
%15 = call i64 @malloc(i32 %14)
%16 = trunc i64 %15 to i32
%17 = add nuw nsw i32 %13, 1
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 %16)
%19 = load i32, i32* %1
%20 = icmp slt i32 %17, %19
br i1 %20, label %12, label %21
21: ; preds = %12, %0
ret i32 0
}