#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_front(int);
int /*<<< orphan*/ add_rear(int);
int del_front();
int del_rear();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int 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_front(p);
      break;
    case 2:
      scanf(" %d%*c", &p);
      add_rear(p);
      break;
    case 3:
      if ((p = del_front()) != -1)
        printf("%d\n", p);
      break;
    case 4:
      if ((p = del_rear()) != -1)
        printf("%d\n", p);
      break;
    default:
      puts("Invalid Input!");
      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    0xe7e(%rip),%rdi
call   1060 <puts@plt>
lea    0xe84(%rip),%rdi
call   1060 <puts@plt>
lea    0xe80(%rip),%rdi
call   1060 <puts@plt>
lea    0xe86(%rip),%rdi
call   1060 <puts@plt>
lea    0xe8c(%rip),%rdi
call   1060 <puts@plt>
lea    0xe92(%rip),%rdi
call   1060 <puts@plt>
lea    0xe98(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x4,%rax
ja     12a5 <main+0x125>
mov    -0x18(%rbp),%rax
lea    0xdfd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe6a(%rip),%rdi
call   1060 <puts@plt>
jmp    12b1 <main+0x131>
lea    0xe5e(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0xc(%rbp),%edi
call   1040 <add_front@plt>
jmp    12b1 <main+0x131>
lea    0xe41(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0xc(%rbp),%edi
call   1080 <add_rear@plt>
jmp    12b1 <main+0x131>
mov    $0x0,%al
call   10a0 <del_front@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
je     1279 <main+0xf9>
mov    -0xc(%rbp),%esi
lea    0xe15(%rip),%rdi
call   1070 <printf@plt>
jmp    12b1 <main+0x131>
mov    $0x0,%al
call   1030 <del_rear@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
je     12a0 <main+0x120>
mov    -0xc(%rbp),%esi
lea    0xdee(%rip),%rdi
call   1070 <printf@plt>
jmp    12b1 <main+0x131>
lea    0xde1(%rip),%rdi
call   1060 <puts@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
cmpl   $0x0,-0x8(%rbp)
jne    118f <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    0xeae(%rip),%r13
lea    0xeb9(%rip),%rbx
lea    0xec4(%rip),%rbp
lea    0xecf(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xe4d(%rip),%r12
jmp    11d6 <main+0x56>
lea    0xed1(%rip),%rdi
call   1060 <puts@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
cmpl   $0x0,0x4(%rsp)
je     12a0 <main+0x120>
lea    0xe37(%rip),%rdi
call   1060 <puts@plt>
lea    0xe3d(%rip),%rdi
call   1060 <puts@plt>
lea    0xe39(%rip),%rdi
call   1060 <puts@plt>
mov    %r13,%rdi
call   1060 <puts@plt>
mov    %rbx,%rdi
call   1060 <puts@plt>
mov    %rbp,%rdi
call   1060 <puts@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x4,%rax
ja     11b5 <main+0x35>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
lea    0xe46(%rip),%rdi
jmp    11bc <main+0x3c>
lea    0xe42(%rip),%rdi
mov    %rsp,%rsi
call   1090 <scanf@plt>
mov    (%rsp),%edi
call   1040 <add_front@plt>
jmp    11c1 <main+0x41>
lea    0xe26(%rip),%rdi
mov    %rsp,%rsi
call   1090 <scanf@plt>
mov    (%rsp),%edi
call   1080 <add_rear@plt>
jmp    11c1 <main+0x41>
xor    %eax,%eax
call   10a0 <del_front@plt>
jmp    1281 <main+0x101>
xor    %eax,%eax
call   1030 <del_rear@plt>
mov    %eax,(%rsp)
cmp    $0xffffffff,%eax
je     11c1 <main+0x41>
lea    0xdf5(%rip),%rdi
mov    %eax,%esi
call   1070 <printf@plt>
jmp    11c1 <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 = [15 x i8] c"Invalid Input!\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 @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 @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_front(i32 %17)
br label %39
19: ; preds = %4
%20 = call i32 @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_rear(i32 %21)
br label %39
23: ; preds = %4
%24 = call i32 (...) @del_front()
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 @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_rear()
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 @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 @puts(i8* getelementptr inbounds ([15 x i8], [15 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.10 = [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 @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 @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_front(i32 %18)
br label %36
20: ; preds = %5
%21 = call i32 @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_rear(i32 %22)
br label %36
24: ; preds = %5
%25 = call i32 (...) @del_front()
store i32 %25, i32* %2
%26 = icmp eq i32 %25, -1
br i1 %26, label %36, label %27
27: ; preds = %24
%28 = call i32 @printf(i8* 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_rear()
store i32 %30, i32* %2
%31 = icmp eq i32 %30, -1
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = call i32 @printf(i8* 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.10, 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
}