#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 char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ ece391_fdputs(int, char *);
int ece391_read(int /*<<< orphan*/, char *, int);
int ece391_strlen(char *);
int main() {
  int cnt;
  uint8_t buf[1000];
  ece391_fdputs(1, (uint8_t *)"Enter the Test Number: (0): Div by 0, (1): "
                              "Deref NULL, (2): ???\n");
  if (-1 == (cnt = ece391_read(0, buf, 1000 - 1))) {
    ece391_fdputs(1, (uint8_t *)"Can't read the number from keyboard.\n");
    return 3;
  }
  buf[cnt] = '\0';
  if ((ece391_strlen(buf) > 2) ||
      ((ece391_strlen(buf) == 2) && ((buf[0] < '0') || (buf[0] > '2')))) {
    ece391_fdputs(1, (uint8_t *)"Wrong Choice!\n");
    return 0;
  } else {
    int i;
    int *j;
    switch (buf[0]) {
    case '0':
      i = 1;
      i--;
      i /= i;
      break;
    case '1':
      j = 0;
      *j = 1;
      break;
    case '2':
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
lea    0xeb2(%rip),%rsi
call   1040 <ece391_fdputs@plt>
lea    -0x3f0(%rbp),%rsi
xor    %edi,%edi
mov    $0x3e7,%edx
call   1050 <ece391_read@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1195 <main+0x65>
mov    $0x1,%edi
lea    0xebd(%rip),%rsi
call   1040 <ece391_fdputs@plt>
movl   $0x3,-0x4(%rbp)
jmp    12ac <main+0x17c>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x3f0(%rbp,%rax,1)
lea    -0x3f0(%rbp),%rdi
call   1030 <ece391_strlen@plt>
cmp    $0x2,%eax
jg     11eb <main+0xbb>
lea    -0x3f0(%rbp),%rdi
call   1030 <ece391_strlen@plt>
cmp    $0x2,%eax
jne    1208 <main+0xd8>
movsbl -0x3f0(%rbp),%eax
cmp    $0x30,%eax
jl     11eb <main+0xbb>
movsbl -0x3f0(%rbp),%eax
cmp    $0x32,%eax
jle    1208 <main+0xd8>
mov    $0x1,%edi
lea    0xe70(%rip),%rsi
call   1040 <ece391_fdputs@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ac <main+0x17c>
movsbl -0x3f0(%rbp),%eax
mov    %eax,-0x404(%rbp)
sub    $0x30,%eax
je     124b <main+0x11b>
jmp    1223 <main+0xf3>
mov    -0x404(%rbp),%eax
sub    $0x31,%eax
je     127e <main+0x14e>
jmp    1237 <main+0x107>
mov    -0x404(%rbp),%eax
sub    $0x32,%eax
je     129b <main+0x16b>
jmp    12a0 <main+0x170>
movl   $0x1,-0x3f4(%rbp)
mov    -0x3f4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3f4(%rbp)
mov    -0x3f4(%rbp),%ecx
mov    -0x3f4(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x3f4(%rbp)
jmp    12a0 <main+0x170>
movq   $0x0,-0x400(%rbp)
mov    -0x400(%rbp),%rax
movl   $0x1,(%rax)
jmp    12a0 <main+0x170>
jmp    12a0 <main+0x170>
jmp    12a5 <main+0x175>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
lea    0xebf(%rip),%rsi
mov    $0x1,%edi
call   1040 <ece391_fdputs@plt>
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x3e7,%edx
call   1050 <ece391_read@plt>
cmp    $0xffffffff,%eax
je     1197 <main+0x67>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1030 <ece391_strlen@plt>
lea    0xef1(%rip),%r14
cmp    $0x2,%eax
jg     11a3 <main+0x73>
mov    %rsp,%rdi
call   1030 <ece391_strlen@plt>
xor    %ebx,%ebx
cmp    $0x2,%eax
jne    11b0 <main+0x80>
mov    (%rsp),%al
add    $0xcd,%al
xor    %ebx,%ebx
cmp    $0xfc,%al
jbe    11a3 <main+0x73>
jmp    11b0 <main+0x80>
mov    $0x3,%ebx
lea    0xe9e(%rip),%r14
mov    $0x1,%edi
mov    %r14,%rsi
call   1040 <ece391_fdputs@plt>
mov    %ebx,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [65 x i8] c"Enter the Test Number: (0): Div by 0, (1): Deref NULL, (2): ???\0A\00"
@.str.1 = [38 x i8] c"Can't read the number from keyboard.\0A\00"
@.str.2 = [15 x i8] c"Wrong Choice!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000 x i8]
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
%6 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%8 = call i32 @ece391_read(i32 0, i8* %7, i32 999)
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, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
store i32 3, i32* %1
br label %50
12: ; preds = %0
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %14
store i8 0, i8* %15
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%17 = call i32 @ece391_strlen(i8* %16)
%18 = icmp sgt i32 %17, 2
br i1 %18, label %33, label %19
19: ; preds = %12
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%21 = call i32 @ece391_strlen(i8* %20)
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %35
23: ; preds = %19
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp slt i32 %26, 48
br i1 %27, label %33, label %28
28: ; preds = %23
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp sgt i32 %31, 50
br i1 %32, label %33, label %35
33: ; preds = %28, %23, %12
%34 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %50
35: ; preds = %28, %19
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
switch i32 %38, label %48 [
i32 48, label %39
i32 49, label %45
i32 50, label %47
]
39: ; preds = %35
store i32 1, i32* %4
%40 = load i32, i32* %4
%41 = add nsw i32 %40, -1
store i32 %41, i32* %4
%42 = load i32, i32* %4
%43 = load i32, i32* %4
%44 = sdiv i32 %43, %42
store i32 %44, i32* %4
br label %48
45: ; preds = %35
store i32* null, i32** %5
%46 = load i32*, i32** %5
store i32 1, i32* %46
br label %48
47: ; preds = %35
br label %48
48: ; preds = %35, %47, %45, %39
br label %49
49: ; preds = %48
store i32 0, i32* %1
br label %50
50: ; preds = %49, %33, %10
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@.str = [65 x i8] c"Enter the Test Number: (0): Div by 0, (1): Deref NULL, (2): ???\0A\00"
@.str.1 = [38 x i8] c"Can't read the number from keyboard.\0A\00"
@.str.2 = [15 x i8] c"Wrong Choice!\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @ece391_read(i32 0, i8* %2, i32 999)
%5 = icmp eq i32 %4, -1
br i1 %5, label %18, label %6
6: ; preds = %0
%7 = sext i32 %4 to i64
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %7
store i8 0, i8* %8
%9 = call i32 @ece391_strlen(i8* %2)
%10 = icmp sgt i32 %9, 2
br i1 %10, label %18, label %11
11: ; preds = %6
%12 = call i32 @ece391_strlen(i8* %2)
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = load i8, i8* %2
%16 = add i8 %15, -51
%17 = icmp ult i8 %16, -3
br i1 %17, label %18, label %22
18: ; preds = %6, %14, %0
%19 = phi i8* [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), %0 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %14 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %6 ]
%20 = phi i32 [ 3, %0 ], [ 0, %14 ], [ 0, %6 ]
%21 = call i32 @ece391_fdputs(i32 1, i8* %19)
br label %22
22: ; preds = %18, %11, %14
%23 = phi i32 [ 0, %14 ], [ 0, %11 ], [ %20, %18 ]
ret i32 %23
}