#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);
bug_s() {
  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);
}


x86 assembly (clang, -O0):
<bug_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x14,%edi
mov    $0xa,%esi
call   1060 <decstbm@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1040 <cup@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jg     11a1 <bug_s+0x51>
mov    -0x8(%rbp),%esi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117a <bug_s+0x2a>
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,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jg     11f8 <bug_s+0xa8>
mov    -0x8(%rbp),%esi
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d1 <bug_s+0x81>
mov    $0x0,%al
call   1070 <holdit@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1060 <decstbm@plt>
mov    -0x4(%rbp),%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
pop    %rbx
jmp    1060 <decstbm@plt>

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() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @decstbm(i32 20, i32 10)
%4 = call i32 @cup(i32 1, i32 1)
store i32 1, i32* %2
br label %5
5: ; preds = %11, %0
%6 = load i32, i32* %2
%7 = icmp sle i32 %6, 20
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %8
%12 = load i32, i32* %2
%13 = add nsw i32 %12, 1
store i32 %13, i32* %2
br label %5
14: ; preds = %5
%15 = call i32 (...) @holdit()
%16 = call i32 @ed(i32 2)
%17 = call i32 @decstbm(i32 0, i32 1)
%18 = call i32 @cup(i32 1, i32 1)
store i32 1, i32* %2
br label %19
19: ; preds = %25, %14
%20 = load i32, i32* %2
%21 = icmp sle i32 %20, 20
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i32, i32* %2
%24 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %19
28: ; preds = %19
%29 = call i32 (...) @holdit()
%30 = call i32 @decstbm(i32 0, i32 0)
%31 = load i32, i32* %1
ret i32 %31
}

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() {
%1 = tail call i32 @decstbm(i32 20, i32 10)
%2 = tail call i32 @cup(i32 1, i32 1)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 2)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 3)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 4)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 5)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 6)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 7)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 8)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 9)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 10)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 11)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 12)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 13)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 14)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 15)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 16)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 17)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 18)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 19)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 20)
%23 = tail call i32 (...) @holdit()
%24 = tail call i32 @ed(i32 2)
%25 = tail call i32 @decstbm(i32 0, i32 1)
%26 = tail call i32 @cup(i32 1, i32 1)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 1)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 2)
%29 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 3)
%30 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 4)
%31 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 5)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 6)
%33 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 7)
%34 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 8)
%35 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 9)
%36 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 10)
%37 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 11)
%38 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 12)
%39 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 13)
%40 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 14)
%41 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 15)
%42 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 16)
%43 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 17)
%44 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 18)
%45 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 19)
%46 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 20)
%47 = tail call i32 (...) @holdit()
%48 = tail call i32 @decstbm(i32 0, i32 0)
ret i32 undef
}