#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 */
void *atoi(char *);
char *calloc(long long, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fread(char **, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  if (argc < 3) {
    fprintf(stderr,
            "Usage uksm_tease page_size number_of_pages < /dev/urandom\n");
    return 1;
  }
  size_t page_size = atoi(argv[1]);
  long long int number_of_pages = atoi(argv[2]);
  char buf[page_size];
  fread(&buf, 1, page_size, stdin);
  char *a = calloc(number_of_pages, page_size);
  if (!a) {
    perror("calloc");
    return 1;
  }
  int i;
  for (i = 0; i < number_of_pages; ++i) {
    memcpy(a + page_size * i, buf, page_size);
  }
  printf("finished\n");
  for (;;) {
    sleep(3600);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11c1 <main+0x41>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ba <main+0x13a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdx
mov    0x2dd3(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    125c <main+0xdc>
lea    0xdf7(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
jmp    12ba <main+0x13a>
movl   $0x0,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    129f <main+0x11f>
mov    -0x48(%rbp),%rsi
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
imul   %rcx,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
call   1070 <memcpy@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1263 <main+0xe3>
lea    0xd9c(%rip),%rdi
call   1040 <printf@plt>
mov    $0xe10,%edi
call   10a0 <sleep@plt>
jmp    12ab <main+0x12b>
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     11bc <main+0x3c>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %rax,%r12
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %rax,%r15
mov    %rsp,%rbx
mov    %rsp,%r14
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x2df5(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
call   1040 <fread@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <calloc@plt>
test   %rax,%rax
je     126c <main+0xec>
test   %r15,%r15
jle    1247 <main+0xc7>
mov    %rax,%r13
cmp    $0x2,%r15
mov    $0x1,%ebx
cmovge %r15,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1070 <memcpy@plt>
add    %r12,%r13
add    $0xffffffffffffffff,%rbx
jne    1230 <main+0xb0>
lea    0xdf4(%rip),%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xe10,%edi
call   10a0 <sleep@plt>
jmp    1260 <main+0xe0>
lea    0xdc8(%rip),%rdi
call   1080 <perror@plt>
mov    %rbx,%rsp
jmp    11a8 <main+0x28>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [59 x i8] c"Usage uksm_tease page_size number_of_pages < /dev/urandom\0A\00"
@stdin = global i32 0
@.str.1 = [7 x i8] c"calloc\00"
@.str.2 = [10 x i8] c"finished\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %65
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i8* @atoi(i8* %20)
%22 = ptrtoint i8* %21 to i64
store i64 %22, i64* %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i8* @atoi(i8* %25)
%27 = ptrtoint i8* %26 to i64
store i64 %27, i64* %7
%28 = load i64, i64* %6
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %8
%30 = alloca i8, i64 %28
store i64 %28, i64* %9
%31 = bitcast i8* %30 to i8**
%32 = load i64, i64* %6
%33 = load i32, i32* @stdin
%34 = call i32 @fread(i8** %31, i32 1, i64 %32, i32 %33)
%35 = load i64, i64* %7
%36 = load i64, i64* %6
%37 = call i8* @calloc(i64 %35, i64 %36)
store i8* %37, i8** %10
%38 = load i8*, i8** %10
%39 = icmp ne i8* %38, null
br i1 %39, label %43, label %40
40: ; preds = %17
%41 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
%42 = load i8*, i8** %8
br label %65
43: ; preds = %17
store i32 0, i32* %11
br label %44
44: ; preds = %58, %43
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = load i64, i64* %7
%48 = icmp slt i64 %46, %47
br i1 %48, label %49, label %61
49: ; preds = %44
%50 = load i8*, i8** %10
%51 = load i64, i64* %6
%52 = load i32, i32* %11
%53 = sext i32 %52 to i64
%54 = mul i64 %51, %53
%55 = getelementptr inbounds i8, i8* %50, i64 %54
%56 = load i64, i64* %6
%57 = call i32 @memcpy(i8* %55, i8* %30, i64 %56)
br label %58
58: ; preds = %49
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 1
store i32 %60, i32* %11
br label %44
61: ; preds = %44
%62 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %63
63: ; preds = %63, %61
%64 = call i32 @sleep(i32 3600)
br label %63
65: ; preds = %40, %14
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [59 x i8] c"Usage uksm_tease page_size number_of_pages < /dev/urandom\0A\00"
@stdin = global i32 0
@.str.1 = [7 x i8] c"calloc\00"
@str = [9 x i8] c"finished\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
br label %40
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i8* @atoi(i8* %9)
%11 = ptrtoint i8* %10 to i64
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i8* @atoi(i8* %13)
%15 = ptrtoint i8* %14 to i64
%16 = tail call i8* @llvm.stacksave()
%17 = alloca i8, i64 %11
%18 = bitcast i8* %17 to i8**
%19 = load i32, i32* @stdin
%20 = call i32 @fread(i8** %18, i32 1, i64 %11, i32 %19)
%21 = call i8* @calloc(i64 %15, i64 %11)
%22 = icmp eq i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %7
%24 = icmp sgt i8* %14, null
br i1 %24, label %25, label %36
25: ; preds = %23
%26 = call i64 @llvm.smax.i64(i64 %15, i64 1)
br label %29
27: ; preds = %7
%28 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %40
29: ; preds = %25, %29
%30 = phi i64 [ 0, %25 ], [ %34, %29 ]
%31 = mul i64 %30, %11
%32 = getelementptr inbounds i8, i8* %21, i64 %31
%33 = call i32 @memcpy(i8* %32, i8* %17, i64 %11)
%34 = add nuw nsw i64 %30, 1
%35 = icmp eq i64 %34, %26
br i1 %35, label %36, label %29
36: ; preds = %29, %23
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %38, %36
%39 = call i32 @sleep(i32 3600)
br label %38
40: ; preds = %27, %4
ret i32 1
}