#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*/ _putchar(char);
int /*<<< orphan*/ scroll1();
int /*<<< orphan*/ vdp_waddr(unsigned int);
void vdp_puts(unsigned int addr, const char *str) {
  char ch;
  vdp_waddr(addr);
  while (ch = *str++) {
    if (ch < ' ') {
      switch (ch) {
      case '\n':
        if (addr < (0x0000 + 40 * (24 - 1)))
          addr += 40;
        else
          scroll1();
      case '\r':
        vdp_waddr(addr);
        break;
      }
    } else {
      _putchar(ch);
    }
  }
}


x86 assembly (clang, -O0):
<vdp_puts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <vdp_waddr@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
cmp    $0x0,%al
je     11d8 <vdp_puts+0xa8>
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
jge    11ca <vdp_puts+0x9a>
movsbl -0x11(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0xa,%eax
je     1196 <vdp_puts+0x66>
jmp    1185 <vdp_puts+0x55>
mov    -0x18(%rbp),%eax
sub    $0xd,%eax
je     11bd <vdp_puts+0x8d>
jmp    11c5 <vdp_puts+0x95>
cmpl   $0x398,-0x4(%rbp)
jae    11b1 <vdp_puts+0x81>
mov    -0x4(%rbp),%eax
add    $0x28,%eax
mov    %eax,-0x4(%rbp)
jmp    11b8 <vdp_puts+0x88>
mov    $0x0,%al
call   1050 <scroll1@plt>
jmp    11bd <vdp_puts+0x8d>
mov    -0x4(%rbp),%edi
call   1030 <vdp_waddr@plt>
jmp    11d3 <vdp_puts+0xa3>
movsbl -0x11(%rbp),%edi
call   1040 <_putchar@plt>
jmp    1147 <vdp_puts+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vdp_puts>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <vdp_waddr@plt>
mov    (%rbx),%al
test   %al,%al
je     1191 <vdp_puts+0x61>
add    $0x1,%rbx
jmp    1163 <vdp_puts+0x33>
nopl   0x0(%rax)
movsbl %al,%edi
call   1040 <_putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1191 <vdp_puts+0x61>
cmp    $0x1f,%al
jg     1150 <vdp_puts+0x20>
movsbl %al,%eax
cmp    $0xd,%eax
je     1188 <vdp_puts+0x58>
cmp    $0xa,%eax
jne    1158 <vdp_puts+0x28>
cmp    $0x397,%ebp
ja     1181 <vdp_puts+0x51>
add    $0x28,%ebp
jmp    1188 <vdp_puts+0x58>
xor    %eax,%eax
call   1050 <scroll1@plt>
mov    %ebp,%edi
call   1030 <vdp_waddr@plt>
jmp    1158 <vdp_puts+0x28>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @vdp_puts(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = call i32 @vdp_waddr(i32 %6)
br label %8
8: ; preds = %36, %2
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %4
%11 = load i8, i8* %9
store i8 %11, i8* %5
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %37
13: ; preds = %8
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = icmp slt i32 %15, 32
br i1 %16, label %17, label %33
17: ; preds = %13
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
switch i32 %19, label %32 [
i32 10, label %20
i32 13, label %29
]
20: ; preds = %17
%21 = load i32, i32* %3
%22 = icmp ult i32 %21, 920
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %3
%25 = add i32 %24, 40
store i32 %25, i32* %3
br label %28
26: ; preds = %20
%27 = call i32 (...) @scroll1()
br label %28
28: ; preds = %26, %23
br label %29
29: ; preds = %17, %28
%30 = load i32, i32* %3
%31 = call i32 @vdp_waddr(i32 %30)
br label %32
32: ; preds = %17, %29
br label %36
33: ; preds = %13
%34 = load i8, i8* %5
%35 = call i32 @_putchar(i8 signext %34)
br label %36
36: ; preds = %33, %32
br label %8
37: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @vdp_puts(i32 %0, i8* nocapture %1) {
%3 = tail call i32 @vdp_waddr(i32 %0)
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %29, label %6
6: ; preds = %2, %25
%7 = phi i8 [ %27, %25 ], [ %4, %2 ]
%8 = phi i8* [ %10, %25 ], [ %1, %2 ]
%9 = phi i32 [ %26, %25 ], [ %0, %2 ]
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = icmp slt i8 %7, 32
br i1 %11, label %12, label %23
12: ; preds = %6
%13 = sext i8 %7 to i32
switch i32 %13, label %25 [
i32 10, label %14
i32 13, label %20
]
14: ; preds = %12
%15 = icmp ult i32 %9, 920
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = add nuw nsw i32 %9, 40
br label %20
18: ; preds = %14
%19 = tail call i32 (...) @scroll1()
br label %20
20: ; preds = %16, %18, %12
%21 = phi i32 [ %9, %12 ], [ %17, %16 ], [ %9, %18 ]
%22 = tail call i32 @vdp_waddr(i32 %21)
br label %25
23: ; preds = %6
%24 = tail call i32 @_putchar(i8 signext %7)
br label %25
25: ; preds = %20, %12, %23
%26 = phi i32 [ %9, %12 ], [ %21, %20 ], [ %9, %23 ]
%27 = load i8, i8* %10
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %6
29: ; preds = %25, %2
ret void
}