#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*/ bug_a();
int /*<<< orphan*/ bug_b();
int /*<<< orphan*/ bug_c();
int /*<<< orphan*/ bug_d();
int /*<<< orphan*/ bug_e();
int /*<<< orphan*/ bug_f();
int /*<<< orphan*/ bug_l();
int /*<<< orphan*/ bug_s();
int /*<<< orphan*/ bug_w();
int /*<<< orphan*/ cup(int, int);
int /*<<< orphan*/ ed(int);
int menu(char **);
int /*<<< orphan*/ println(char *);
tst_bugs() {
  int i, menuchoice;
  static char *menutable[] = {
      "Exit to main menu",
      "Bug A: Smooth scroll to jump scroll",
      "Bug B: Scrolling region",
      "Bug C: Wide to narrow screen",
      "Bug D: Narrow to wide screen",
      "Bug E: Cursor move from double- to single-wide line",
      "Bug F: Column mode escape sequence",
      "Wrap around with cursor addressing",
      "Erase right half of double width lines",
      "Funny scroll regions",
      ""};
  static char *hmsg[] = {
      "Test of known bugs in the DEC VT100 series. The numbering of some of",
      "the bugs (A-F) refers to the article 'VT100 MAGIC' by Sami Tabih in",
      "the 'Proceedings of the DEC Users Society' at St. Louis, Missouri, May",
      "1983. To understand some of the tests, you have to look at the source",
      "code or the article. Of course, a good VT100-compatible terminal",
      "should not have these bugs (or have some means of disabling them)! If",
      "a bug appears, you might want to RESET the terminal before continuing",
      "the test. There is a test of the RESET function in the main menu.",
      ""};
  do {
    ed(2);
    cup(1, 1);
    for (i = 0; *hmsg[i]; i++)
      println(hmsg[i]);
    println("");
    println("          Choose bug test number:");
    menuchoice = menu(menutable);
    switch (menuchoice) {
    case 1:
      bug_a();
      break;
    case 2:
      bug_b();
      break;
    case 3:
      bug_c();
      break;
    case 4:
      bug_d();
      break;
    case 5:
      bug_e();
      break;
    case 6:
      bug_f();
      break;
    case 7:
      bug_w();
      break;
    case 8:
      bug_l();
      break;
    case 9:
      bug_s();
      break;
    }
  } while (menuchoice);
}


x86 assembly (clang, -O0):
<tst_bugs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x2,%edi
call   10a0 <ed@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1090 <cup@plt>
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rcx
lea    0x2ef0(%rip),%rax
mov    (%rax,%rcx,8),%rax
cmpb   $0x0,(%rax)
je     122f <tst_bugs+0x5f>
movslq -0x8(%rbp),%rcx
lea    0x2ed8(%rip),%rax
mov    (%rax,%rcx,8),%rdi
call   1080 <println@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f5 <tst_bugs+0x25>
lea    0x1150(%rip),%rdi
call   1080 <println@plt>
lea    0x1145(%rip),%rdi
call   1080 <println@plt>
lea    0x2e42(%rip),%rdi
call   1030 <menu@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x8,%eax
ja     12e6 <tst_bugs+0x116>
mov    -0x18(%rbp),%rax
lea    0xd8a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   10c0 <bug_a@plt>
jmp    12e6 <tst_bugs+0x116>
mov    $0x0,%al
call   1050 <bug_b@plt>
jmp    12e6 <tst_bugs+0x116>
mov    $0x0,%al
call   10d0 <bug_c@plt>
jmp    12e6 <tst_bugs+0x116>
mov    $0x0,%al
call   1060 <bug_d@plt>
jmp    12e6 <tst_bugs+0x116>
mov    $0x0,%al
call   10e0 <bug_e@plt>
jmp    12e6 <tst_bugs+0x116>
mov    $0x0,%al
call   1040 <bug_f@plt>
jmp    12e6 <tst_bugs+0x116>
mov    $0x0,%al
call   10b0 <bug_w@plt>
jmp    12e6 <tst_bugs+0x116>
mov    $0x0,%al
call   1070 <bug_l@plt>
jmp    12e6 <tst_bugs+0x116>
mov    $0x0,%al
call   10f0 <bug_s@plt>
jmp    12eb <tst_bugs+0x11b>
cmpl   $0x0,-0xc(%rbp)
jne    11d8 <tst_bugs+0x8>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tst_bugs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0x1121(%rip),%r14
lea    0x1160(%rip),%r15
lea    0x119a(%rip),%r12
lea    0x1194(%rip),%r13
lea    0x2e92(%rip),%rbx
lea    0xdfb(%rip),%rbp
jmp    1210 <tst_bugs+0x40>
xor    %eax,%eax
call   10f0 <bug_s@plt>
xchg   %ax,%ax
mov    $0x2,%edi
call   10a0 <ed@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1090 <cup@plt>
lea    0xf36(%rip),%rdi
call   1080 <println@plt>
lea    0xf6f(%rip),%rdi
call   1080 <println@plt>
lea    0xfa7(%rip),%rdi
call   1080 <println@plt>
lea    0xfe2(%rip),%rdi
call   1080 <println@plt>
lea    0x101c(%rip),%rdi
call   1080 <println@plt>
lea    0x1051(%rip),%rdi
call   1080 <println@plt>
mov    %r14,%rdi
call   1080 <println@plt>
mov    %r15,%rdi
call   1080 <println@plt>
mov    %r12,%rdi
call   1080 <println@plt>
mov    %r13,%rdi
call   1080 <println@plt>
mov    %rbx,%rdi
call   1030 <menu@plt>
cmp    $0x9,%eax
ja     1210 <tst_bugs+0x40>
mov    %eax,%eax
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
xor    %eax,%eax
call   10c0 <bug_a@plt>
jmp    1210 <tst_bugs+0x40>
xor    %eax,%eax
call   1050 <bug_b@plt>
jmp    1210 <tst_bugs+0x40>
xor    %eax,%eax
call   10d0 <bug_c@plt>
jmp    1210 <tst_bugs+0x40>
xor    %eax,%eax
call   1060 <bug_d@plt>
jmp    1210 <tst_bugs+0x40>
xor    %eax,%eax
call   10e0 <bug_e@plt>
jmp    1210 <tst_bugs+0x40>
xor    %eax,%eax
call   1040 <bug_f@plt>
jmp    1210 <tst_bugs+0x40>
xor    %eax,%eax
call   10b0 <bug_w@plt>
jmp    1210 <tst_bugs+0x40>
xor    %eax,%eax
call   1070 <bug_l@plt>
jmp    1210 <tst_bugs+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@tst_bugs.menutable = internal global [11 x i8*] [i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.10, i32 0, i32 0)]
@.str = [18 x i8] c"Exit to main menu\00"
@.str.1 = [36 x i8] c"Bug A: Smooth scroll to jump scroll\00"
@.str.2 = [24 x i8] c"Bug B: Scrolling region\00"
@.str.3 = [29 x i8] c"Bug C: Wide to narrow screen\00"
@.str.4 = [29 x i8] c"Bug D: Narrow to wide screen\00"
@.str.5 = [52 x i8] c"Bug E: Cursor move from double- to single-wide line\00"
@.str.6 = [35 x i8] c"Bug F: Column mode escape sequence\00"
@.str.7 = [35 x i8] c"Wrap around with cursor addressing\00"
@.str.8 = [39 x i8] c"Erase right half of double width lines\00"
@.str.9 = [21 x i8] c"Funny scroll regions\00"
@.str.10 = [1 x i8] zeroinitializer
@tst_bugs.hmsg = internal global [9 x i8*] [i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.18, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.10, i32 0, i32 0)]
@.str.11 = [69 x i8] c"Test of known bugs in the DEC VT100 series. The numbering of some of\00"
@.str.12 = [68 x i8] c"the bugs (A-F) refers to the article 'VT100 MAGIC' by Sami Tabih in\00"
@.str.13 = [71 x i8] c"the 'Proceedings of the DEC Users Society' at St. Louis, Missouri, May\00"
@.str.14 = [70 x i8] c"1983. To understand some of the tests, you have to look at the source\00"
@.str.15 = [65 x i8] c"code or the article. Of course, a good VT100-compatible terminal\00"
@.str.16 = [70 x i8] c"should not have these bugs (or have some means of disabling them)! If\00"
@.str.17 = [70 x i8] c"a bug appears, you might want to RESET the terminal before continuing\00"
@.str.18 = [66 x i8] c"the test. There is a test of the RESET function in the main menu.\00"
@.str.19 = [34 x i8] c" Choose bug test number:\00"
define i32 @tst_bugs() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
br label %4
4: ; preds = %47, %0
%5 = call i32 @ed(i32 2)
%6 = call i32 @cup(i32 1, i32 1)
store i32 0, i32* %2
br label %7
7: ; preds = %20, %4
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [9 x i8*], [9 x i8*]* @tst_bugs.hmsg, i64 0, i64 %9
%11 = load i8*, i8** %10
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %7
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [9 x i8*], [9 x i8*]* @tst_bugs.hmsg, i64 0, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 @println(i8* %18)
br label %20
20: ; preds = %14
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %7
23: ; preds = %7
%24 = call i32 @println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.10, i64 0, i64 0))
%25 = call i32 @println(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.19, i64 0, i64 0))
%26 = call i32 @menu(i8** getelementptr inbounds ([11 x i8*], [11 x i8*]* @tst_bugs.menutable, i64 0, i64 0))
store i32 %26, i32* %3
%27 = load i32, i32* %3
switch i32 %27, label %46 [
i32 1, label %28
i32 2, label %30
i32 3, label %32
i32 4, label %34
i32 5, label %36
i32 6, label %38
i32 7, label %40
i32 8, label %42
i32 9, label %44
]
28: ; preds = %23
%29 = call i32 (...) @bug_a()
br label %46
30: ; preds = %23
%31 = call i32 (...) @bug_b()
br label %46
32: ; preds = %23
%33 = call i32 (...) @bug_c()
br label %46
34: ; preds = %23
%35 = call i32 (...) @bug_d()
br label %46
36: ; preds = %23
%37 = call i32 (...) @bug_e()
br label %46
38: ; preds = %23
%39 = call i32 (...) @bug_f()
br label %46
40: ; preds = %23
%41 = call i32 (...) @bug_w()
br label %46
42: ; preds = %23
%43 = call i32 (...) @bug_l()
br label %46
44: ; preds = %23
%45 = call i32 (...) @bug_s()
br label %46
46: ; preds = %23, %44, %42, %40, %38, %36, %34, %32, %30, %28
br label %47
47: ; preds = %46
%48 = load i32, i32* %3
%49 = icmp ne i32 %48, 0
br i1 %49, label %4, label %50
50: ; preds = %47
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@tst_bugs.menutable = internal global [11 x i8*] [i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.10, i32 0, i32 0)]
@.str = [18 x i8] c"Exit to main menu\00"
@.str.1 = [36 x i8] c"Bug A: Smooth scroll to jump scroll\00"
@.str.2 = [24 x i8] c"Bug B: Scrolling region\00"
@.str.3 = [29 x i8] c"Bug C: Wide to narrow screen\00"
@.str.4 = [29 x i8] c"Bug D: Narrow to wide screen\00"
@.str.5 = [52 x i8] c"Bug E: Cursor move from double- to single-wide line\00"
@.str.6 = [35 x i8] c"Bug F: Column mode escape sequence\00"
@.str.7 = [35 x i8] c"Wrap around with cursor addressing\00"
@.str.8 = [39 x i8] c"Erase right half of double width lines\00"
@.str.9 = [21 x i8] c"Funny scroll regions\00"
@.str.10 = [1 x i8] zeroinitializer
@.str.11 = [69 x i8] c"Test of known bugs in the DEC VT100 series. The numbering of some of\00"
@.str.12 = [68 x i8] c"the bugs (A-F) refers to the article 'VT100 MAGIC' by Sami Tabih in\00"
@.str.13 = [71 x i8] c"the 'Proceedings of the DEC Users Society' at St. Louis, Missouri, May\00"
@.str.14 = [70 x i8] c"1983. To understand some of the tests, you have to look at the source\00"
@.str.15 = [65 x i8] c"code or the article. Of course, a good VT100-compatible terminal\00"
@.str.16 = [70 x i8] c"should not have these bugs (or have some means of disabling them)! If\00"
@.str.17 = [70 x i8] c"a bug appears, you might want to RESET the terminal before continuing\00"
@.str.18 = [66 x i8] c"the test. There is a test of the RESET function in the main menu.\00"
@.str.19 = [34 x i8] c" Choose bug test number:\00"
define i32 @tst_bugs() {
br label %1
1: ; preds = %33, %0
%2 = tail call i32 @ed(i32 2)
%3 = tail call i32 @cup(i32 1, i32 1)
%4 = tail call i32 @println(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.11, i64 0, i64 0))
%5 = tail call i32 @println(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.12, i64 0, i64 0))
%6 = tail call i32 @println(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.13, i64 0, i64 0))
%7 = tail call i32 @println(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.14, i64 0, i64 0))
%8 = tail call i32 @println(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.15, i64 0, i64 0))
%9 = tail call i32 @println(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.16, i64 0, i64 0))
%10 = tail call i32 @println(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.17, i64 0, i64 0))
%11 = tail call i32 @println(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.18, i64 0, i64 0))
%12 = tail call i32 @println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.10, i64 0, i64 0))
%13 = tail call i32 @println(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.19, i64 0, i64 0))
%14 = tail call i32 @menu(i8** getelementptr inbounds ([11 x i8*], [11 x i8*]* @tst_bugs.menutable, i64 0, i64 0))
switch i32 %14, label %33 [
i32 1, label %15
i32 2, label %17
i32 3, label %19
i32 4, label %21
i32 5, label %23
i32 6, label %25
i32 7, label %27
i32 8, label %29
i32 9, label %31
i32 0, label %34
]
15: ; preds = %1
%16 = tail call i32 (...) @bug_a()
br label %33
17: ; preds = %1
%18 = tail call i32 (...) @bug_b()
br label %33
19: ; preds = %1
%20 = tail call i32 (...) @bug_c()
br label %33
21: ; preds = %1
%22 = tail call i32 (...) @bug_d()
br label %33
23: ; preds = %1
%24 = tail call i32 (...) @bug_e()
br label %33
25: ; preds = %1
%26 = tail call i32 (...) @bug_f()
br label %33
27: ; preds = %1
%28 = tail call i32 (...) @bug_w()
br label %33
29: ; preds = %1
%30 = tail call i32 (...) @bug_l()
br label %33
31: ; preds = %1
%32 = tail call i32 (...) @bug_s()
br label %33
33: ; preds = %31, %29, %27, %25, %23, %21, %19, %17, %15, %1
br label %1
34: ; preds = %1
ret i32 undef
}