#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*/ add_processes(struct times **, int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int get_algorithm(char *);
int /*<<< orphan*/ output_algorithm(struct times **, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stdin;
int main() {
  char algor[10];
  int quanta = 0, check = 0, timeRetrieve = 1, processCount = 1, tempNum = 0,
      tempProcess = 0;
  struct times *burstList = 0;
  printf("Welcome to the Job Scheduler Computer.\nWhat algorithm would you "
         "like to use\n");
  scanf("%s", algor);
  check = get_algorithm(algor);
  if (check) {
    if (check == 4) {
      return 0;
      printf("What is the time quanta for %s scheduling\n", algor);
      scanf("%d", &quanta);
    }
    while (timeRetrieve == 1) {
      if (processCount <= 63) {
        printf("Process %d (P%d) – What is the burst time & start time?\n",
               processCount, processCount);
        scanf("%d%d", &tempNum, &tempProcess);
        if (!feof(stdin)) {
          add_processes(&burstList, tempNum, tempProcess);
        } else {
          printf("Input terminated\n");
          timeRetrieve = 0;
        }
      } else {
        timeRetrieve = 0;
        fclose(stdin);
      }
      processCount++;
    }
    output_algorithm(&burstList, check, quanta);
  } else {
    printf("You didn't enter a valid algorithm. Process terminated!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xe(%rbp),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    -0xe(%rbp),%rdi
call   1030 <get_algorithm@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     12bc <main+0x14c>
cmpl   $0x4,-0x18(%rbp)
jne    11fd <main+0x8d>
movl   $0x0,-0x4(%rbp)
jmp    12d1 <main+0x161>
jmp    1202 <main+0x92>
cmpl   $0x1,-0x1c(%rbp)
jne    12a8 <main+0x138>
cmpl   $0x3f,-0x20(%rbp)
jg     1285 <main+0x115>
mov    -0x20(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5a(%rip),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1080 <scanf@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
cmp    $0x0,%eax
jne    126b <main+0xfb>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    -0x30(%rbp),%rdi
call   1060 <add_processes@plt>
jmp    1280 <main+0x110>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
jmp    129a <main+0x12a>
movl   $0x0,-0x1c(%rbp)
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1202 <main+0x92>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    -0x30(%rbp),%rdi
call   1090 <output_algorithm@plt>
jmp    12ca <main+0x15a>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
lea    0xe46(%rip),%rdi
lea    0x1e(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    %rbx,%rdi
call   1030 <get_algorithm@plt>
test   %eax,%eax
je     1264 <main+0xe4>
cmp    $0x4,%eax
je     128e <main+0x10e>
mov    %eax,0xc(%rsp)
lea    0xe51(%rip),%r12
lea    0x8(%rsp),%r13
lea    0x4(%rsp),%rbp
mov    0x2dea(%rip),%r15
lea    0x10(%rsp),%rbx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r14d
lea    0xde8(%rip),%rdi
mov    %r14d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <scanf@plt>
mov    (%r15),%edi
call   1080 <feof@plt>
test   %eax,%eax
jne    1272 <main+0xf2>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
call   1070 <add_processes@plt>
cmp    $0x3f,%r14d
jb     1210 <main+0x90>
mov    (%r15),%edi
call   1050 <fclose@plt>
jmp    127e <main+0xfe>
lea    0xe24(%rip),%rdi
call   1040 <puts@plt>
jmp    128e <main+0x10e>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
xor    %edx,%edx
call   10a0 <output_algorithm@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.times = type { i32 }
@.str = [77 x i8] c"Welcome to the Job Scheduler Computer.\0AWhat algorithm would you like to use\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [59 x i8] c"Process %d (P%d) \E2\80\93 What is the burst time & start time?\0A\00"
@.str.3 = [5 x i8] c"%d%d\00"
@stdin = global i32 0
@.str.4 = [18 x i8] c"Input terminated\0A\00"
@.str.5 = [57 x i8] c"You didn't enter a valid algorithm. Process terminated!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.times*
store i32 0, i32* %1
store i32 0, i32* %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
store %struct.times* null, %struct.times** %9
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%14 = call i32 @get_algorithm(i8* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %53
17: ; preds = %0
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 4
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %1
br label %56
21: ; preds = %17
br label %22
22: ; preds = %46, %21
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %49
25: ; preds = %22
%26 = load i32, i32* %6
%27 = icmp sle i32 %26, 63
br i1 %27, label %28, label %43
28: ; preds = %25
%29 = load i32, i32* %6
%30 = load i32, i32* %6
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %30)
%32 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %7, i32* %8)
%33 = load i32, i32* @stdin
%34 = call i32 @feof(i32 %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %28
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = call i32 @add_processes(%struct.times** %9, i32 %37, i32 %38)
br label %42
40: ; preds = %28
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %5
br label %42
42: ; preds = %40, %36
br label %46
43: ; preds = %25
store i32 0, i32* %5
%44 = load i32, i32* @stdin
%45 = call i32 @fclose(i32 %44)
br label %46
46: ; preds = %43, %42
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %22
49: ; preds = %22
%50 = load i32, i32* %4
%51 = load i32, i32* %3
%52 = call i32 @output_algorithm(%struct.times** %9, i32 %50, i32 %51)
br label %55
53: ; preds = %0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
store i32 0, i32* %1
br label %56
56: ; preds = %55, %20
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
%struct.times = type { i32 }
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [59 x i8] c"Process %d (P%d) \E2\80\93 What is the burst time & start time?\0A\00"
@.str.3 = [5 x i8] c"%d%d\00"
@stdin = global i32 0
@str = [76 x i8] c"Welcome to the Job Scheduler Computer.\0AWhat algorithm would you like to use\00"
@str.6 = [56 x i8] c"You didn't enter a valid algorithm. Process terminated!\00"
@str.7 = [17 x i8] c"Input terminated\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.times*
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = bitcast %struct.times** %4 to i8*
store %struct.times* null, %struct.times** %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%11 = call i32 @get_algorithm(i8* %5)
switch i32 %11, label %12 [
i32 0, label %32
i32 4, label %34
]
12: ; preds = %0, %24
%13 = phi i32 [ %28, %24 ], [ 1, %0 ]
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %13)
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %2, i32* %3)
%16 = load i32, i32* @stdin
%17 = call i32 @feof(i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %12
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
br label %30
21: ; preds = %24
%22 = load i32, i32* @stdin
%23 = call i32 @fclose(i32 %22)
br label %30
24: ; preds = %12
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = call i32 @add_processes(%struct.times** %4, i32 %25, i32 %26)
%28 = add nuw nsw i32 %13, 1
%29 = icmp ult i32 %13, 63
br i1 %29, label %12, label %21
30: ; preds = %19, %21
%31 = call i32 @output_algorithm(%struct.times** %4, i32 %11, i32 0)
br label %34
32: ; preds = %0
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.6, i64 0, i64 0))
br label %34
34: ; preds = %30, %32, %0
ret i32 0
}