#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 scalar_t__ uint8_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ ece391_fdputs(int, scalar_t__ *);
int ece391_read(int /*<<< orphan*/, scalar_t__ *, int);
int err_big_fd();
int err_neg_fd();
int err_open();
int err_open_lots();
int err_stdin_out();
int err_syscall_num();
int err_unopened();
int err_vidmap();
int main() {
  int32_t cnt, select;
  uint8_t buf[128];
  int fail = 0;
  ece391_fdputs(1, (uint8_t *)"Choose from tests 1-8. 0 to run all: ");
  if (-1 == (cnt = ece391_read(0, buf, 127))) {
    ece391_fdputs(1, (uint8_t *)"Can't read test #\n");
    return 2;
  }
  select = (int)(buf[0] - '0');
  switch (select) {
  case 0:
    fail += err_neg_fd();
    fail += err_big_fd();
    fail += err_open_lots();
    fail += err_open();
    fail += err_unopened();
    fail += err_vidmap();
    fail += err_stdin_out();
    fail += err_syscall_num();
    if (fail) {
      ece391_fdputs(1, (uint8_t *)"\nOverall Tests: FAIL\n");
    } else {
      ece391_fdputs(1, (uint8_t *)"\nOverall Tests: PASS\n");
    }
    return fail;
  case 1:
    return err_neg_fd();
  case 2:
    return err_big_fd();
  case 3:
    return err_open_lots();
  case 4:
    return err_open();
  case 5:
    return err_unopened();
  case 6:
    return err_vidmap();
  case 7:
    return err_stdin_out();
  case 8:
    return err_syscall_num();
  default:
    ece391_fdputs(1,
                  (uint8_t *)"Invalid test number. Choose from tests 1-8 or 0");
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x414(%rbp)
mov    $0x1,%edi
lea    0xe5c(%rip),%rsi
call   1080 <ece391_fdputs@plt>
lea    -0x410(%rbp),%rsi
xor    %edi,%edi
mov    $0x7f,%edx
call   10a0 <ece391_read@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    120f <main+0x6f>
mov    $0x1,%edi
lea    0xe4c(%rip),%rsi
call   1080 <ece391_fdputs@plt>
movl   $0x2,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    -0x410(%rbp),%eax
add    $0xffffffd0,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,-0x420(%rbp)
sub    $0x8,%rax
ja     1398 <main+0x1f8>
mov    -0x420(%rbp),%rax
lea    0xdc3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1060 <err_neg_fd@plt>
add    -0x414(%rbp),%eax
mov    %eax,-0x414(%rbp)
mov    $0x0,%al
call   1040 <err_big_fd@plt>
add    -0x414(%rbp),%eax
mov    %eax,-0x414(%rbp)
mov    $0x0,%al
call   10b0 <err_open_lots@plt>
add    -0x414(%rbp),%eax
mov    %eax,-0x414(%rbp)
mov    $0x0,%al
call   10c0 <err_open@plt>
add    -0x414(%rbp),%eax
mov    %eax,-0x414(%rbp)
mov    $0x0,%al
call   1030 <err_unopened@plt>
add    -0x414(%rbp),%eax
mov    %eax,-0x414(%rbp)
mov    $0x0,%al
call   1090 <err_vidmap@plt>
add    -0x414(%rbp),%eax
mov    %eax,-0x414(%rbp)
mov    $0x0,%al
call   1050 <err_stdin_out@plt>
add    -0x414(%rbp),%eax
mov    %eax,-0x414(%rbp)
mov    $0x0,%al
call   1070 <err_syscall_num@plt>
add    -0x414(%rbp),%eax
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
je     1301 <main+0x161>
mov    $0x1,%edi
lea    0xd66(%rip),%rsi
call   1080 <ece391_fdputs@plt>
jmp    1312 <main+0x172>
mov    $0x1,%edi
lea    0xd66(%rip),%rsi
call   1080 <ece391_fdputs@plt>
mov    -0x414(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    $0x0,%al
call   1060 <err_neg_fd@plt>
mov    %eax,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    $0x0,%al
call   1040 <err_big_fd@plt>
mov    %eax,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    $0x0,%al
call   10b0 <err_open_lots@plt>
mov    %eax,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    $0x0,%al
call   10c0 <err_open@plt>
mov    %eax,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    $0x0,%al
call   1030 <err_unopened@plt>
mov    %eax,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    $0x0,%al
call   1090 <err_vidmap@plt>
mov    %eax,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    $0x0,%al
call   1050 <err_stdin_out@plt>
mov    %eax,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    $0x0,%al
call   1070 <err_syscall_num@plt>
mov    %eax,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    $0x1,%edi
lea    0xce5(%rip),%rsi
call   1080 <ece391_fdputs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
lea    0xe72(%rip),%rsi
mov    $0x1,%edi
call   1080 <ece391_fdputs@plt>
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x7f,%edx
call   10a0 <ece391_read@plt>
cmp    $0xffffffff,%eax
je     1265 <main+0xc5>
mov    (%rsp),%eax
add    $0xffffffd0,%eax
cmp    $0x8,%eax
ja     1289 <main+0xe9>
lea    0xe16(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
call   1060 <err_neg_fd@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <err_big_fd@plt>
mov    %eax,%ebp
add    %ebx,%ebp
xor    %eax,%eax
call   10b0 <err_open_lots@plt>
mov    %eax,%ebx
add    %ebp,%ebx
xor    %eax,%eax
call   10c0 <err_open@plt>
mov    %eax,%ebp
add    %ebx,%ebp
xor    %eax,%eax
call   1030 <err_unopened@plt>
mov    %eax,%ebx
add    %ebp,%ebx
xor    %eax,%eax
call   1090 <err_vidmap@plt>
mov    %eax,%ebp
add    %ebx,%ebp
xor    %eax,%eax
call   1050 <err_stdin_out@plt>
mov    %eax,%r14d
add    %ebp,%r14d
xor    %eax,%eax
call   1070 <err_syscall_num@plt>
mov    %eax,%ebx
add    %r14d,%ebx
je     12ea <main+0x14a>
lea    0xe04(%rip),%rsi
mov    $0x1,%edi
call   1080 <ece391_fdputs@plt>
jmp    127b <main+0xdb>
lea    0xdde(%rip),%rsi
mov    $0x1,%edi
call   1080 <ece391_fdputs@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdf9(%rip),%rsi
jmp    12f1 <main+0x151>
xor    %eax,%eax
call   1060 <err_neg_fd@plt>
mov    %eax,%ebx
jmp    127b <main+0xdb>
xor    %eax,%eax
call   1040 <err_big_fd@plt>
mov    %eax,%ebx
jmp    127b <main+0xdb>
xor    %eax,%eax
call   10b0 <err_open_lots@plt>
mov    %eax,%ebx
jmp    127b <main+0xdb>
xor    %eax,%eax
call   10c0 <err_open@plt>
mov    %eax,%ebx
jmp    127b <main+0xdb>
xor    %eax,%eax
call   1030 <err_unopened@plt>
mov    %eax,%ebx
jmp    127b <main+0xdb>
xor    %eax,%eax
call   1090 <err_vidmap@plt>
mov    %eax,%ebx
jmp    127b <main+0xdb>
xor    %eax,%eax
call   1050 <err_stdin_out@plt>
mov    %eax,%ebx
jmp    127b <main+0xdb>
xor    %eax,%eax
call   1070 <err_syscall_num@plt>
mov    %eax,%ebx
jmp    127b <main+0xdb>
lea    0xd82(%rip),%rsi
mov    $0x1,%edi
call   1080 <ece391_fdputs@plt>
xor    %ebx,%ebx
jmp    127b <main+0xdb>

LLVM IR (-O0):
@.str = [38 x i8] c"Choose from tests 1-8. 0 to run all: \00"
@.str.1 = [19 x i8] c"Can't read test #\0A\00"
@.str.2 = [22 x i8] c"\0AOverall Tests: FAIL\0A\00"
@.str.3 = [22 x i8] c"\0AOverall Tests: PASS\0A\00"
@.str.4 = [48 x i8] c"Invalid test number. Choose from tests 1-8 or 0\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [128 x i64]
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%6 = call i32 @ece391_fdputs(i32 1, i64* bitcast ([38 x i8]* @.str to i64*))
%7 = getelementptr inbounds [128 x i64], [128 x i64]* %4, i64 0, i64 0
%8 = call i32 @ece391_read(i32 0, i64* %7, i32 127)
store i32 %8, i32* %2
%9 = icmp eq i32 -1, %8
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @ece391_fdputs(i32 1, i64* bitcast ([19 x i8]* @.str.1 to i64*))
store i32 2, i32* %1
br label %70
12: ; preds = %0
%13 = getelementptr inbounds [128 x i64], [128 x i64]* %4, i64 0, i64 0
%14 = load i64, i64* %13
%15 = sub nsw i64 %14, 48
%16 = trunc i64 %15 to i32
store i32 %16, i32* %3
%17 = load i32, i32* %3
switch i32 %17, label %67 [
i32 0, label %18
i32 1, label %51
i32 2, label %53
i32 3, label %55
i32 4, label %57
i32 5, label %59
i32 6, label %61
i32 7, label %63
i32 8, label %65
]
18: ; preds = %12
%19 = call i32 (...) @err_neg_fd()
%20 = load i32, i32* %5
%21 = add nsw i32 %20, %19
store i32 %21, i32* %5
%22 = call i32 (...) @err_big_fd()
%23 = load i32, i32* %5
%24 = add nsw i32 %23, %22
store i32 %24, i32* %5
%25 = call i32 (...) @err_open_lots()
%26 = load i32, i32* %5
%27 = add nsw i32 %26, %25
store i32 %27, i32* %5
%28 = call i32 (...) @err_open()
%29 = load i32, i32* %5
%30 = add nsw i32 %29, %28
store i32 %30, i32* %5
%31 = call i32 (...) @err_unopened()
%32 = load i32, i32* %5
%33 = add nsw i32 %32, %31
store i32 %33, i32* %5
%34 = call i32 (...) @err_vidmap()
%35 = load i32, i32* %5
%36 = add nsw i32 %35, %34
store i32 %36, i32* %5
%37 = call i32 (...) @err_stdin_out()
%38 = load i32, i32* %5
%39 = add nsw i32 %38, %37
store i32 %39, i32* %5
%40 = call i32 (...) @err_syscall_num()
%41 = load i32, i32* %5
%42 = add nsw i32 %41, %40
store i32 %42, i32* %5
%43 = load i32, i32* %5
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %18
%46 = call i32 @ece391_fdputs(i32 1, i64* bitcast ([22 x i8]* @.str.2 to i64*))
br label %49
47: ; preds = %18
%48 = call i32 @ece391_fdputs(i32 1, i64* bitcast ([22 x i8]* @.str.3 to i64*))
br label %49
49: ; preds = %47, %45
%50 = load i32, i32* %5
store i32 %50, i32* %1
br label %70
51: ; preds = %12
%52 = call i32 (...) @err_neg_fd()
store i32 %52, i32* %1
br label %70
53: ; preds = %12
%54 = call i32 (...) @err_big_fd()
store i32 %54, i32* %1
br label %70
55: ; preds = %12
%56 = call i32 (...) @err_open_lots()
store i32 %56, i32* %1
br label %70
57: ; preds = %12
%58 = call i32 (...) @err_open()
store i32 %58, i32* %1
br label %70
59: ; preds = %12
%60 = call i32 (...) @err_unopened()
store i32 %60, i32* %1
br label %70
61: ; preds = %12
%62 = call i32 (...) @err_vidmap()
store i32 %62, i32* %1
br label %70
63: ; preds = %12
%64 = call i32 (...) @err_stdin_out()
store i32 %64, i32* %1
br label %70
65: ; preds = %12
%66 = call i32 (...) @err_syscall_num()
store i32 %66, i32* %1
br label %70
67: ; preds = %12
%68 = call i32 @ece391_fdputs(i32 1, i64* bitcast ([48 x i8]* @.str.4 to i64*))
br label %69
69: ; preds = %67
store i32 0, i32* %1
br label %70
70: ; preds = %69, %65, %63, %61, %59, %57, %55, %53, %51, %49, %10
%71 = load i32, i32* %1
ret i32 %71
}

LLVM IR (-O2):
@.str = [38 x i8] c"Choose from tests 1-8. 0 to run all: \00"
@.str.1 = [19 x i8] c"Can't read test #\0A\00"
@.str.2 = [22 x i8] c"\0AOverall Tests: FAIL\0A\00"
@.str.3 = [22 x i8] c"\0AOverall Tests: PASS\0A\00"
@.str.4 = [48 x i8] c"Invalid test number. Choose from tests 1-8 or 0\00"
define i32 @main() {
%1 = alloca [128 x i64]
%2 = bitcast [128 x i64]* %1 to i8*
%3 = tail call i32 @ece391_fdputs(i32 1, i64* bitcast ([38 x i8]* @.str to i64*))
%4 = getelementptr inbounds [128 x i64], [128 x i64]* %1, i64 0, i64 0
%5 = call i32 @ece391_read(i32 0, i64* %4, i32 127)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @ece391_fdputs(i32 1, i64* bitcast ([19 x i8]* @.str.1 to i64*))
br label %51
9: ; preds = %0
%10 = load i64, i64* %4
%11 = trunc i64 %10 to i32
switch i32 %11, label %49 [
i32 48, label %12
i32 49, label %33
i32 50, label %35
i32 51, label %37
i32 52, label %39
i32 53, label %41
i32 54, label %43
i32 55, label %45
i32 56, label %47
]
12: ; preds = %9
%13 = call i32 (...) @err_neg_fd()
%14 = call i32 (...) @err_big_fd()
%15 = add nsw i32 %14, %13
%16 = call i32 (...) @err_open_lots()
%17 = add nsw i32 %15, %16
%18 = call i32 (...) @err_open()
%19 = add nsw i32 %17, %18
%20 = call i32 (...) @err_unopened()
%21 = add nsw i32 %19, %20
%22 = call i32 (...) @err_vidmap()
%23 = add nsw i32 %21, %22
%24 = call i32 (...) @err_stdin_out()
%25 = add nsw i32 %23, %24
%26 = call i32 (...) @err_syscall_num()
%27 = add nsw i32 %25, %26
%28 = icmp eq i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %12
%30 = call i32 @ece391_fdputs(i32 1, i64* bitcast ([22 x i8]* @.str.2 to i64*))
br label %51
31: ; preds = %12
%32 = call i32 @ece391_fdputs(i32 1, i64* bitcast ([22 x i8]* @.str.3 to i64*))
br label %51
33: ; preds = %9
%34 = call i32 (...) @err_neg_fd()
br label %51
35: ; preds = %9
%36 = call i32 (...) @err_big_fd()
br label %51
37: ; preds = %9
%38 = call i32 (...) @err_open_lots()
br label %51
39: ; preds = %9
%40 = call i32 (...) @err_open()
br label %51
41: ; preds = %9
%42 = call i32 (...) @err_unopened()
br label %51
43: ; preds = %9
%44 = call i32 (...) @err_vidmap()
br label %51
45: ; preds = %9
%46 = call i32 (...) @err_stdin_out()
br label %51
47: ; preds = %9
%48 = call i32 (...) @err_syscall_num()
br label %51
49: ; preds = %9
%50 = call i32 @ece391_fdputs(i32 1, i64* bitcast ([48 x i8]* @.str.4 to i64*))
br label %51
51: ; preds = %29, %31, %49, %47, %45, %43, %41, %39, %37, %35, %33, %7
%52 = phi i32 [ 2, %7 ], [ 0, %49 ], [ %48, %47 ], [ %46, %45 ], [ %44, %43 ], [ %42, %41 ], [ %40, %39 ], [ %38, %37 ], [ %36, %35 ], [ %34, %33 ], [ 0, %31 ], [ %27, %29 ]
ret i32 %52
}