#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 */

/* Variables and functions */
int /*<<< orphan*/ add(int, int);
int del();
int /*<<< orphan*/ display();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  unsigned ch;
  int pid, p;
  do {
    puts("Choose an action");
    puts("0: Exit");
    puts("1: Add");
    puts("2: Del");
    puts("3: Display");
    scanf(" %d%*c", &ch);
    switch (ch) {
    case 0:
      puts("Bye!");
      break;
    case 1:
      puts("PID and Priority?");
      scanf(" %d %d%*c", &pid, &p);
      add(pid, p);
      break;
    case 2:
      if ((p = del()) != -1)
        printf("PID: %d\n", p);
      break;
    case 3:
      display();
      break;
    default:
      printf("Invalid Input!\n");
      break;
    }
    putchar('\n');
  } while (ch);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1050 <puts@plt>
lea    0xe8f(%rip),%rdi
call   1050 <puts@plt>
lea    0xe8b(%rip),%rdi
call   1050 <puts@plt>
lea    0xe86(%rip),%rdi
call   1050 <puts@plt>
lea    0xe81(%rip),%rdi
call   1050 <puts@plt>
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x3,%rax
ja     126a <main+0xfa>
mov    -0x18(%rbp),%rax
lea    0xe17(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe49(%rip),%rdi
call   1050 <puts@plt>
jmp    1278 <main+0x108>
lea    0xe3d(%rip),%rdi
call   1050 <puts@plt>
lea    0xe43(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <add@plt>
jmp    1278 <main+0x108>
mov    $0x0,%al
call   1090 <del@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
je     1259 <main+0xe9>
mov    -0x10(%rbp),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1278 <main+0x108>
mov    $0x0,%al
call   1060 <display@plt>
jmp    1278 <main+0x108>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,-0x8(%rbp)
jne    117f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xea4(%rip),%r12
lea    0xea4(%rip),%r13
lea    0xea4(%rip),%rbx
lea    0xec2(%rip),%rbp
lea    0x10(%rsp),%r14
lea    0xe5a(%rip),%r15
jmp    11d1 <main+0x61>
nopl   0x0(%rax,%rax,1)
lea    0xeb5(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,0x10(%rsp)
je     12ac <main+0x13c>
lea    0xe38(%rip),%rdi
call   1050 <puts@plt>
lea    0xe3d(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
call   1050 <puts@plt>
mov    %r13,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x10(%rsp),%eax
cmp    $0x3,%rax
ja     11b0 <main+0x40>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
lea    0xe1a(%rip),%rdi
jmp    11b7 <main+0x47>
nopw   0x0(%rax,%rax,1)
lea    0xe10(%rip),%rdi
call   1050 <puts@plt>
lea    0xe16(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x14(%rsp),%edi
mov    0xc(%rsp),%esi
call   1040 <add@plt>
jmp    11bc <main+0x4c>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <del@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     11bc <main+0x4c>
lea    0xdd8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    11bc <main+0x4c>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <display@plt>
jmp    11bc <main+0x4c>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Choose an action\00"
@.str.1 = [8 x i8] c"0: Exit\00"
@.str.2 = [7 x i8] c"1: Add\00"
@.str.3 = [7 x i8] c"2: Del\00"
@.str.4 = [11 x i8] c"3: Display\00"
@.str.5 = [7 x i8] c" %d%*c\00"
@.str.6 = [5 x i8] c"Bye!\00"
@.str.7 = [18 x i8] c"PID and Priority?\00"
@.str.8 = [10 x i8] c" %d %d%*c\00"
@.str.9 = [9 x i8] c"PID: %d\0A\00"
@.str.10 = [16 x i8] c"Invalid Input!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
br label %5
5: ; preds = %34, %0
%6 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
switch i32 %12, label %30 [
i32 0, label %13
i32 1, label %15
i32 2, label %21
i32 3, label %28
]
13: ; preds = %5
%14 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %32
15: ; preds = %5
%16 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32* %3, i32* %4)
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = call i32 @add(i32 %18, i32 %19)
br label %32
21: ; preds = %5
%22 = call i32 (...) @del()
store i32 %22, i32* %4
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %24, %21
br label %32
28: ; preds = %5
%29 = call i32 (...) @display()
br label %32
30: ; preds = %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %32
32: ; preds = %30, %28, %27, %15, %13
%33 = call i32 @putchar(i8 signext 10)
br label %34
34: ; preds = %32
%35 = load i32, i32* %2
%36 = icmp ne i32 %35, 0
br i1 %36, label %5, label %37
37: ; preds = %34
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"Choose an action\00"
@.str.1 = [8 x i8] c"0: Exit\00"
@.str.2 = [7 x i8] c"1: Add\00"
@.str.3 = [7 x i8] c"2: Del\00"
@.str.4 = [11 x i8] c"3: Display\00"
@.str.5 = [7 x i8] c" %d%*c\00"
@.str.6 = [5 x i8] c"Bye!\00"
@.str.7 = [18 x i8] c"PID and Priority?\00"
@.str.8 = [10 x i8] c" %d %d%*c\00"
@.str.9 = [9 x i8] c"PID: %d\0A\00"
@str = [15 x i8] c"Invalid Input!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
br label %7
7: ; preds = %32, %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%14 = load i32, i32* %1
switch i32 %14, label %30 [
i32 0, label %15
i32 1, label %17
i32 2, label %23
i32 3, label %28
]
15: ; preds = %7
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %32
17: ; preds = %7
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32* %2, i32* %3)
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = call i32 @add(i32 %20, i32 %21)
br label %32
23: ; preds = %7
%24 = call i32 (...) @del()
store i32 %24, i32* %3
%25 = icmp eq i32 %24, -1
br i1 %25, label %32, label %26
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 %24)
br label %32
28: ; preds = %7
%29 = call i32 (...) @display()
br label %32
30: ; preds = %7
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %23, %26, %30, %28, %17, %15
%33 = call i32 @putchar(i8 signext 10)
%34 = load i32, i32* %1
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %7
36: ; preds = %32
ret i32 0
}