#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*/ FIFOSimulate(int *, int *);
int /*<<< orphan*/ LRUSimulate(int *, int *);
int /*<<< orphan*/ getch();
int /*<<< orphan*/ initSegments();
int /*<<< orphan*/ printf(char *, int);
int random_400();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
main() {
  initSegments();
  srand(time(0));
  int FIFO_pf = 0, LRU_pf = 0;
  int node_numbers[100], page_numbers[100], i;
  for (i = 0; i < 100; ++i) {
    node_numbers[i] = random_400();
    page_numbers[i] = node_numbers[i] / 4;
  }
  FIFOSimulate(page_numbers, &FIFO_pf);
  LRUSimulate(page_numbers, &LRU_pf);
  printf("In FIFO %i\n", FIFO_pf);
  printf("IN LRU %i", LRU_pf);
  getch();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <initSegments@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x334(%rbp)
cmpl   $0x64,-0x334(%rbp)
jge    121d <main+0x9d>
mov    $0x0,%al
call   10a0 <random_400@plt>
mov    %eax,%ecx
movslq -0x334(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
movslq -0x334(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
movslq -0x334(%rbp),%rax
mov    %ecx,-0x330(%rbp,%rax,4)
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x334(%rbp)
jmp    11bf <main+0x3f>
lea    -0x330(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1090 <FIFOSimulate@plt>
lea    -0x330(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <LRUSimulate@plt>
mov    -0x8(%rbp),%esi
lea    0xdb9(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xdb6(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1080 <getch@plt>
mov    -0x4(%rbp),%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1a0,%rsp
xor    %eax,%eax
call   1070 <initSegments@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   10a0 <random_400@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x2,%ecx
mov    %ecx,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    11b0 <main+0x30>
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <FIFOSimulate@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <LRUSimulate@plt>
mov    0xc(%rsp),%esi
lea    0xe06(%rip),%rdi
call   1030 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xe02(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1080 <getch@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"In FIFO %i\0A\00"
@.str.1 = [10 x i8] c"IN LRU %i\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i32]
%5 = alloca [100 x i32]
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (...) @initSegments()
%8 = call i32 @time(i32 0)
%9 = call i32 @srand(i32 %8)
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %6
br label %10
10: ; preds = %26, %0
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 100
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = call i32 (...) @random_400()
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %16
store i32 %14, i32* %17
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = sdiv i32 %21, 4
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %24
store i32 %22, i32* %25
br label %26
26: ; preds = %13
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %10
29: ; preds = %10
%30 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 0
%31 = call i32 @FIFOSimulate(i32* %30, i32* %2)
%32 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 0
%33 = call i32 @LRUSimulate(i32* %32, i32* %3)
%34 = load i32, i32* %2
%35 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %3
%37 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = call i32 (...) @getch()
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [12 x i8] c"In FIFO %i\0A\00"
@.str.1 = [10 x i8] c"IN LRU %i\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i32]
%4 = tail call i32 (...) @initSegments()
%5 = tail call i32 @time(i32 0)
%6 = tail call i32 @srand(i32 %5)
%7 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%8 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%9 = bitcast [100 x i32]* %3 to i8*
br label %10
10: ; preds = %0, %10
%11 = phi i64 [ 0, %0 ], [ %15, %10 ]
%12 = tail call i32 (...) @random_400()
%13 = sdiv i32 %12, 4
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %11
store i32 %13, i32* %14
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, 100
br i1 %16, label %17, label %10
17: ; preds = %10
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%19 = call i32 @FIFOSimulate(i32* %18, i32* %1)
%20 = call i32 @LRUSimulate(i32* %18, i32* %2)
%21 = load i32, i32* %1
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = call i32 (...) @getch()
ret i32 0
}