#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*/ holdit();
int /*<<< orphan*/ hvp(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ println(char *);
bug_w() {
  int row, col;
  cup(16, 1);
  println("   This illustrates the \"wrap around bug\" which exists on a");
  println("   standard VT100. At the top of the screen there should be");
  println("   a row of +'s, and the rightmost column should be filled");
  println("   with *'s. But if the bug is present, some of the *'s may");
  println("   be placed in other places, e.g. in the leftmost column,");
  println("   and the top line of +'s may be scrolled away.");
  cup(1, 1);
  for (col = 1; col <= 79; col++)
    printf("+");
  for (row = 1; row <= 24; row++) {
    hvp(row, 80);
    printf("*");
  }
  cup(24, 1);
  holdit();
}


x86 assembly (clang, -O0):
<bug_w>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x10,%edi
mov    $0x1,%esi
call   1050 <cup@plt>
lea    0xe92(%rip),%rdi
call   1040 <println@plt>
lea    0xec2(%rip),%rdi
call   1040 <println@plt>
lea    0xef2(%rip),%rdi
call   1040 <println@plt>
lea    0xf21(%rip),%rdi
call   1040 <println@plt>
lea    0xf51(%rip),%rdi
call   1040 <println@plt>
lea    0xf80(%rip),%rdi
call   1040 <println@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1050 <cup@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x4f,-0xc(%rbp)
jg     11e6 <bug_w+0x96>
lea    0xf88(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c2 <bug_w+0x72>
movl   $0x1,-0x8(%rbp)
cmpl   $0x18,-0x8(%rbp)
jg     121e <bug_w+0xce>
mov    -0x8(%rbp),%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
lea    0xf52(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ed <bug_w+0x9d>
mov    $0x18,%edi
mov    $0x1,%esi
call   1050 <cup@plt>
mov    $0x0,%al
call   1070 <holdit@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bug_w>:
push   %rbx
mov    $0x10,%edi
mov    $0x1,%esi
call   1050 <cup@plt>
lea    0xe99(%rip),%rdi
call   1040 <println@plt>
lea    0xec9(%rip),%rdi
call   1040 <println@plt>
lea    0xef9(%rip),%rdi
call   1040 <println@plt>
lea    0xf28(%rip),%rdi
call   1040 <println@plt>
lea    0xf58(%rip),%rdi
call   1040 <println@plt>
lea    0xf87(%rip),%rdi
call   1040 <println@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1050 <cup@plt>
mov    $0x4f,%ebx
nopl   0x0(%rax)
mov    $0x2b,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    11c0 <bug_w+0x70>
mov    $0x1,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x2,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x3,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x4,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x5,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x6,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x7,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x9,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0xb,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0xc,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0xd,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0xe,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0xf,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x10,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x11,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x12,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x13,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x14,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x15,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x16,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x17,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x18,%edi
mov    $0x50,%esi
call   1060 <hvp@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    $0x18,%edi
mov    $0x1,%esi
call   1050 <cup@plt>
xor    %eax,%eax
pop    %rbx
jmp    1070 <holdit@plt>

LLVM IR (-O0):
@.str = [60 x i8] c" This illustrates the \22wrap around bug\22 which exists on a\00"
@.str.1 = [60 x i8] c" standard VT100. At the top of the screen there should be\00"
@.str.2 = [59 x i8] c" a row of +'s, and the rightmost column should be filled\00"
@.str.3 = [60 x i8] c" with *'s. But if the bug is present, some of the *'s may\00"
@.str.4 = [59 x i8] c" be placed in other places, e.g. in the leftmost column,\00"
@.str.5 = [49 x i8] c" and the top line of +'s may be scrolled away.\00"
@.str.6 = [2 x i8] c"+\00"
@.str.7 = [2 x i8] c"*\00"
define i32 @bug_w() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @cup(i32 16, i32 1)
%5 = call i32 @println(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @println(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @println(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @println(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @println(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 @println(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 @cup(i32 1, i32 1)
store i32 1, i32* %3
br label %12
12: ; preds = %17, %0
%13 = load i32, i32* %3
%14 = icmp sle i32 %13, 79
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %17
17: ; preds = %15
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %12
20: ; preds = %12
store i32 1, i32* %2
br label %21
21: ; preds = %28, %20
%22 = load i32, i32* %2
%23 = icmp sle i32 %22, 24
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32, i32* %2
%26 = call i32 @hvp(i32 %25, i32 80)
%27 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %28
28: ; preds = %24
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
store i32 %30, i32* %2
br label %21
31: ; preds = %21
%32 = call i32 @cup(i32 24, i32 1)
%33 = call i32 (...) @holdit()
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [60 x i8] c" This illustrates the \22wrap around bug\22 which exists on a\00"
@.str.1 = [60 x i8] c" standard VT100. At the top of the screen there should be\00"
@.str.2 = [59 x i8] c" a row of +'s, and the rightmost column should be filled\00"
@.str.3 = [60 x i8] c" with *'s. But if the bug is present, some of the *'s may\00"
@.str.4 = [59 x i8] c" be placed in other places, e.g. in the leftmost column,\00"
@.str.5 = [49 x i8] c" and the top line of +'s may be scrolled away.\00"
define i32 @bug_w() {
%1 = tail call i32 @cup(i32 16, i32 1)
%2 = tail call i32 @println(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @println(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @println(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @println(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
%6 = tail call i32 @println(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0))
%7 = tail call i32 @println(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0))
%8 = tail call i32 @cup(i32 1, i32 1)
br label %9
9: ; preds = %0, %9
%10 = phi i32 [ 1, %0 ], [ %12, %9 ]
%11 = tail call i32 @putchar(i32 43)
%12 = add nuw nsw i32 %10, 1
%13 = icmp eq i32 %12, 80
br i1 %13, label %14, label %9
14: ; preds = %9
%15 = tail call i32 @hvp(i32 1, i32 80)
%16 = tail call i32 @putchar(i32 42)
%17 = tail call i32 @hvp(i32 2, i32 80)
%18 = tail call i32 @putchar(i32 42)
%19 = tail call i32 @hvp(i32 3, i32 80)
%20 = tail call i32 @putchar(i32 42)
%21 = tail call i32 @hvp(i32 4, i32 80)
%22 = tail call i32 @putchar(i32 42)
%23 = tail call i32 @hvp(i32 5, i32 80)
%24 = tail call i32 @putchar(i32 42)
%25 = tail call i32 @hvp(i32 6, i32 80)
%26 = tail call i32 @putchar(i32 42)
%27 = tail call i32 @hvp(i32 7, i32 80)
%28 = tail call i32 @putchar(i32 42)
%29 = tail call i32 @hvp(i32 8, i32 80)
%30 = tail call i32 @putchar(i32 42)
%31 = tail call i32 @hvp(i32 9, i32 80)
%32 = tail call i32 @putchar(i32 42)
%33 = tail call i32 @hvp(i32 10, i32 80)
%34 = tail call i32 @putchar(i32 42)
%35 = tail call i32 @hvp(i32 11, i32 80)
%36 = tail call i32 @putchar(i32 42)
%37 = tail call i32 @hvp(i32 12, i32 80)
%38 = tail call i32 @putchar(i32 42)
%39 = tail call i32 @hvp(i32 13, i32 80)
%40 = tail call i32 @putchar(i32 42)
%41 = tail call i32 @hvp(i32 14, i32 80)
%42 = tail call i32 @putchar(i32 42)
%43 = tail call i32 @hvp(i32 15, i32 80)
%44 = tail call i32 @putchar(i32 42)
%45 = tail call i32 @hvp(i32 16, i32 80)
%46 = tail call i32 @putchar(i32 42)
%47 = tail call i32 @hvp(i32 17, i32 80)
%48 = tail call i32 @putchar(i32 42)
%49 = tail call i32 @hvp(i32 18, i32 80)
%50 = tail call i32 @putchar(i32 42)
%51 = tail call i32 @hvp(i32 19, i32 80)
%52 = tail call i32 @putchar(i32 42)
%53 = tail call i32 @hvp(i32 20, i32 80)
%54 = tail call i32 @putchar(i32 42)
%55 = tail call i32 @hvp(i32 21, i32 80)
%56 = tail call i32 @putchar(i32 42)
%57 = tail call i32 @hvp(i32 22, i32 80)
%58 = tail call i32 @putchar(i32 42)
%59 = tail call i32 @hvp(i32 23, i32 80)
%60 = tail call i32 @putchar(i32 42)
%61 = tail call i32 @hvp(i32 24, i32 80)
%62 = tail call i32 @putchar(i32 42)
%63 = tail call i32 @cup(i32 24, i32 1)
%64 = tail call i32 (...) @holdit()
ret i32 undef
}