#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);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  unsigned ch;
  int p;
  do {
    puts("Choose an action ");
    puts("0: Exit");
    puts("1: Add to   FRONT");
    puts("2: Add to   REAR ");
    puts("3: Del from FRONT");
    puts("4: Del from REAR ");
    scanf(" %u%*c", &ch);
    switch (ch) {
    case 0:
      puts("Bye!");
      break;
    case 1:
      scanf(" %d%*c", &p);
      add(0, p);
      break;
    case 2:
      scanf(" %d%*c", &p);
      add(1, p);
      break;
    case 3:
      if ((p = del(0)) != -1)
        printf("%d\n", p);
      break;
    case 4:
      if ((p = del(1)) != -1)
        printf("%d\n", p);
      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    0xe9e(%rip),%rdi
call   1050 <puts@plt>
lea    0xea4(%rip),%rdi
call   1050 <puts@plt>
lea    0xea0(%rip),%rdi
call   1050 <puts@plt>
lea    0xea6(%rip),%rdi
call   1050 <puts@plt>
lea    0xeac(%rip),%rdi
call   1050 <puts@plt>
lea    0xeb2(%rip),%rdi
call   1050 <puts@plt>
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x4,%rax
ja     1299 <main+0x139>
mov    -0x18(%rbp),%rax
lea    0xe1b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe88(%rip),%rdi
call   1050 <puts@plt>
jmp    12a7 <main+0x147>
lea    0xe7c(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0xc(%rbp),%esi
xor    %edi,%edi
call   1040 <add@plt>
jmp    12a7 <main+0x147>
lea    0xe5b(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0xc(%rbp),%esi
mov    $0x1,%edi
call   1040 <add@plt>
jmp    12a7 <main+0x147>
xor    %edi,%edi
call   1080 <del@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
je     1268 <main+0x108>
mov    -0xc(%rbp),%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12a7 <main+0x147>
mov    $0x1,%edi
call   1080 <del@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
je     1294 <main+0x134>
mov    -0xc(%rbp),%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12a7 <main+0x147>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,-0x8(%rbp)
jne    116f <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
push   %rax
lea    0xece(%rip),%r13
lea    0xed9(%rip),%rbx
lea    0xee4(%rip),%rbp
lea    0xeef(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xe6d(%rip),%r12
jmp    11b6 <main+0x56>
lea    0xef1(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,0x4(%rsp)
je     128d <main+0x12d>
lea    0xe57(%rip),%rdi
call   1050 <puts@plt>
lea    0xe5d(%rip),%rdi
call   1050 <puts@plt>
lea    0xe59(%rip),%rdi
call   1050 <puts@plt>
mov    %r13,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x4,%rax
ja     1195 <main+0x35>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
lea    0xe64(%rip),%rdi
jmp    119c <main+0x3c>
lea    0xe60(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    (%rsp),%esi
xor    %edi,%edi
call   1040 <add@plt>
jmp    11a1 <main+0x41>
lea    0xe40(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    (%rsp),%esi
mov    $0x1,%edi
call   1040 <add@plt>
jmp    11a1 <main+0x41>
xor    %edi,%edi
jmp    1267 <main+0x107>
mov    $0x1,%edi
call   1080 <del@plt>
mov    %eax,(%rsp)
cmp    $0xffffffff,%eax
je     11a1 <main+0x41>
lea    0xe0a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11a1 <main+0x41>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Choose an action \00"
@.str.1 = [8 x i8] c"0: Exit\00"
@.str.2 = [18 x i8] c"1: Add to FRONT\00"
@.str.3 = [18 x i8] c"2: Add to REAR \00"
@.str.4 = [18 x i8] c"3: Del from FRONT\00"
@.str.5 = [18 x i8] c"4: Del from REAR \00"
@.str.6 = [7 x i8] c" %u%*c\00"
@.str.7 = [5 x i8] c"Bye!\00"
@.str.8 = [7 x i8] c" %d%*c\00"
@.str.9 = [4 x i8] c"%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
store i32 0, i32* %1
br label %4
4: ; preds = %41, %0
%5 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
switch i32 %12, label %37 [
i32 0, label %13
i32 1, label %15
i32 2, label %19
i32 3, label %23
i32 4, label %30
]
13: ; preds = %4
%14 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %39
15: ; preds = %4
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32* %3)
%17 = load i32, i32* %3
%18 = call i32 @add(i32 0, i32 %17)
br label %39
19: ; preds = %4
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32* %3)
%21 = load i32, i32* %3
%22 = call i32 @add(i32 1, i32 %21)
br label %39
23: ; preds = %4
%24 = call i32 @del(i32 0)
store i32 %24, i32* %3
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %23
br label %39
30: ; preds = %4
%31 = call i32 @del(i32 1)
store i32 %31, i32* %3
%32 = icmp ne i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %3
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33, %30
br label %39
37: ; preds = %4
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %39
39: ; preds = %37, %36, %29, %19, %15, %13
%40 = call i32 @putchar(i8 signext 10)
br label %41
41: ; preds = %39
%42 = load i32, i32* %2
%43 = icmp ne i32 %42, 0
br i1 %43, label %4, label %44
44: ; preds = %41
ret i32 0
}

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