#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ cancelSpecific(int *, int);
int /*<<< orphan*/ checkReservedSpecific(int *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reserveFreeWindow(int *, int);
int /*<<< orphan*/ reserveSpecific(int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ showBlanks(int *, int);
int /*<<< orphan*/ showMenu();
int /*<<< orphan*/ showPlan(int *, int, char *);
int /*<<< orphan*/ showReserved(int *, int);
int /*<<< orphan*/ writePlanFile(int *, int, char *);
int main(void) {
  char plate[7], option;
  int maxSeats, layout[53], i;
  FILE *bus;
  bus = fopen(
      "I:\\Personal\\Education\\EAP\\PLS\\PLS50\\GE1\\CLion\\Exercise4\\bus."
      "txt",
      "r");
  fscanf(bus, "%s %d", plate, &maxSeats);
  fclose(bus);
  if ((maxSeats - 5) % 4) {
    printf("Adynatos syndyasmos arithmoy theseon (%d)\n", maxSeats);
    printf("Prepei na isxyei Theseis=4xTheseis + 5 (Theseis >= 0)\n");
  } else if (maxSeats > 53) {
    printf("Adynato plithos theseon (%d)\n", maxSeats);
    printf("Oi theseis den prepei na einai pano apo 53\n");
  } else {
    for (i = 0; i < maxSeats; i++) {
      layout[i] = 0;
    }
    do {
      showMenu();
      scanf(" %c", &option);
      switch (option) {
      case '1':
        showBlanks(layout, maxSeats);
        break;
      case '2':
        reserveSpecific(layout, maxSeats, 0);
        break;
      case '3':
        reserveFreeWindow(layout, maxSeats);
        break;
      case '4':
        cancelSpecific(layout, maxSeats);
        break;
      case '5':
        checkReservedSpecific(layout, maxSeats);
        break;
      case '6':
        showReserved(layout, maxSeats);
        break;
      case '7':
        showPlan(layout, maxSeats, plate);
        break;
      case '8':
        writePlanFile(layout, maxSeats, plate);
        break;
      case '0':
        break;
      default:
        printf("H epilogh poy dosate den einai egkyrh!\n");
        break;
      }
    } while (option != '0');
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe2b(%rip),%rdi
lea    0xe64(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x100(%rbp)
mov    -0x100(%rbp),%rdi
lea    -0xb(%rbp),%rdx
lea    0xe48(%rip),%rsi
lea    -0x10(%rbp),%rcx
call   1070 <fscanf@plt>
mov    -0x100(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%eax
sub    $0x5,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     126e <main+0x8e>
mov    -0x10(%rbp),%esi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1407 <main+0x227>
cmpl   $0x35,-0x10(%rbp)
jle    129c <main+0xbc>
mov    -0x10(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1402 <main+0x222>
movl   $0x0,-0xf4(%rbp)
mov    -0xf4(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12db <main+0xfb>
movslq -0xf4(%rbp),%rax
movl   $0x0,-0xf0(%rbp,%rax,4)
mov    -0xf4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4(%rbp)
jmp    12a6 <main+0xc6>
jmp    12e0 <main+0x100>
xor    %eax,%eax
call   1090 <showMenu@plt>
lea    0xe2a(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   10a0 <scanf@plt>
movsbl -0xc(%rbp),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x108(%rbp)
sub    $0x8,%eax
ja     13d6 <main+0x1f6>
mov    -0x108(%rbp),%rax
lea    0xce2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0xf0(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   10e0 <showBlanks@plt>
jmp    13e4 <main+0x204>
lea    -0xf0(%rbp),%rdi
mov    -0x10(%rbp),%esi
xor    %edx,%edx
call   1040 <reserveSpecific@plt>
jmp    13e4 <main+0x204>
lea    -0xf0(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   10d0 <reserveFreeWindow@plt>
jmp    13e4 <main+0x204>
lea    -0xf0(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1100 <cancelSpecific@plt>
jmp    13e4 <main+0x204>
lea    -0xf0(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1080 <checkReservedSpecific@plt>
jmp    13e4 <main+0x204>
lea    -0xf0(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   10f0 <showReserved@plt>
jmp    13e4 <main+0x204>
lea    -0xf0(%rbp),%rdi
mov    -0x10(%rbp),%esi
lea    -0xb(%rbp),%rdx
call   10c0 <showPlan@plt>
jmp    13e4 <main+0x204>
lea    -0xf0(%rbp),%rdi
mov    -0x10(%rbp),%esi
lea    -0xb(%rbp),%rdx
call   1030 <writePlanFile@plt>
jmp    13e4 <main+0x204>
jmp    13e4 <main+0x204>
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13e9 <main+0x209>
movsbl -0xc(%rbp),%eax
cmp    $0x30,%eax
jne    12e0 <main+0x100>
movl   $0x1,-0x4(%rbp)
jmp    140e <main+0x22e>
jmp    1407 <main+0x227>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
lea    0xe0c(%rip),%rdi
lea    0xe45(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rbx
lea    0xe38(%rip),%rsi
lea    0x9(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rax,%rdi
call   1090 <fscanf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x4(%rsp),%edx
lea    -0x1(%rdx),%eax
test   $0x3,%al
je     1263 <main+0x63>
lea    0xeb1(%rip),%rbx
lea    0xe0b(%rip),%rdi
jmp    1276 <main+0x76>
cmp    $0x35,%edx
jle    129d <main+0x9d>
lea    0xe71(%rip),%rbx
lea    0xe21(%rip),%rdi
xor    %ebp,%ebp
mov    %edx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %ebp,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %edx,%edx
jle    12b1 <main+0xb1>
shl    $0x2,%rdx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xdfd(%rip),%r14
lea    0x3(%rsp),%rbx
lea    0xdf5(%rip),%r15
lea    0xd35(%rip),%rbp
lea    0x10(%rsp),%r12
lea    0x9(%rsp),%r13
jmp    12ed <main+0xed>
mov    %r15,%rdi
call   1040 <puts@plt>
nop
movzbl 0x3(%rsp),%eax
cmp    $0x30,%al
je     1397 <main+0x197>
xor    %eax,%eax
call   10b0 <showMenu@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10c0 <scanf@plt>
movsbl 0x3(%rsp),%eax
lea    -0x30(%rax),%ecx
cmp    $0x8,%ecx
ja     12d7 <main+0xd7>
movslq 0x0(%rbp,%rcx,4),%rcx
add    %rbp,%rcx
jmp    *%rcx
mov    0x4(%rsp),%esi
mov    %r12,%rdi
call   1100 <showBlanks@plt>
jmp    12e0 <main+0xe0>
mov    0x4(%rsp),%esi
mov    %r12,%rdi
xor    %edx,%edx
call   1050 <reserveSpecific@plt>
jmp    12e0 <main+0xe0>
mov    0x4(%rsp),%esi
mov    %r12,%rdi
call   10f0 <reserveFreeWindow@plt>
jmp    12e0 <main+0xe0>
mov    0x4(%rsp),%esi
mov    %r12,%rdi
call   1120 <cancelSpecific@plt>
jmp    12e0 <main+0xe0>
mov    0x4(%rsp),%esi
mov    %r12,%rdi
call   10a0 <checkReservedSpecific@plt>
jmp    12e0 <main+0xe0>
mov    0x4(%rsp),%esi
mov    %r12,%rdi
call   1110 <showReserved@plt>
jmp    12e0 <main+0xe0>
mov    0x4(%rsp),%esi
mov    %r12,%rdi
mov    %r13,%rdx
call   10e0 <showPlan@plt>
jmp    12e0 <main+0xe0>
mov    0x4(%rsp),%esi
mov    %r12,%rdi
mov    %r13,%rdx
call   1030 <writePlanFile@plt>
jmp    12e0 <main+0xe0>
mov    $0x1,%ebp
jmp    1289 <main+0x89>

LLVM IR (-O0):
@.str = [64 x i8] c"I:\\Personal\\Education\\EAP\\PLS\\PLS50\\GE1\\CLion\\Exercise4\\bus.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%s %d\00"
@.str.3 = [43 x i8] c"Adynatos syndyasmos arithmoy theseon (%d)\0A\00"
@.str.4 = [55 x i8] c"Prepei na isxyei Theseis=4xTheseis + 5 (Theseis >= 0)\0A\00"
@.str.5 = [30 x i8] c"Adynato plithos theseon (%d)\0A\00"
@.str.6 = [44 x i8] c"Oi theseis den prepei na einai pano apo 53\0A\00"
@.str.7 = [4 x i8] c" %c\00"
@.str.8 = [40 x i8] c"H epilogh poy dosate den einai egkyrh!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [7 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca [53 x i32]
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %1
%8 = call i32* @fopen(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%11 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %10, i32* %4)
%12 = load i32*, i32** %7
%13 = call i32 @fclose(i32* %12)
%14 = load i32, i32* %4
%15 = sub nsw i32 %14, 5
%16 = srem i32 %15, 4
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %0
%19 = load i32, i32* %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
br label %91
22: ; preds = %0
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 53
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0))
br label %90
29: ; preds = %22
store i32 0, i32* %6
br label %30
30: ; preds = %38, %29
%31 = load i32, i32* %6
%32 = load i32, i32* %4
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %41
34: ; preds = %30
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [53 x i32], [53 x i32]* %5, i64 0, i64 %36
store i32 0, i32* %37
br label %38
38: ; preds = %34
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %30
41: ; preds = %30
br label %42
42: ; preds = %85, %41
%43 = call i32 (...) @showMenu()
%44 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %3)
%45 = load i8, i8* %3
%46 = sext i8 %45 to i32
switch i32 %46, label %82 [
i32 49, label %47
i32 50, label %51
i32 51, label %55
i32 52, label %59
i32 53, label %63
i32 54, label %67
i32 55, label %71
i32 56, label %76
i32 48, label %81
]
47: ; preds = %42
%48 = getelementptr inbounds [53 x i32], [53 x i32]* %5, i64 0, i64 0
%49 = load i32, i32* %4
%50 = call i32 @showBlanks(i32* %48, i32 %49)
br label %84
51: ; preds = %42
%52 = getelementptr inbounds [53 x i32], [53 x i32]* %5, i64 0, i64 0
%53 = load i32, i32* %4
%54 = call i32 @reserveSpecific(i32* %52, i32 %53, i32 0)
br label %84
55: ; preds = %42
%56 = getelementptr inbounds [53 x i32], [53 x i32]* %5, i64 0, i64 0
%57 = load i32, i32* %4
%58 = call i32 @reserveFreeWindow(i32* %56, i32 %57)
br label %84
59: ; preds = %42
%60 = getelementptr inbounds [53 x i32], [53 x i32]* %5, i64 0, i64 0
%61 = load i32, i32* %4
%62 = call i32 @cancelSpecific(i32* %60, i32 %61)
br label %84
63: ; preds = %42
%64 = getelementptr inbounds [53 x i32], [53 x i32]* %5, i64 0, i64 0
%65 = load i32, i32* %4
%66 = call i32 @checkReservedSpecific(i32* %64, i32 %65)
br label %84
67: ; preds = %42
%68 = getelementptr inbounds [53 x i32], [53 x i32]* %5, i64 0, i64 0
%69 = load i32, i32* %4
%70 = call i32 @showReserved(i32* %68, i32 %69)
br label %84
71: ; preds = %42
%72 = getelementptr inbounds [53 x i32], [53 x i32]* %5, i64 0, i64 0
%73 = load i32, i32* %4
%74 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%75 = call i32 @showPlan(i32* %72, i32 %73, i8* %74)
br label %84
76: ; preds = %42
%77 = getelementptr inbounds [53 x i32], [53 x i32]* %5, i64 0, i64 0
%78 = load i32, i32* %4
%79 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%80 = call i32 @writePlanFile(i32* %77, i32 %78, i8* %79)
br label %84
81: ; preds = %42
br label %84
82: ; preds = %42
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0))
br label %84
84: ; preds = %82, %81, %76, %71, %67, %63, %59, %55, %51, %47
br label %85
85: ; preds = %84
%86 = load i8, i8* %3
%87 = sext i8 %86 to i32
%88 = icmp ne i32 %87, 48
br i1 %88, label %42, label %89
89: ; preds = %85
store i32 1, i32* %1
br label %92
90: ; preds = %25
br label %91
91: ; preds = %90, %18
store i32 0, i32* %1
br label %92
92: ; preds = %91, %89
%93 = load i32, i32* %1
ret i32 %93
}

LLVM IR (-O2):
@.str = [64 x i8] c"I:\\Personal\\Education\\EAP\\PLS\\PLS50\\GE1\\CLion\\Exercise4\\bus.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%s %d\00"
@.str.3 = [43 x i8] c"Adynatos syndyasmos arithmoy theseon (%d)\0A\00"
@.str.5 = [30 x i8] c"Adynato plithos theseon (%d)\0A\00"
@.str.7 = [4 x i8] c" %c\00"
@str = [39 x i8] c"H epilogh poy dosate den einai egkyrh!\00"
@str.9 = [43 x i8] c"Oi theseis den prepei na einai pano apo 53\00"
@str.10 = [54 x i8] c"Prepei na isxyei Theseis=4xTheseis + 5 (Theseis >= 0)\00"
define i32 @main() {
%1 = alloca [7 x i8]
%2 = alloca i8
%3 = alloca i32
%4 = alloca [53 x i32]
%5 = bitcast [53 x i32]* %4 to i8*
%6 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32* %3)
%10 = call i32 @fclose(i32* %8)
%11 = load i32, i32* %3
%12 = add i32 %11, 3
%13 = and i32 %12, 3
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %60
15: ; preds = %0
%16 = icmp sgt i32 %11, 53
br i1 %16, label %60, label %17
17: ; preds = %15
%18 = icmp sgt i32 %11, 0
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = zext i32 %11 to i64
%21 = shl nuw nsw i64 %20, 2
br label %22
22: ; preds = %19, %17
%23 = getelementptr inbounds [53 x i32], [53 x i32]* %4, i64 0, i64 0
br label %24
24: ; preds = %22, %57
%25 = call i32 (...) @showMenu()
%26 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %2)
%27 = load i8, i8* %2
%28 = sext i8 %27 to i32
switch i32 %28, label %53 [
i32 49, label %29
i32 50, label %32
i32 51, label %35
i32 52, label %38
i32 53, label %41
i32 54, label %44
i32 55, label %47
i32 56, label %50
i32 48, label %57
]
29: ; preds = %24
%30 = load i32, i32* %3
%31 = call i32 @showBlanks(i32* %23, i32 %30)
br label %55
32: ; preds = %24
%33 = load i32, i32* %3
%34 = call i32 @reserveSpecific(i32* %23, i32 %33, i32 0)
br label %55
35: ; preds = %24
%36 = load i32, i32* %3
%37 = call i32 @reserveFreeWindow(i32* %23, i32 %36)
br label %55
38: ; preds = %24
%39 = load i32, i32* %3
%40 = call i32 @cancelSpecific(i32* %23, i32 %39)
br label %55
41: ; preds = %24
%42 = load i32, i32* %3
%43 = call i32 @checkReservedSpecific(i32* %23, i32 %42)
br label %55
44: ; preds = %24
%45 = load i32, i32* %3
%46 = call i32 @showReserved(i32* %23, i32 %45)
br label %55
47: ; preds = %24
%48 = load i32, i32* %3
%49 = call i32 @showPlan(i32* %23, i32 %48, i8* %6)
br label %55
50: ; preds = %24
%51 = load i32, i32* %3
%52 = call i32 @writePlanFile(i32* %23, i32 %51, i8* %6)
br label %55
53: ; preds = %24
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %55
55: ; preds = %53, %50, %47, %44, %41, %38, %35, %32, %29
%56 = load i8, i8* %2
br label %57
57: ; preds = %55, %24
%58 = phi i8 [ %56, %55 ], [ %27, %24 ]
%59 = icmp eq i8 %58, 48
br i1 %59, label %65, label %24
60: ; preds = %15, %0
%61 = phi i8* [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), %0 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), %15 ]
%62 = phi i8* [ getelementptr inbounds ([54 x i8], [54 x i8]* @str.10, i64 0, i64 0), %0 ], [ getelementptr inbounds ([43 x i8], [43 x i8]* @str.9, i64 0, i64 0), %15 ]
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %61, i32 %11)
%64 = call i32 @puts(i8* dereferenceable(1) %62)
br label %65
65: ; preds = %57, %60
%66 = phi i32 [ 0, %60 ], [ 1, %57 ]
ret i32 %66
}