#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 atoi(char *);
int c_look(int *, int);
int c_scan(int *, int);
int /*<<< orphan*/ exit(int);
int fcfs(int *, int);
int look(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int scan(int *, int);
int /*<<< orphan*/ set_head(int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int sstf(int *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Usage: HDD first_head_postion\n");
    exit(1);
  }
  int position = atoi(argv[1]);
  int req[10];
  srand(time(NULL));
  printf("Requests: ");
  for (int i = 0; i < 10; i++) {
    req[i] = rand() % 10;
    if (i % 10 == 0)
      printf("\n");
    printf("%04d ", req[i]);
  }
  printf("\n");
  set_head(position);
  printf("FCFS: %d\n", fcfs(req, 10));
  set_head(position);
  printf("SSTF: %d\n", sstf(req, 10));
  set_head(position);
  printf("SCAN: %d\n", scan(req, 10));
  set_head(position);
  printf("C-SCAN: %d\n", c_scan(req, 10));
  set_head(position);
  printf("LOOK: %d\n", look(req, 10));
  set_head(position);
  printf("C-LOOK: %d\n", c_look(req, 10));
}


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   $0x2,-0x8(%rbp)
jge    1208 <main+0x38>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x44(%rbp)
cmpl   $0xa,-0x44(%rbp)
jge    12a4 <main+0xd4>
mov    $0x0,%al
call   10f0 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
movslq -0x44(%rbp),%rax
mov    %edx,-0x40(%rbp,%rax,4)
mov    -0x44(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1280 <main+0xb0>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    123d <main+0x6d>
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   10e0 <set_head@plt>
lea    -0x40(%rbp),%rdi
mov    $0xa,%esi
call   1070 <fcfs@plt>
mov    %eax,%esi
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   10e0 <set_head@plt>
lea    -0x40(%rbp),%rdi
mov    $0xa,%esi
call   1030 <sstf@plt>
mov    %eax,%esi
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   10e0 <set_head@plt>
lea    -0x40(%rbp),%rdi
mov    $0xa,%esi
call   10b0 <scan@plt>
mov    %eax,%esi
lea    0xd29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   10e0 <set_head@plt>
lea    -0x40(%rbp),%rdi
mov    $0xa,%esi
call   1040 <c_scan@plt>
mov    %eax,%esi
lea    0xd01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   10e0 <set_head@plt>
lea    -0x40(%rbp),%rdi
mov    $0xa,%esi
call   1090 <look@plt>
mov    %eax,%esi
lea    0xce9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   10e0 <set_head@plt>
lea    -0x40(%rbp),%rdi
mov    $0xa,%esi
call   10a0 <c_look@plt>
mov    %eax,%esi
lea    0xcc1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x1,%edi
jle    13a2 <main+0x1b2>
mov    0x8(%rsi),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r15d
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
lea    0xdd8(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdd5(%rip),%r14
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    125a <main+0x6a>
nopl   (%rax)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbx
add    $0xff,%r12b
cmp    $0xa,%rbx
je     12a6 <main+0xb6>
movzbl %bl,%eax
imul   $0xcd,%eax,%eax
shr    $0xa,%eax
and    $0xfffffffe,%eax
lea    (%rax,%rax,4),%r13d
xor    %eax,%eax
call   1110 <rand@plt>
movslq %eax,%rbp
imul   $0x66666667,%rbp,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebp
mov    %ebp,(%rsp,%rbx,4)
add    %r12b,%r13b
jne    1240 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1240 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15d,%edi
call   1100 <set_head@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xa,%esi
call   1090 <fcfs@plt>
lea    0xd42(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
call   1100 <set_head@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1050 <sstf@plt>
lea    0xd27(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
call   1100 <set_head@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   10d0 <scan@plt>
lea    0xd0e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
call   1100 <set_head@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1060 <c_scan@plt>
lea    0xce7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
call   1100 <set_head@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   10b0 <look@plt>
lea    0xcd0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
call   1100 <set_head@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   10c0 <c_look@plt>
lea    0xca9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc94(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Usage: HDD first_head_postion\0A\00"
@.str.1 = [11 x i8] c"Requests: \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c"%04d \00"
@.str.4 = [10 x i8] c"FCFS: %d\0A\00"
@.str.5 = [10 x i8] c"SSTF: %d\0A\00"
@.str.6 = [10 x i8] c"SCAN: %d\0A\00"
@.str.7 = [12 x i8] c"C-SCAN: %d\0A\00"
@.str.8 = [10 x i8] c"LOOK: %d\0A\00"
@.str.9 = [12 x i8] c"C-LOOK: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [10 x i32]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = call i32 @time(i32* null)
%20 = call i32 @srand(i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %22
22: ; preds = %42, %14
%23 = load i32, i32* %8
%24 = icmp slt i32 %23, 10
br i1 %24, label %25, label %45
25: ; preds = %22
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 10
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %29
store i32 %27, i32* %30
%31 = load i32, i32* %8
%32 = srem i32 %31, 10
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %25
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %25
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %36
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %22
45: ; preds = %22
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%47 = load i32, i32* %6
%48 = call i32 @set_head(i32 %47)
%49 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%50 = call i32 @fcfs(i32* %49, i32 10)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %6
%53 = call i32 @set_head(i32 %52)
%54 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%55 = call i32 @sstf(i32* %54, i32 10)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %55)
%57 = load i32, i32* %6
%58 = call i32 @set_head(i32 %57)
%59 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%60 = call i32 @scan(i32* %59, i32 10)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %6
%63 = call i32 @set_head(i32 %62)
%64 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%65 = call i32 @c_scan(i32* %64, i32 10)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %6
%68 = call i32 @set_head(i32 %67)
%69 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%70 = call i32 @look(i32* %69, i32 10)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %70)
%72 = load i32, i32* %6
%73 = call i32 @set_head(i32 %72)
%74 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%75 = call i32 @c_look(i32* %74, i32 10)
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"Requests: \00"
@.str.3 = [6 x i8] c"%04d \00"
@.str.4 = [10 x i8] c"FCFS: %d\0A\00"
@.str.5 = [10 x i8] c"SSTF: %d\0A\00"
@.str.6 = [10 x i8] c"SCAN: %d\0A\00"
@.str.7 = [12 x i8] c"C-SCAN: %d\0A\00"
@.str.8 = [10 x i8] c"LOOK: %d\0A\00"
@.str.9 = [12 x i8] c"C-LOOK: %d\0A\00"
@str = [30 x i8] c"Usage: HDD first_head_postion\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i32]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = bitcast [10 x i32]* %3 to i8*
%13 = tail call i32 @time(i32* null)
%14 = tail call i32 @srand(i32 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %37
16: ; preds = %47
%17 = tail call i32 @putchar(i32 10)
%18 = tail call i32 @set_head(i32 %11)
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%20 = call i32 @fcfs(i32* %19, i32 10)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = call i32 @set_head(i32 %11)
%23 = call i32 @sstf(i32* %19, i32 10)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %23)
%25 = call i32 @set_head(i32 %11)
%26 = call i32 @scan(i32* %19, i32 10)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %26)
%28 = call i32 @set_head(i32 %11)
%29 = call i32 @c_scan(i32* %19, i32 10)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %29)
%31 = call i32 @set_head(i32 %11)
%32 = call i32 @look(i32* %19, i32 10)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %32)
%34 = call i32 @set_head(i32 %11)
%35 = call i32 @c_look(i32* %19, i32 10)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %35)
ret i32 0
37: ; preds = %8, %47
%38 = phi i64 [ 0, %8 ], [ %49, %47 ]
%39 = tail call i32 (...) @rand()
%40 = srem i32 %39, 10
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %38
store i32 %40, i32* %41
%42 = trunc i64 %38 to i8
%43 = urem i8 %42, 10
%44 = icmp eq i8 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %37
%46 = tail call i32 @putchar(i32 10)
br label %47
47: ; preds = %45, %37
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%49 = add nuw nsw i64 %38, 1
%50 = icmp eq i64 %49, 10
br i1 %50, label %16, label %37
}