#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*/ decstbm(int, int);
int /*<<< orphan*/ ed(int);
int /*<<< orphan*/ holdit();
int /*<<< orphan*/ printf(char *, int);
int bug_s(const char *the_title) {
  int i;
  decstbm(20, 10);
  cup(1, 1);
  for (i = 1; i <= 20; i++)
    printf("This is 20 lines of text (line %d), no scroll region.\n", i);
  holdit();
  ed(2);
  decstbm(0, 1);
  cup(1, 1);
  for (i = 1; i <= 20; i++)
    printf("This is 20 lines of text (line %d), no scroll region.\n", i);
  holdit();
  decstbm(0, 0);
  return 0;
}


x86 assembly (clang, -O0):
<bug_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x14,%edi
mov    $0xa,%esi
call   1060 <decstbm@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1040 <cup@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jg     11a5 <bug_s+0x55>
mov    -0xc(%rbp),%esi
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117e <bug_s+0x2e>
mov    $0x0,%al
call   1070 <holdit@plt>
mov    $0x2,%edi
call   1050 <ed@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <decstbm@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1040 <cup@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jg     11fc <bug_s+0xac>
mov    -0xc(%rbp),%esi
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d5 <bug_s+0x85>
mov    $0x0,%al
call   1070 <holdit@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1060 <decstbm@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bug_s>:
push   %rbx
mov    $0x14,%edi
mov    $0xa,%esi
call   1060 <decstbm@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1040 <cup@plt>
lea    0xe8a(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xb,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xd,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xe,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xf,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x11,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x12,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x13,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <holdit@plt>
mov    $0x2,%edi
call   1050 <ed@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <decstbm@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1040 <cup@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xb,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xd,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xe,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xf,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x11,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x12,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x13,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <holdit@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1060 <decstbm@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [55 x i8] c"This is 20 lines of text (line %d), no scroll region.\0A\00"
define i32 @bug_s(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = call i32 @decstbm(i32 20, i32 10)
%5 = call i32 @cup(i32 1, i32 1)
store i32 1, i32* %3
br label %6
6: ; preds = %12, %1
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 20
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = load i32, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %9
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %6
15: ; preds = %6
%16 = call i32 (...) @holdit()
%17 = call i32 @ed(i32 2)
%18 = call i32 @decstbm(i32 0, i32 1)
%19 = call i32 @cup(i32 1, i32 1)
store i32 1, i32* %3
br label %20
20: ; preds = %26, %15
%21 = load i32, i32* %3
%22 = icmp sle i32 %21, 20
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* %3
%25 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %23
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %20
29: ; preds = %20
%30 = call i32 (...) @holdit()
%31 = call i32 @decstbm(i32 0, i32 0)
ret i32 0
}

LLVM IR (-O2):
@.str = [55 x i8] c"This is 20 lines of text (line %d), no scroll region.\0A\00"
define i32 @bug_s(i8* nocapture readnone %0) {
%2 = tail call i32 @decstbm(i32 20, i32 10)
%3 = tail call i32 @cup(i32 1, i32 1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 1)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 2)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 3)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 5)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 6)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 7)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 8)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 9)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 10)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 11)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 12)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 13)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 14)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 15)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 16)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 17)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 18)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 19)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 20)
%24 = tail call i32 (...) @holdit()
%25 = tail call i32 @ed(i32 2)
%26 = tail call i32 @decstbm(i32 0, i32 1)
%27 = tail call i32 @cup(i32 1, i32 1)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 1)
%29 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 2)
%30 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 3)
%31 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 4)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 5)
%33 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 6)
%34 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 7)
%35 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 8)
%36 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 9)
%37 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 10)
%38 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 11)
%39 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 12)
%40 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 13)
%41 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 14)
%42 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 15)
%43 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 16)
%44 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 17)
%45 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 18)
%46 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 19)
%47 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 20)
%48 = tail call i32 (...) @holdit()
%49 = tail call i32 @decstbm(i32 0, i32 0)
ret i32 0
}