#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*/ cup(int, int);
int /*<<< orphan*/ decsclm(int);
int /*<<< orphan*/ esc(char *);
int /*<<< orphan*/ holdit();
int /*<<< orphan*/ nel();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ println(char *);
int bug_a(const char *the_title) {
  int i;
  cup(10, 1);
  println("This is a test of the VT100 'Scroll while toggle softscroll'");
  println("bug.  The cursor may disappear, or move UP the screen, or");
  println("multiple copies of some lines may appear.");
  holdit();
  esc("[24H");
  decsclm((0));
  for (i = 1; i <= 20; i++)
    printf("\n");
  decsclm((1));
  for (i = 1; i <= 10; i++)
    printf("\n");
  decsclm((0));
  for (i = 1; i <= 5; i++)
    printf("\n");
  decsclm((1));
  nel();
  decsclm((0));
  nel();
  for (i = 1; i <= 10; i++) {
    printf("Softscroll bug test, line %d.  ", i);
    holdit();
  }
  println("That should have been enough to show the bug, if present.");
  return 1;
}


x86 assembly (clang, -O0):
<bug_a>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0xa,%edi
mov    $0x1,%esi
call   1060 <cup@plt>
lea    0xe6e(%rip),%rdi
call   1050 <println@plt>
lea    0xe9f(%rip),%rdi
call   1050 <println@plt>
lea    0xecd(%rip),%rdi
call   1050 <println@plt>
mov    $0x0,%al
call   1090 <holdit@plt>
lea    0xee4(%rip),%rdi
call   1080 <esc@plt>
xor    %edi,%edi
call   1030 <decsclm@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jg     11f6 <bug_a+0x86>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d0 <bug_a+0x60>
mov    $0x1,%edi
call   1030 <decsclm@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jg     122d <bug_a+0xbd>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1207 <bug_a+0x97>
xor    %edi,%edi
call   1030 <decsclm@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jg     1261 <bug_a+0xf1>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <bug_a+0xcb>
mov    $0x1,%edi
call   1030 <decsclm@plt>
mov    $0x0,%al
call   1070 <nel@plt>
xor    %edi,%edi
call   1030 <decsclm@plt>
mov    $0x0,%al
call   1070 <nel@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jg     12b7 <bug_a+0x147>
mov    -0xc(%rbp),%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <holdit@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1287 <bug_a+0x117>
lea    0xe0a(%rip),%rdi
call   1050 <println@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bug_a>:
push   %rbx
mov    $0xa,%edi
mov    $0x1,%esi
call   1070 <cup@plt>
lea    0xe69(%rip),%rdi
call   1060 <println@plt>
lea    0xe9a(%rip),%rdi
call   1060 <println@plt>
lea    0xec8(%rip),%rdi
call   1060 <println@plt>
xor    %eax,%eax
call   10a0 <holdit@plt>
lea    0xedf(%rip),%rdi
call   1090 <esc@plt>
xor    %edi,%edi
call   1040 <decsclm@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   1040 <decsclm@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1040 <decsclm@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   1040 <decsclm@plt>
xor    %eax,%eax
call   1080 <nel@plt>
xor    %edi,%edi
call   1040 <decsclm@plt>
xor    %eax,%eax
call   1080 <nel@plt>
lea    0xd43(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <holdit@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <holdit@plt>
lea    0xc80(%rip),%rdi
call   1060 <println@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [61 x i8] c"This is a test of the VT100 'Scroll while toggle softscroll'\00"
@.str.1 = [58 x i8] c"bug. The cursor may disappear, or move UP the screen, or\00"
@.str.2 = [42 x i8] c"multiple copies of some lines may appear.\00"
@.str.3 = [5 x i8] c"[24H\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [32 x i8] c"Softscroll bug test, line %d. \00"
@.str.6 = [58 x i8] c"That should have been enough to show the bug, if present.\00"
define i32 @bug_a(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = call i32 @cup(i32 10, i32 1)
%5 = call i32 @println(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @println(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @println(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (...) @holdit()
%9 = call i32 @esc(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @decsclm(i32 0)
store i32 1, i32* %3
br label %11
11: ; preds = %16, %1
%12 = load i32, i32* %3
%13 = icmp sle i32 %12, 20
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %16
16: ; preds = %14
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %11
19: ; preds = %11
%20 = call i32 @decsclm(i32 1)
store i32 1, i32* %3
br label %21
21: ; preds = %26, %19
%22 = load i32, i32* %3
%23 = icmp sle i32 %22, 10
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %24
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %21
29: ; preds = %21
%30 = call i32 @decsclm(i32 0)
store i32 1, i32* %3
br label %31
31: ; preds = %36, %29
%32 = load i32, i32* %3
%33 = icmp sle i32 %32, 5
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %31
39: ; preds = %31
%40 = call i32 @decsclm(i32 1)
%41 = call i32 (...) @nel()
%42 = call i32 @decsclm(i32 0)
%43 = call i32 (...) @nel()
store i32 1, i32* %3
br label %44
44: ; preds = %51, %39
%45 = load i32, i32* %3
%46 = icmp sle i32 %45, 10
br i1 %46, label %47, label %54
47: ; preds = %44
%48 = load i32, i32* %3
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %48)
%50 = call i32 (...) @holdit()
br label %51
51: ; preds = %47
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 1
store i32 %53, i32* %3
br label %44
54: ; preds = %44
%55 = call i32 @println(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.6, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [61 x i8] c"This is a test of the VT100 'Scroll while toggle softscroll'\00"
@.str.1 = [58 x i8] c"bug. The cursor may disappear, or move UP the screen, or\00"
@.str.2 = [42 x i8] c"multiple copies of some lines may appear.\00"
@.str.3 = [5 x i8] c"[24H\00"
@.str.5 = [32 x i8] c"Softscroll bug test, line %d. \00"
@.str.6 = [58 x i8] c"That should have been enough to show the bug, if present.\00"
define i32 @bug_a(i8* nocapture readnone %0) {
%2 = tail call i32 @cup(i32 10, i32 1)
%3 = tail call i32 @println(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @println(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @println(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 (...) @holdit()
%7 = tail call i32 @esc(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @decsclm(i32 0)
%9 = tail call i32 @putchar(i32 10)
%10 = tail call i32 @putchar(i32 10)
%11 = tail call i32 @putchar(i32 10)
%12 = tail call i32 @putchar(i32 10)
%13 = tail call i32 @putchar(i32 10)
%14 = tail call i32 @putchar(i32 10)
%15 = tail call i32 @putchar(i32 10)
%16 = tail call i32 @putchar(i32 10)
%17 = tail call i32 @putchar(i32 10)
%18 = tail call i32 @putchar(i32 10)
%19 = tail call i32 @putchar(i32 10)
%20 = tail call i32 @putchar(i32 10)
%21 = tail call i32 @putchar(i32 10)
%22 = tail call i32 @putchar(i32 10)
%23 = tail call i32 @putchar(i32 10)
%24 = tail call i32 @putchar(i32 10)
%25 = tail call i32 @putchar(i32 10)
%26 = tail call i32 @putchar(i32 10)
%27 = tail call i32 @putchar(i32 10)
%28 = tail call i32 @putchar(i32 10)
%29 = tail call i32 @decsclm(i32 1)
%30 = tail call i32 @putchar(i32 10)
%31 = tail call i32 @putchar(i32 10)
%32 = tail call i32 @putchar(i32 10)
%33 = tail call i32 @putchar(i32 10)
%34 = tail call i32 @putchar(i32 10)
%35 = tail call i32 @putchar(i32 10)
%36 = tail call i32 @putchar(i32 10)
%37 = tail call i32 @putchar(i32 10)
%38 = tail call i32 @putchar(i32 10)
%39 = tail call i32 @putchar(i32 10)
%40 = tail call i32 @decsclm(i32 0)
%41 = tail call i32 @putchar(i32 10)
%42 = tail call i32 @putchar(i32 10)
%43 = tail call i32 @putchar(i32 10)
%44 = tail call i32 @putchar(i32 10)
%45 = tail call i32 @putchar(i32 10)
%46 = tail call i32 @decsclm(i32 1)
%47 = tail call i32 (...) @nel()
%48 = tail call i32 @decsclm(i32 0)
%49 = tail call i32 (...) @nel()
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 1)
%51 = tail call i32 (...) @holdit()
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 2)
%53 = tail call i32 (...) @holdit()
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 3)
%55 = tail call i32 (...) @holdit()
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 4)
%57 = tail call i32 (...) @holdit()
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 5)
%59 = tail call i32 (...) @holdit()
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 6)
%61 = tail call i32 (...) @holdit()
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 7)
%63 = tail call i32 (...) @holdit()
%64 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 8)
%65 = tail call i32 (...) @holdit()
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 9)
%67 = tail call i32 (...) @holdit()
%68 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 10)
%69 = tail call i32 (...) @holdit()
%70 = tail call i32 @println(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.6, i64 0, i64 0))
ret i32 1
}