#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*/ MCL_CURRENT;
int /*<<< orphan*/ alloc_mem(unsigned long);
int getpid();
int /*<<< orphan*/ mlockall(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned long *);
int main(int argc, char *argv[]) {
  int pid;
  unsigned long size;
  printf("pid : %d\n", getpid());
  mlockall(MCL_CURRENT);
  while (1) {
    printf("alloc size(# of pages): ");
    scanf("%lu", &size);
    if (size > 0) {
      size *= 4096;
      printf(" -> alloc %lu bytes\n", size);
      alloc_mem(size);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
call   1060 <mlockall@plt>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe83(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <scanf@plt>
cmpq   $0x0,-0x20(%rbp)
jbe    11db <main+0x8b>
mov    -0x20(%rbp),%rax
shl    $0xc,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <alloc_mem@plt>
jmp    118b <main+0x3b>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe9a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1060 <mlockall@plt>
lea    0xe86(%rip),%r14
lea    0xe98(%rip),%r15
mov    %rsp,%rbx
lea    0xe92(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%rsi
test   %rsi,%rsi
je     11a0 <main+0x50>
shl    $0xc,%rsi
mov    %rsi,(%rsp)
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%rdi
call   1030 <alloc_mem@plt>
jmp    11a0 <main+0x50>

LLVM IR (-O0):
@.str = [10 x i8] c"pid : %d\0A\00"
@MCL_CURRENT = global i32 0
@.str.1 = [25 x i8] c"alloc size(# of pages): \00"
@.str.2 = [4 x i8] c"%lu\00"
@.str.3 = [21 x i8] c" -> alloc %lu bytes\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @getpid()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @MCL_CURRENT
%11 = call i32 @mlockall(i32 %10)
br label %12
12: ; preds = %2, %24
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %7)
%15 = load i64, i64* %7
%16 = icmp ugt i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = load i64, i64* %7
%19 = mul i64 %18, 4096
store i64 %19, i64* %7
%20 = load i64, i64* %7
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i64 %20)
%22 = load i64, i64* %7
%23 = call i32 @alloc_mem(i64 %22)
br label %24
24: ; preds = %17, %12
br label %12
}

LLVM IR (-O2):
@.str = [10 x i8] c"pid : %d\0A\00"
@MCL_CURRENT = global i32 0
@.str.1 = [25 x i8] c"alloc size(# of pages): \00"
@.str.2 = [4 x i8] c"%lu\00"
@.str.3 = [21 x i8] c" -> alloc %lu bytes\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @MCL_CURRENT
%8 = tail call i32 @mlockall(i32 %7)
br label %9
9: ; preds = %19, %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %3)
%12 = load i64, i64* %3
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = shl i64 %12, 12
store i64 %15, i64* %3
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i64 %15)
%17 = load i64, i64* %3
%18 = call i32 @alloc_mem(i64 %17)
br label %19
19: ; preds = %14, %9
br label %9
}