#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;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ ece391_fdputs(int, char *);
int /*<<< orphan*/ ece391_itoa(int, char *, int);
int ece391_read(int /*<<< orphan*/, char *, int);
int ece391_strlen(char *);
int main() {
  uint32_t i, cnt, max = 0;
  uint8_t buf[1024];
  ece391_fdputs(
      1,
      (uint8_t *)"Enter the Test Number: (0): 100, (1): 10000, (2): 100000\n");
  if (-1 == (cnt = ece391_read(0, buf, 1024 - 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 {
    switch (buf[0]) {
    case '0':
      max = 100;
      break;
    case '1':
      max = 10000;
      break;
    case '2':
      max = 100000;
      break;
    }
  }
  for (i = 0; i < max; i++) {
    ece391_itoa(i + 1, buf, 10);
    ece391_fdputs(1, buf);
    ece391_fdputs(1, (uint8_t *)"\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x1,%edi
lea    0xe9b(%rip),%rsi
call   1040 <ece391_fdputs@plt>
lea    -0x410(%rbp),%rsi
xor    %edi,%edi
mov    $0x3ff,%edx
call   1050 <ece391_read@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11ac <main+0x6c>
mov    $0x1,%edi
lea    0xe9f(%rip),%rsi
call   1040 <ece391_fdputs@plt>
movl   $0x3,-0x4(%rbp)
jmp    12e7 <main+0x1a7>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
call   1030 <ece391_strlen@plt>
cmp    $0x2,%eax
jg     1202 <main+0xc2>
lea    -0x410(%rbp),%rdi
call   1030 <ece391_strlen@plt>
cmp    $0x2,%eax
jne    121f <main+0xdf>
movsbl -0x410(%rbp),%eax
cmp    $0x30,%eax
jl     1202 <main+0xc2>
movsbl -0x410(%rbp),%eax
cmp    $0x32,%eax
jle    121f <main+0xdf>
mov    $0x1,%edi
lea    0xe52(%rip),%rsi
call   1040 <ece391_fdputs@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e7 <main+0x1a7>
movsbl -0x410(%rbp),%eax
mov    %eax,-0x414(%rbp)
sub    $0x30,%eax
je     1262 <main+0x122>
jmp    123a <main+0xfa>
mov    -0x414(%rbp),%eax
sub    $0x31,%eax
je     126e <main+0x12e>
jmp    124e <main+0x10e>
mov    -0x414(%rbp),%eax
sub    $0x32,%eax
je     127a <main+0x13a>
jmp    1281 <main+0x141>
movl   $0x64,-0x10(%rbp)
jmp    1281 <main+0x141>
movl   $0x2710,-0x10(%rbp)
jmp    1281 <main+0x141>
movl   $0x186a0,-0x10(%rbp)
jmp    1286 <main+0x146>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12e0 <main+0x1a0>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0x410(%rbp),%rsi
mov    $0xa,%edx
call   1060 <ece391_itoa@plt>
lea    -0x410(%rbp),%rsi
mov    $0x1,%edi
call   1040 <ece391_fdputs@plt>
mov    $0x1,%edi
lea    0xda0(%rip),%rsi
call   1040 <ece391_fdputs@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    128d <main+0x14d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
lea    0xeaa(%rip),%rsi
mov    $0x1,%edi
call   1040 <ece391_fdputs@plt>
xor    %r14d,%r14d
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x3ff,%edx
call   1050 <ece391_read@plt>
cmp    $0xffffffff,%eax
je     122d <main+0xed>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1030 <ece391_strlen@plt>
lea    0xed0(%rip),%rbx
cmp    $0x2,%eax
jg     123a <main+0xfa>
mov    %rsp,%rdi
call   1030 <ece391_strlen@plt>
movsbq (%rsp),%rcx
cmp    $0x2,%eax
jne    11b6 <main+0x76>
lea    -0x33(%rcx),%eax
cmp    $0xfd,%al
jb     123a <main+0xfa>
lea    -0x30(%rcx),%eax
xor    %r14d,%r14d
cmp    $0x2,%eax
ja     1247 <main+0x107>
lea    0xea4(%rip),%rax
xor    %ebx,%ebx
sub    -0xc0(%rax,%rcx,4),%ebx
xor    %r14d,%r14d
mov    $0x1,%ebp
mov    %rsp,%r12
lea    0xe86(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0xa,%edx
call   1060 <ece391_itoa@plt>
mov    $0x1,%edi
mov    %r12,%rsi
call   1040 <ece391_fdputs@plt>
mov    $0x1,%edi
mov    %r15,%rsi
call   1040 <ece391_fdputs@plt>
lea    (%rbx,%rbp,1),%eax
add    $0x1,%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x1,%eax
jne    11f0 <main+0xb0>
jmp    1247 <main+0x107>
mov    $0x3,%r14d
lea    0xe00(%rip),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
call   1040 <ece391_fdputs@plt>
mov    %r14d,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [58 x i8] c"Enter the Test Number: (0): 100, (1): 10000, (2): 100000\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"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
store i32 0, i32* %1
store i32 0, i32* %4
%6 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = call i32 @ece391_read(i32 0, i8* %7, i32 1023)
store i32 %8, i32* %3
%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 %60
12: ; preds = %0
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %14
store i8 0, i8* %15
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, 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 [1024 x i8], [1024 x i8]* %5, 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 [1024 x i8], [1024 x i8]* %5, 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 [1024 x i8], [1024 x i8]* %5, 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 %60
35: ; preds = %28, %19
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
switch i32 %38, label %42 [
i32 48, label %39
i32 49, label %40
i32 50, label %41
]
39: ; preds = %35
store i32 100, i32* %4
br label %42
40: ; preds = %35
store i32 10000, i32* %4
br label %42
41: ; preds = %35
store i32 100000, i32* %4
br label %42
42: ; preds = %35, %41, %40, %39
br label %43
43: ; preds = %42
store i32 0, i32* %2
br label %44
44: ; preds = %56, %43
%45 = load i32, i32* %2
%46 = load i32, i32* %4
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %59
48: ; preds = %44
%49 = load i32, i32* %2
%50 = add nsw i32 %49, 1
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%52 = call i32 @ece391_itoa(i32 %50, i8* %51, i32 10)
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%54 = call i32 @ece391_fdputs(i32 1, i8* %53)
%55 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %48
%57 = load i32, i32* %2
%58 = add nsw i32 %57, 1
store i32 %58, i32* %2
br label %44
59: ; preds = %44
store i32 0, i32* %1
br label %60
60: ; preds = %59, %33, %10
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str = [58 x i8] c"Enter the Test Number: (0): 100, (1): 10000, (2): 100000\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"
@.str.3 = [2 x i8] c"\0A\00"
@switch.table.main = [3 x i32] [i32 100, i32 10000, i32 100000]
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @ece391_read(i32 0, i8* %2, i32 1023)
%5 = icmp eq i32 %4, -1
br i1 %5, label %33, label %6
6: ; preds = %0
%7 = sext i32 %4 to i64
%8 = getelementptr inbounds [1024 x i8], [1024 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 %33, label %11
11: ; preds = %6
%12 = call i32 @ece391_strlen(i8* %2)
%13 = icmp eq i32 %12, 2
%14 = load i8, i8* %2
%15 = add i8 %14, -51
%16 = icmp ult i8 %15, -3
%17 = select i1 %13, i1 %16, i1 false
br i1 %17, label %33, label %18
18: ; preds = %11
%19 = sext i8 %14 to i32
%20 = add nsw i32 %19, -48
%21 = icmp ult i32 %20, 3
br i1 %21, label %22, label %37
22: ; preds = %18
%23 = sext i32 %20 to i64
%24 = getelementptr inbounds [3 x i32], [3 x i32]* @switch.table.main, i64 0, i64 %23
%25 = load i32, i32* %24
br label %26
26: ; preds = %22, %26
%27 = phi i32 [ %28, %26 ], [ 0, %22 ]
%28 = add nuw nsw i32 %27, 1
%29 = call i32 @ece391_itoa(i32 %28, i8* %2, i32 10)
%30 = call i32 @ece391_fdputs(i32 1, i8* %2)
%31 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i32 %28, %25
br i1 %32, label %37, label %26
33: ; preds = %6, %11, %0
%34 = 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), %11 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %6 ]
%35 = phi i32 [ 3, %0 ], [ 0, %11 ], [ 0, %6 ]
%36 = call i32 @ece391_fdputs(i32 1, i8* %34)
br label %37
37: ; preds = %26, %18, %33
%38 = phi i32 [ 0, %18 ], [ %35, %33 ], [ 0, %26 ]
ret i32 %38
}