#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*/ decdwl();
int /*<<< orphan*/ holdit();
char inchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ println(char *);
int /*<<< orphan*/ readnl();
int /*<<< orphan*/ rm(char *);
int /*<<< orphan*/ sgr(char *);
int /*<<< orphan*/ sm(char *);
bug_d() {
  int i;
  char result;
  do {
    cup(14, 1);
    sm("?3");
    cup(1, 9);
    decdwl();
    println("You should see blinking text at the bottom line.");
    cup(3, 9);
    decdwl();
    println("Enter 0 to exit, 1 to try to invoke the bug again.");
    cup(24, 9);
    decdwl();
    sgr("1;5;7");
    printf("If you can see this then the bug did not appear.");
    sgr("");
    cup(4, 9);
    decdwl();
    result = inchar();
    readnl();
    rm("?3");
  } while (result == '1');
  sm("?4");
  cup(23, 1);
  for (i = 1; i <= 5; i++)
    println("If the bug is present, this should make things much worse!");
  holdit();
  rm("?4");
}


x86 assembly (clang, -O0):
<bug_d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xe,%edi
mov    $0x1,%esi
call   1070 <cup@plt>
lea    0xe42(%rip),%rdi
call   1090 <sm@plt>
mov    $0x1,%edi
mov    $0x9,%esi
call   1070 <cup@plt>
mov    $0x0,%al
call   1050 <decdwl@plt>
lea    0xe23(%rip),%rdi
call   1060 <println@plt>
mov    $0x3,%edi
mov    $0x9,%esi
call   1070 <cup@plt>
mov    $0x0,%al
call   1050 <decdwl@plt>
lea    0xe32(%rip),%rdi
call   1060 <println@plt>
mov    $0x18,%edi
mov    $0x9,%esi
call   1070 <cup@plt>
mov    $0x0,%al
call   1050 <decdwl@plt>
lea    0xe43(%rip),%rdi
call   10a0 <sgr@plt>
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9f(%rip),%rdi
call   10a0 <sgr@plt>
mov    $0x4,%edi
mov    $0x9,%esi
call   1070 <cup@plt>
mov    $0x0,%al
call   1050 <decdwl@plt>
mov    $0x0,%al
call   1080 <inchar@plt>
mov    %al,-0x9(%rbp)
mov    $0x0,%al
call   10c0 <readnl@plt>
lea    0xd91(%rip),%rdi
call   1030 <rm@plt>
movsbl -0x9(%rbp),%eax
cmp    $0x31,%eax
je     11a8 <bug_d+0x8>
lea    0xe16(%rip),%rdi
call   1090 <sm@plt>
mov    $0x17,%edi
mov    $0x1,%esi
call   1070 <cup@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jg     12c7 <bug_d+0x127>
lea    0xded(%rip),%rdi
call   1060 <println@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12a3 <bug_d+0x103>
mov    $0x0,%al
call   10b0 <holdit@plt>
lea    0xdc9(%rip),%rdi
call   1030 <rm@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bug_d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe4e(%rip),%rbx
lea    0xe7b(%rip),%r15
lea    0xea7(%rip),%r12
lea    0xea6(%rip),%r13
lea    0xf0d(%rip),%rbp
xchg   %ax,%ax
mov    $0xe,%edi
mov    $0x1,%esi
call   1070 <cup@plt>
mov    %rbx,%rdi
call   1090 <sm@plt>
mov    $0x1,%edi
mov    $0x9,%esi
call   1070 <cup@plt>
xor    %eax,%eax
call   1050 <decdwl@plt>
lea    0xdff(%rip),%rdi
call   1060 <println@plt>
mov    $0x3,%edi
mov    $0x9,%esi
call   1070 <cup@plt>
xor    %eax,%eax
call   1050 <decdwl@plt>
mov    %r15,%rdi
call   1060 <println@plt>
mov    $0x18,%edi
mov    $0x9,%esi
call   1070 <cup@plt>
xor    %eax,%eax
call   1050 <decdwl@plt>
mov    %r12,%rdi
call   10a0 <sgr@plt>
mov    %r13,%rdi
call   1040 <printf@plt>
mov    %rbp,%rdi
call   10a0 <sgr@plt>
mov    $0x4,%edi
mov    $0x9,%esi
call   1070 <cup@plt>
xor    %eax,%eax
call   1050 <decdwl@plt>
xor    %eax,%eax
call   1080 <inchar@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   10c0 <readnl@plt>
mov    %rbx,%rdi
call   1030 <rm@plt>
cmp    $0x31,%r14b
je     11d0 <bug_d+0x30>
lea    0xe09(%rip),%rbx
mov    %rbx,%rdi
call   1090 <sm@plt>
mov    $0x17,%edi
mov    $0x1,%esi
call   1070 <cup@plt>
lea    0xdee(%rip),%rbp
mov    %rbp,%rdi
call   1060 <println@plt>
mov    %rbp,%rdi
call   1060 <println@plt>
mov    %rbp,%rdi
call   1060 <println@plt>
mov    %rbp,%rdi
call   1060 <println@plt>
mov    %rbp,%rdi
call   1060 <println@plt>
xor    %eax,%eax
call   10b0 <holdit@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <rm@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"?3\00"
@.str.1 = [49 x i8] c"You should see blinking text at the bottom line.\00"
@.str.2 = [51 x i8] c"Enter 0 to exit, 1 to try to invoke the bug again.\00"
@.str.3 = [6 x i8] c"1;5;7\00"
@.str.4 = [49 x i8] c"If you can see this then the bug did not appear.\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [3 x i8] c"?4\00"
@.str.7 = [59 x i8] c"If the bug is present, this should make things much worse!\00"
define i32 @bug_d() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
br label %4
4: ; preds = %23, %0
%5 = call i32 @cup(i32 14, i32 1)
%6 = call i32 @sm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @cup(i32 1, i32 9)
%8 = call i32 (...) @decdwl()
%9 = call i32 @println(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @cup(i32 3, i32 9)
%11 = call i32 (...) @decdwl()
%12 = call i32 @println(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @cup(i32 24, i32 9)
%14 = call i32 (...) @decdwl()
%15 = call i32 @sgr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @sgr(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 @cup(i32 4, i32 9)
%19 = call i32 (...) @decdwl()
%20 = call signext i8 (...) @inchar()
store i8 %20, i8* %3
%21 = call i32 (...) @readnl()
%22 = call i32 @rm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %4
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 49
br i1 %26, label %4, label %27
27: ; preds = %23
%28 = call i32 @sm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%29 = call i32 @cup(i32 23, i32 1)
store i32 1, i32* %2
br label %30
30: ; preds = %35, %27
%31 = load i32, i32* %2
%32 = icmp sle i32 %31, 5
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = call i32 @println(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.7, 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 (...) @holdit()
%40 = call i32 @rm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"?3\00"
@.str.1 = [49 x i8] c"You should see blinking text at the bottom line.\00"
@.str.2 = [51 x i8] c"Enter 0 to exit, 1 to try to invoke the bug again.\00"
@.str.3 = [6 x i8] c"1;5;7\00"
@.str.4 = [49 x i8] c"If you can see this then the bug did not appear.\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [3 x i8] c"?4\00"
@.str.7 = [59 x i8] c"If the bug is present, this should make things much worse!\00"
define i32 @bug_d() {
br label %1
1: ; preds = %1, %0
%2 = tail call i32 @cup(i32 14, i32 1)
%3 = tail call i32 @sm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @cup(i32 1, i32 9)
%5 = tail call i32 (...) @decdwl()
%6 = tail call i32 @println(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @cup(i32 3, i32 9)
%8 = tail call i32 (...) @decdwl()
%9 = tail call i32 @println(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @cup(i32 24, i32 9)
%11 = tail call i32 (...) @decdwl()
%12 = tail call i32 @sgr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
%14 = tail call i32 @sgr(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%15 = tail call i32 @cup(i32 4, i32 9)
%16 = tail call i32 (...) @decdwl()
%17 = tail call signext i8 (...) @inchar()
%18 = tail call i32 (...) @readnl()
%19 = tail call i32 @rm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i8 %17, 49
br i1 %20, label %1, label %21
21: ; preds = %1
%22 = tail call i32 @sm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%23 = tail call i32 @cup(i32 23, i32 1)
%24 = tail call i32 @println(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.7, i64 0, i64 0))
%25 = tail call i32 @println(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.7, i64 0, i64 0))
%26 = tail call i32 @println(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.7, i64 0, i64 0))
%27 = tail call i32 @println(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.7, i64 0, i64 0))
%28 = tail call i32 @println(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.7, i64 0, i64 0))
%29 = tail call i32 (...) @holdit()
%30 = tail call i32 @rm(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
ret i32 undef
}