void sjf_algorithm(struct times **list) {
  int processCounter = 1, startTime = 0, stopTime = 0, searching = 1,
      curShort = 0, counter = 0;
  struct times *visited = 0;
  struct times *temp;
  struct times *wait = 0;
  struct times *turnaround = 0;
  char waitMessage[50] = {"Computing Wait times\n"};
  char summaryMessage[50] = {"Computing Turn around times\n"};
  temp = *list;
  if (temp == 0) {
    printf("Nothing in the list\n");
  } else {
    while (searching == 1) {
      curShort = findshortest(list);
      if (curShort == -1) {
        searching = 0;
      } else {
        stopTime = stopTime + curShort;
        add_burst_time(&wait, startTime);
        add_burst_time(&turnaround, stopTime);
        printf("P%d\t\t\t%d\t\t\t\t\%d\t\t\t\t%d\n", counter, curShort,
               startTime, stopTime);
        startTime = startTime + curShort;
      }
      counter++;
    }
  }
  counter = 1;
  output_summary(waitMessage, &wait, counter);
  counter = 1;
  output_summary(summaryMessage, &turnaround, counter);
  printf("\n");
}


x86 assembly (clang, -O0):
<sjf_algorithm>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe54(%rip),%rsi
mov    $0x32,%edx
call   1070 <memcpy@plt>
lea    -0xc0(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x32,%edx
call   1070 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f7 <sjf_algorithm+0xa7>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1286 <sjf_algorithm+0x136>
jmp    11fc <sjf_algorithm+0xac>
cmpl   $0x1,-0x18(%rbp)
jne    1281 <sjf_algorithm+0x131>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1060 <findshortest@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    122a <sjf_algorithm+0xda>
movl   $0x0,-0x18(%rbp)
jmp    1273 <sjf_algorithm+0x123>
mov    -0x14(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%esi
lea    -0x38(%rbp),%rdi
mov    $0x0,%al
call   1040 <add_burst_time@plt>
mov    -0x14(%rbp),%esi
lea    -0x40(%rbp),%rdi
mov    $0x0,%al
call   1040 <add_burst_time@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11fc <sjf_algorithm+0xac>
jmp    1286 <sjf_algorithm+0x136>
movl   $0x1,-0x20(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    -0x38(%rbp),%rsi
mov    $0x0,%al
call   1030 <output_summary@plt>
movl   $0x1,-0x20(%rbp)
lea    -0xc0(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    -0x40(%rbp),%rsi
mov    $0x0,%al
call   1030 <output_summary@plt>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sjf_algorithm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
movaps 0xe97(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe7b(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe5f(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movw   $0x0,0x80(%rsp)
movaps 0xea9(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe8d(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe71(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x0,0x40(%rsp)
cmpq   $0x0,(%rdi)
je     125c <sjf_algorithm+0xfc>
mov    %rdi,%r13
xor    %eax,%eax
call   1080 <findshortest@plt>
cmp    $0xffffffff,%eax
je     1268 <sjf_algorithm+0x108>
mov    %eax,%ebp
lea    0xe79(%rip),%r12
xor    %ebx,%ebx
xor    %r14d,%r14d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %ebp,%r14d
lea    0x8(%rsp),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <add_burst_time@plt>
mov    %rsp,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <add_burst_time@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1070 <printf@plt>
add    %ebp,%r15d
add    $0x1,%ebx
mov    %r13,%rdi
xor    %eax,%eax
call   1080 <findshortest@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1210 <sjf_algorithm+0xb0>
jmp    1268 <sjf_algorithm+0x108>
lea    0xe25(%rip),%rdi
call   1050 <puts@plt>
lea    0x50(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <output_summary@plt>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <output_summary@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.times = type opaque
@__const.sjf_algorithm.waitMessage = [50 x i8] c"Computing Wait times\0A\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.sjf_algorithm.summaryMessage = [50 x i8] c"Computing Turn around times\0A\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\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"
@str = [20 x i8] c"Nothing in the list\00"
define void @sjf_algorithm(%struct.times** %0) {
%2 = alloca %struct.times*
%3 = alloca %struct.times*
%4 = alloca [50 x i8]
%5 = alloca [50 x i8]
%6 = bitcast %struct.times** %2 to i8*
store %struct.times* null, %struct.times** %2
%7 = bitcast %struct.times** %3 to i8*
store %struct.times* null, %struct.times** %3
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%10 = load %struct.times*, %struct.times** %0
%11 = icmp eq %struct.times* %10, null
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = call i32 (%struct.times**, ...) bitcast (i32 (...)* @findshortest to i32 (%struct.times**, ...)*)(%struct.times** %0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %30, 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 %30
17: ; preds = %12, %17
%18 = phi i32 [ %28, %17 ], [ %13, %12 ]
%19 = phi i32 [ %27, %17 ], [ 0, %12 ]
%20 = phi i32 [ %22, %17 ], [ 0, %12 ]
%21 = phi i32 [ %26, %17 ], [ 0, %12 ]
%22 = add nsw i32 %18, %20
%23 = call i32 (%struct.times**, i32, ...) bitcast (i32 (...)* @add_burst_time to i32 (%struct.times**, i32, ...)*)(%struct.times** %2, i32 %21)
%24 = call i32 (%struct.times**, i32, ...) bitcast (i32 (...)* @add_burst_time to i32 (%struct.times**, i32, ...)*)(%struct.times** %3, i32 %22)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %18, i32 %21, i32 %22)
%26 = add nsw i32 %18, %21
%27 = add nuw nsw i32 %19, 1
%28 = call i32 (%struct.times**, ...) bitcast (i32 (...)* @findshortest to i32 (%struct.times**, ...)*)(%struct.times** %0)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %17
30: ; preds = %17, %12, %15
%31 = call i32 (i8*, %struct.times**, i32, ...) bitcast (i32 (...)* @output_summary to i32 (i8*, %struct.times**, i32, ...)*)(i8* %8, %struct.times** %2, i32 1)
%32 = call i32 (i8*, %struct.times**, i32, ...) bitcast (i32 (...)* @output_summary to i32 (i8*, %struct.times**, i32, ...)*)(i8* %9, %struct.times** %3, i32 1)
%33 = call i32 @putchar(i32 10)
ret void
}