#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_turn_around(struct times **list) {
  printf("\n");
  printf("Computing Turn around times\n");
  printf("\n");
  struct times *temp;
  temp = *list;
  int turnaround = 0, processing = 1, processCounter = 1, first = 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) {
          turnaround = *lowBurst - *lowArrive;
        } else {
          turnaround = turnaround + (*lowBurst - *lowArrive);
        }
        printf("P%d\t%d\n", processCounter, turnaround);
      } else {
        processing = 0;
      }
      processCounter++;
    }
  }
}


x86 assembly (clang, -O0):
<fcfs_turn_around>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xf05(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee9(%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)
cmpq   $0x0,-0x10(%rbp)
jne    119b <fcfs_turn_around+0x7b>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122d <fcfs_turn_around+0x10d>
jmp    11a0 <fcfs_turn_around+0x80>
cmpl   $0x1,-0x18(%rbp)
jne    1228 <fcfs_turn_around+0x108>
lea    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <findshortest@plt>
mov    -0x28(%rbp),%rax
cmpl   $0xffffffff,(%rax)
je     1213 <fcfs_turn_around+0xf3>
cmpl   $0x1,-0x20(%rbp)
jne    11e6 <fcfs_turn_around+0xc6>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    -0x28(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x14(%rbp)
jmp    11fa <fcfs_turn_around+0xda>
mov    -0x14(%rbp),%eax
mov    -0x30(%rbp),%rcx
mov    (%rcx),%ecx
mov    -0x28(%rbp),%rdx
sub    (%rdx),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121a <fcfs_turn_around+0xfa>
movl   $0x0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a0 <fcfs_turn_around+0x80>
jmp    122d <fcfs_turn_around+0x10d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcfs_turn_around>:
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_turn_around+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_turn_around+0xb5>
mov    $0x1,%ebx
lea    0xe55(%rip),%r14
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
mov    %rsp,%r13
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rcx
mov    (%rcx),%ecx
sub    %eax,%ecx
add    %ecx,%ebp
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
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
cmp    $0xffffffff,%eax
jne    11c0 <fcfs_turn_around+0x80>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe19(%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 = [29 x i8] c"Computing Turn around 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_turn_around(%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*
store %struct.times** %0, %struct.times*** %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = load %struct.times**, %struct.times*** %2
%14 = load %struct.times*, %struct.times** %13
store %struct.times* %14, %struct.times** %3
store i32 0, i32* %4
store i32 1, i32* %5
store i32 1, i32* %6
store i32 0, i32* %7
%15 = load %struct.times*, %struct.times** %3
%16 = icmp eq %struct.times* %15, null
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %54
19: ; preds = %1
br label %20
20: ; preds = %50, %19
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %53
23: ; preds = %20
%24 = call i32 @findshortest(%struct.times** %3, i32** %9, i32** %8)
%25 = load i32*, i32** %8
%26 = load i32, i32* %25
%27 = icmp ne i32 %26, -1
br i1 %27, label %28, label %49
28: ; preds = %23
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i32*, i32** %9
%33 = load i32, i32* %32
%34 = load i32*, i32** %8
%35 = load i32, i32* %34
%36 = sub nsw i32 %33, %35
store i32 %36, i32* %4
br label %45
37: ; preds = %28
%38 = load i32, i32* %4
%39 = load i32*, i32** %9
%40 = load i32, i32* %39
%41 = load i32*, i32** %8
%42 = load i32, i32* %41
%43 = sub nsw i32 %40, %42
%44 = add nsw i32 %38, %43
store i32 %44, i32* %4
br label %45
45: ; preds = %37, %31
%46 = load i32, i32* %6
%47 = load i32, i32* %4
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %47)
br label %50
49: ; preds = %23
store i32 0, i32* %5
br label %50
50: ; preds = %49, %45
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %20
53: ; preds = %20
br label %54
54: ; preds = %53, %17
ret void
}

LLVM IR (-O2):
%struct.times = type { i32 }
@.str.3 = [8 x i8] c"P%d\09%d\0A\00"
@str = [28 x i8] c"Computing Turn around times\00"
@str.4 = [20 x i8] c"Nothing in the list\00"
define void @fcfs_turn_around(%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 ([28 x i8], [28 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 = load i32*, i32** %4
%25 = load i32, i32* %24
%26 = sub nsw i32 %25, %21
%27 = add nsw i32 %26, %23
%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 %27)
%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
}