#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*/ esc(char *);
int /*<<< orphan*/ holdit();
int /*<<< orphan*/ nel();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ println(char *);
int /*<<< orphan*/ rm(char *);
int /*<<< orphan*/ sm(char *);
bug_a() {
  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");
  rm("?4");
  for (i = 1; i <= 20; i++)
    printf("\n");
  sm("?4");
  for (i = 1; i <= 10; i++)
    printf("\n");
  rm("?4");
  for (i = 1; i <= 5; i++)
    printf("\n");
  sm("?4");
  nel();
  rm("?4");
  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.");
  holdit();
}


x86 assembly (clang, -O0):
<bug_a>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xa,%edi
mov    $0x1,%esi
call   1060 <cup@plt>
lea    0xe62(%rip),%rdi
call   1050 <println@plt>
lea    0xe93(%rip),%rdi
call   1050 <println@plt>
lea    0xec1(%rip),%rdi
call   1050 <println@plt>
mov    $0x0,%al
call   10a0 <holdit@plt>
lea    0xed8(%rip),%rdi
call   1090 <esc@plt>
lea    0xed1(%rip),%rdi
call   1030 <rm@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jg     1207 <bug_a+0x87>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e1 <bug_a+0x61>
lea    0xe98(%rip),%rdi
call   1080 <sm@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jg     1240 <bug_a+0xc0>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    121a <bug_a+0x9a>
lea    0xe5f(%rip),%rdi
call   1030 <rm@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jg     1279 <bug_a+0xf9>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1253 <bug_a+0xd3>
lea    0xe26(%rip),%rdi
call   1080 <sm@plt>
mov    $0x0,%al
call   1070 <nel@plt>
lea    0xe13(%rip),%rdi
call   1030 <rm@plt>
mov    $0x0,%al
call   1070 <nel@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jg     12d6 <bug_a+0x156>
mov    -0x8(%rbp),%esi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   10a0 <holdit@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12a6 <bug_a+0x126>
lea    0xdee(%rip),%rdi
call   1050 <println@plt>
mov    $0x0,%al
call   10a0 <holdit@plt>
mov    -0x4(%rbp),%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    0xe59(%rip),%rdi
call   1060 <println@plt>
lea    0xe8a(%rip),%rdi
call   1060 <println@plt>
lea    0xeb8(%rip),%rdi
call   1060 <println@plt>
xor    %eax,%eax
call   10b0 <holdit@plt>
lea    0xecf(%rip),%rdi
call   10a0 <esc@plt>
lea    0xec8(%rip),%rbx
mov    %rbx,%rdi
call   1040 <rm@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    %rbx,%rdi
call   1090 <sm@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    %rbx,%rdi
call   1040 <rm@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    %rbx,%rdi
call   1090 <sm@plt>
xor    %eax,%eax
call   1080 <nel@plt>
mov    %rbx,%rdi
call   1040 <rm@plt>
xor    %eax,%eax
call   1080 <nel@plt>
lea    0xd30(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10b0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10b0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10b0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10b0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10b0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10b0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10b0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10b0 <holdit@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10b0 <holdit@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10b0 <holdit@plt>
lea    0xc6d(%rip),%rdi
call   1060 <println@plt>
xor    %eax,%eax
pop    %rbx
jmp    10b0 <holdit@plt>

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 = [3 x i8] c"?4\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [32 x i8] c"Softscroll bug test, line %d. \00"
@.str.7 = [58 x i8] c"That should have been enough to show the bug, if present.\00"
define i32 @bug_a() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @cup(i32 10, i32 1)
%4 = call i32 @println(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @println(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @println(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 (...) @holdit()
%8 = call i32 @esc(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @rm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %10
10: ; preds = %15, %0
%11 = load i32, i32* %2
%12 = icmp sle i32 %11, 20
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %15
15: ; preds = %13
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %10
18: ; preds = %10
%19 = call i32 @sm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %20
20: ; preds = %25, %18
%21 = load i32, i32* %2
%22 = icmp sle i32 %21, 10
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %25
25: ; preds = %23
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %20
28: ; preds = %20
%29 = call i32 @rm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %30
30: ; preds = %35, %28
%31 = load i32, i32* %2
%32 = icmp sle i32 %31, 5
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %35
35: ; preds = %33
%36 = load i32, i32* %2
%37 = add nsw i32 %36, 1
store i32 %37, i32* %2
br label %30
38: ; preds = %30
%39 = call i32 @sm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 (...) @nel()
%41 = call i32 @rm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 (...) @nel()
store i32 1, i32* %2
br label %43
43: ; preds = %50, %38
%44 = load i32, i32* %2
%45 = icmp sle i32 %44, 10
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = load i32, i32* %2
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %47)
%49 = call i32 (...) @holdit()
br label %50
50: ; preds = %46
%51 = load i32, i32* %2
%52 = add nsw i32 %51, 1
store i32 %52, i32* %2
br label %43
53: ; preds = %43
%54 = call i32 @println(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.7, i64 0, i64 0))
%55 = call i32 (...) @holdit()
%56 = load i32, i32* %1
ret i32 %56
}

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.4 = [3 x i8] c"?4\00"
@.str.6 = [32 x i8] c"Softscroll bug test, line %d. \00"
@.str.7 = [58 x i8] c"That should have been enough to show the bug, if present.\00"
define i32 @bug_a() {
%1 = tail call i32 @cup(i32 10, i32 1)
%2 = tail call i32 @println(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @println(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @println(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 (...) @holdit()
%6 = tail call i32 @esc(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 @rm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i32 @putchar(i32 10)
%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 @sm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%29 = tail call i32 @putchar(i32 10)
%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 @rm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%40 = tail call i32 @putchar(i32 10)
%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 @sm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%46 = tail call i32 (...) @nel()
%47 = tail call i32 @rm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%48 = tail call i32 (...) @nel()
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 1)
%50 = tail call i32 (...) @holdit()
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 2)
%52 = tail call i32 (...) @holdit()
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 3)
%54 = tail call i32 (...) @holdit()
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 4)
%56 = tail call i32 (...) @holdit()
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 5)
%58 = tail call i32 (...) @holdit()
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 6)
%60 = tail call i32 (...) @holdit()
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 7)
%62 = tail call i32 (...) @holdit()
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 8)
%64 = tail call i32 (...) @holdit()
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 9)
%66 = tail call i32 (...) @holdit()
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 10)
%68 = tail call i32 (...) @holdit()
%69 = tail call i32 @println(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.7, i64 0, i64 0))
%70 = tail call i32 (...) @holdit()
ret i32 undef
}