#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*/ findshortest(struct times **, int **, int **);
int /*<<< orphan*/ printf(char *, ...);
void fcfs_wait_time(struct times **list) {
  printf("\n");
  printf("Computing Wait times\n");
  printf("\n");
  struct times *temp;
  temp = *list;
  int startTime = 0, processing = 1, processCounter = 1, first = 0,
      stopTime = 0;
  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 - *lowArrive;
          stopTime = startTime + *lowBurst;
        }
        printf("P%d\t%d\n", processCounter, startTime);
      } else {
        processing = 0;
      }
      processCounter++;
    }
  }
}


x86 assembly (clang, -O0):
<fcfs_wait_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xefe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a2 <fcfs_wait_time+0x82>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1245 <fcfs_wait_time+0x125>
jmp    11a7 <fcfs_wait_time+0x87>
cmpl   $0x1,-0x18(%rbp)
jne    1240 <fcfs_wait_time+0x120>
lea    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <findshortest@plt>
mov    -0x30(%rbp),%rax
cmpl   $0xffffffff,(%rax)
je     122b <fcfs_wait_time+0x10b>
cmpl   $0x1,-0x20(%rbp)
jne    11fa <fcfs_wait_time+0xda>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x38(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
jmp    1212 <fcfs_wait_time+0xf2>
mov    -0x24(%rbp),%eax
mov    -0x30(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x38(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1232 <fcfs_wait_time+0x112>
movl   $0x0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a7 <fcfs_wait_time+0x87>
jmp    1245 <fcfs_wait_time+0x125>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcfs_wait_time>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xea6(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%rbx),%rax
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1204 <fcfs_wait_time+0xc4>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1060 <findshortest@plt>
mov    (%rsp),%rax
mov    (%rax),%eax
cmp    $0xffffffff,%eax
je     11f5 <fcfs_wait_time+0xb5>
mov    $0x1,%ebx
lea    0xe55(%rip),%r14
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
mov    %rsp,%r13
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
sub    %eax,%edx
mov    0x8(%rsp),%rax
mov    (%rax),%ebp
add    %edx,%ebp
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1060 <findshortest@plt>
mov    (%rsp),%rax
mov    (%rax),%eax
mov    %ebp,%edx
cmp    $0xffffffff,%eax
jne    11c0 <fcfs_wait_time+0x80>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe12(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

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

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