#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*/ lru(size_t, size_t *, size_t);
int /*<<< orphan*/ printf(char *, size_t);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, size_t *);
int main() {
  size_t i, n_frame, pages[20], n_page;
  puts("Number of frames?");
  scanf(" %zu%*c", &n_frame);
  if (n_frame > 20)
    n_frame = 20;
  putchar('\n');
  puts("Number of pages?");
  scanf(" %zu%*c", &n_page);
  if (n_page > 20)
    n_page = 20;
  putchar('\n');
  printf("%zu pages?\n", n_page);
  for (i = 0; i < n_page; ++i)
    scanf(" %zu%*c", pages + i);
  putchar('\n');
  lru(n_frame, pages, n_page);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9d(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <scanf@plt>
cmpq   $0x14,-0x18(%rbp)
jbe    1191 <main+0x41>
movq   $0x14,-0x18(%rbp)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe78(%rip),%rdi
call   1040 <puts@plt>
lea    0xe64(%rip),%rdi
lea    -0xc8(%rbp),%rsi
call   1070 <scanf@plt>
cmpq   $0x14,-0xc8(%rbp)
14
jbe    11d3 <main+0x83>
movq   $0x14,-0xc8(%rbp)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0xc8(%rbp),%rsi
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0xc8(%rbp),%rax
jae    1238 <main+0xe8>
lea    -0xc0(%rbp),%rsi
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xdf0(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11f8 <main+0xa8>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
mov    -0xc8(%rbp),%rdx
call   1060 <lru@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xb0,%rsp
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
lea    0xea3(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <scanf@plt>
cmpq   $0x15,0x8(%rsp)
jb     118a <main+0x3a>
movq   $0x14,0x8(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe7f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6b(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
cmpq   $0x15,(%rsp)
jb     11be <main+0x6e>
movq   $0x14,(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%rsp),%rsi
lea    0xe58(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,(%rsp)
je     1209 <main+0xb9>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe25(%rip),%r14
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
add    $0x1,%rbx
add    $0x8,%r15
cmp    (%rsp),%rbx
jb     11f0 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rdx
lea    0x10(%rsp),%rsi
call   1060 <lru@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Number of frames?\00"
@.str.1 = [8 x i8] c" %zu%*c\00"
@.str.2 = [17 x i8] c"Number of pages?\00"
@.str.3 = [12 x i8] c"%zu pages?\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca [20 x i64]
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%8 = load i64, i64* %3
%9 = icmp ugt i64 %8, 20
br i1 %9, label %10, label %11
10: ; preds = %0
store i64 20, i64* %3
br label %11
11: ; preds = %10, %0
%12 = call i32 @putchar(i8 signext 10)
%13 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64* %5)
%15 = load i64, i64* %5
%16 = icmp ugt i64 %15, 20
br i1 %16, label %17, label %18
17: ; preds = %11
store i64 20, i64* %5
br label %18
18: ; preds = %17, %11
%19 = call i32 @putchar(i8 signext 10)
%20 = load i64, i64* %5
%21 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 %20)
store i64 0, i64* %2
br label %22
22: ; preds = %31, %18
%23 = load i64, i64* %2
%24 = load i64, i64* %5
%25 = icmp ult i64 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = getelementptr inbounds [20 x i64], [20 x i64]* %4, i64 0, i64 0
%28 = load i64, i64* %2
%29 = getelementptr inbounds i64, i64* %27, i64 %28
%30 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64* %29)
br label %31
31: ; preds = %26
%32 = load i64, i64* %2
%33 = add i64 %32, 1
store i64 %33, i64* %2
br label %22
34: ; preds = %22
%35 = call i32 @putchar(i8 signext 10)
%36 = load i64, i64* %3
%37 = getelementptr inbounds [20 x i64], [20 x i64]* %4, i64 0, i64 0
%38 = load i64, i64* %5
%39 = call i32 @lru(i64 %36, i64* %37, i64 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Number of frames?\00"
@.str.1 = [8 x i8] c" %zu%*c\00"
@.str.2 = [17 x i8] c"Number of pages?\00"
@.str.3 = [12 x i8] c"%zu pages?\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [20 x i64]
%3 = alloca i64
%4 = bitcast i64* %1 to i8*
%5 = bitcast [20 x i64]* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%9 = load i64, i64* %1
%10 = icmp ugt i64 %9, 20
br i1 %10, label %11, label %12
11: ; preds = %0
store i64 20, i64* %1
br label %12
12: ; preds = %11, %0
%13 = call i32 @putchar(i8 signext 10)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%16 = load i64, i64* %3
%17 = icmp ugt i64 %16, 20
br i1 %17, label %18, label %19
18: ; preds = %12
store i64 20, i64* %3
br label %19
19: ; preds = %18, %12
%20 = call i32 @putchar(i8 signext 10)
%21 = load i64, i64* %3
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 %21)
%23 = load i64, i64* %3
%24 = icmp eq i64 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %19, %25
%26 = phi i64 [ %29, %25 ], [ 0, %19 ]
%27 = getelementptr inbounds [20 x i64], [20 x i64]* %2, i64 0, i64 %26
%28 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64* %27)
%29 = add nuw i64 %26, 1
%30 = load i64, i64* %3
%31 = icmp ult i64 %29, %30
br i1 %31, label %25, label %32
32: ; preds = %25, %19
%33 = call i32 @putchar(i8 signext 10)
%34 = load i64, i64* %1
%35 = getelementptr inbounds [20 x i64], [20 x i64]* %2, i64 0, i64 0
%36 = load i64, i64* %3
%37 = call i32 @lru(i64 %34, i64* %35, i64 %36)
ret i32 0
}