#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 */
struct times {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fcfs_turn_around(struct times **);
int /*<<< orphan*/ fcfs_wait_time(struct times **);
int /*<<< orphan*/ findshortest(struct times **, int **, int **);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reset_searched_markers(struct times **);
void fcfs_algorithm(struct times **list) {
  struct times *temp;
  temp = *list;
  int processCounter = 1, startTime = 0, stopTime = 0, first = 1,
      processing = 1;
  int *lowArrive;
  int *lowBurst;
  if (temp == 0) {
    printf("Nothing in the list\n");
  } else {
    while (processing == 1) {
      findshortest(&temp, &lowBurst, &lowArrive);
      if (*lowArrive != -1) {
        if (first == 1) {
          startTime = *lowArrive;
          stopTime = startTime + *lowBurst;
          first = 0;
        } else {
          startTime = stopTime;
          stopTime = stopTime + *lowBurst;
        }
        printf("P%d\t\t\t%d\t\t\t\t\%d\t\t\t\t%d\n", processCounter, *lowBurst,
               startTime, stopTime);
        startTime = *lowArrive;
      } else {
        processing = 0;
      }
      processCounter++;
    }
    reset_searched_markers(list);
    fcfs_wait_time(list);
    reset_searched_markers(list);
    fcfs_turn_around(list);
  }
}


x86 assembly (clang, -O0):
<fcfs_algorithm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a8 <fcfs_algorithm+0x58>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1277 <fcfs_algorithm+0x127>
jmp    11ad <fcfs_algorithm+0x5d>
cmpl   $0x1,-0x24(%rbp)
jne    1253 <fcfs_algorithm+0x103>
lea    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <findshortest@plt>
mov    -0x30(%rbp),%rax
cmpl   $0xffffffff,(%rax)
je     123e <fcfs_algorithm+0xee>
cmpl   $0x1,-0x20(%rbp)
jne    1200 <fcfs_algorithm+0xb0>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x38(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
jmp    1212 <fcfs_algorithm+0xc2>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x38(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1245 <fcfs_algorithm+0xf5>
movl   $0x0,-0x24(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ad <fcfs_algorithm+0x5d>
mov    -0x8(%rbp),%rdi
call   1050 <reset_searched_markers@plt>
mov    -0x8(%rbp),%rdi
call   1060 <fcfs_wait_time@plt>
mov    -0x8(%rbp),%rdi
call   1050 <reset_searched_markers@plt>
mov    -0x8(%rbp),%rdi
call   1070 <fcfs_turn_around@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcfs_algorithm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    (%rdi),%rax
mov    %rax,0x18(%rsp)
test   %rax,%rax
je     122c <fcfs_algorithm+0xcc>
mov    %rdi,0x20(%rsp)
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1050 <findshortest@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%ecx
cmp    $0xffffffff,%ecx
je     11f8 <fcfs_algorithm+0x98>
mov    $0x1,%ebp
lea    0xe50(%rip),%r15
lea    0x18(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%rbx
nop
mov    0x10(%rsp),%rax
mov    (%rax),%edx
lea    (%rdx,%rcx,1),%r14d
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1050 <findshortest@plt>
mov    0x8(%rsp),%rax
cmpl   $0xffffffff,(%rax)
mov    %r14d,%ecx
jne    11c0 <fcfs_algorithm+0x60>
mov    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <reset_searched_markers@plt>
mov    %rbx,%rdi
call   1070 <fcfs_wait_time@plt>
mov    %rbx,%rdi
call   1060 <reset_searched_markers@plt>
mov    %rbx,%rdi
call   1080 <fcfs_turn_around@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde3(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
%struct.times = type { i32 }
@.str = [21 x i8] c"Nothing in the list\0A\00"
@.str.1 = [22 x i8] c"P%d\09\09\09%d\09\09\09\09%d\09\09\09\09%d\0A\00"
define void @fcfs_algorithm(%struct.times** %0) {
%2 = alloca %struct.times**
%3 = alloca %struct.times*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
store %struct.times** %0, %struct.times*** %2
%11 = load %struct.times**, %struct.times*** %2
%12 = load %struct.times*, %struct.times** %11
store %struct.times* %12, %struct.times** %3
store i32 1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 1, i32* %7
store i32 1, i32* %8
%13 = load %struct.times*, %struct.times** %3
%14 = icmp eq %struct.times* %13, null
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %64
17: ; preds = %1
br label %18
18: ; preds = %52, %17
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %55
21: ; preds = %18
%22 = call i32 @findshortest(%struct.times** %3, i32** %10, i32** %9)
%23 = load i32*, i32** %9
%24 = load i32, i32* %23
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %51
26: ; preds = %21
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32*, i32** %9
%31 = load i32, i32* %30
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = load i32*, i32** %10
%34 = load i32, i32* %33
%35 = add nsw i32 %32, %34
store i32 %35, i32* %6
store i32 0, i32* %7
br label %42
36: ; preds = %26
%37 = load i32, i32* %6
store i32 %37, i32* %5
%38 = load i32, i32* %6
%39 = load i32*, i32** %10
%40 = load i32, i32* %39
%41 = add nsw i32 %38, %40
store i32 %41, i32* %6
br label %42
42: ; preds = %36, %29
%43 = load i32, i32* %4
%44 = load i32*, i32** %10
%45 = load i32, i32* %44
%46 = load i32, i32* %5
%47 = load i32, i32* %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %43, i32 %45, i32 %46, i32 %47)
%49 = load i32*, i32** %9
%50 = load i32, i32* %49
store i32 %50, i32* %5
br label %52
51: ; preds = %21
store i32 0, i32* %8
br label %52
52: ; preds = %51, %42
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %18
55: ; preds = %18
%56 = load %struct.times**, %struct.times*** %2
%57 = call i32 @reset_searched_markers(%struct.times** %56)
%58 = load %struct.times**, %struct.times*** %2
%59 = call i32 @fcfs_wait_time(%struct.times** %58)
%60 = load %struct.times**, %struct.times*** %2
%61 = call i32 @reset_searched_markers(%struct.times** %60)
%62 = load %struct.times**, %struct.times*** %2
%63 = call i32 @fcfs_turn_around(%struct.times** %62)
br label %64
64: ; preds = %55, %15
ret void
}

LLVM IR (-O2):
%struct.times = type { i32 }
@.str.1 = [22 x i8] c"P%d\09\09\09%d\09\09\09\09%d\09\09\09\09%d\0A\00"
@str = [20 x i8] c"Nothing in the list\00"
define void @fcfs_algorithm(%struct.times** %0) {
%2 = alloca %struct.times*
%3 = alloca i32*
%4 = alloca i32*
%5 = bitcast %struct.times** %2 to i8*
%6 = load %struct.times*, %struct.times** %0
store %struct.times* %6, %struct.times** %2
%7 = bitcast i32** %3 to i8*
%8 = bitcast i32** %4 to i8*
%9 = icmp eq %struct.times* %6, null
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = call i32 @findshortest(%struct.times** %2, i32** %4, i32** %3)
%12 = load i32*, i32** %3
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, -1
br i1 %14, label %29, label %17
15: ; preds = %1
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %34
17: ; preds = %10, %17
%18 = phi i32 [ %24, %17 ], [ 1, %10 ]
%19 = phi i32 [ %22, %17 ], [ %13, %10 ]
%20 = load i32*, i32** %4
%21 = load i32, i32* %20
%22 = add nsw i32 %21, %19
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %21, i32 %19, i32 %22)
%24 = add nuw nsw i32 %18, 1
%25 = call i32 @findshortest(%struct.times** %2, i32** %4, i32** %3)
%26 = load i32*, i32** %3
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %17
29: ; preds = %17, %10
%30 = call i32 @reset_searched_markers(%struct.times** %0)
%31 = call i32 @fcfs_wait_time(%struct.times** %0)
%32 = call i32 @reset_searched_markers(%struct.times** %0)
%33 = call i32 @fcfs_turn_around(%struct.times** %0)
br label %34
34: ; preds = %29, %15
ret void
}